欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SqlServer中表结构

程序员文章站 2022-03-11 08:59:52
...
--获取SqlServer中表结构 主键,及描述
declare @table_name as varchar(max)
set @table_name = '你的表名'
select sys.columns.name, sys.types.name, sys.columns.max_length, sys.columns.is_nullable,
(select count(*) from sys.identity_columns where sys.identity_columns.object_id = sys.columns.object_id and sys.columns.column_id = sys.identity_columns.column_id) as is_identity ,
(select value from sys.extended_properties where sys.extended_properties.major_id = sys.columns.object_id and sys.extended_properties.minor_id = sys.columns.column_id) as description
from sys.columns, sys.tables, sys.types where sys.columns.object_id = sys.tables.object_id and sys.columns.system_type_id=sys.types.system_type_id and [email protected]_name order by sys.columns.column_id


[img]http://images.cnblogs.com/cnblogs_com/eflylab/200711/2008-06-23_003008.jpg[/img]

--获取表主外键约束
exec sp_helpconstraint '你的表名' ;

来源
http://www.cnblogs.com/eflylab/archive/2008/06/23/1227838.html#2279325
相关标签: sqlserver