獲取SQLSERVER 表結構資訊
阿新 • • 發佈:2019-01-07
--獲取SqlServer中表結構 主鍵,及描述declare@table_nameasvarchar(max)
set@table_name='你的表名'select sys.columns.name, sys.types.name, sys.columns.max_length, sys.columns.is_nullable,
(selectcount(*) from sys.identity_columns where sys.identity_columns.object_id= sys.columns.object_idand 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_idand 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_idand sys.columns.system_type_id =sys.types.system_type_id and sys.tables.name=@table_nameorderby sys.columns.column_id
執行效果
set@table_name='你的表名'select sys.columns.name, sys.types.name, sys.columns.max_length, sys.columns.is_nullable,
(selectcount(*) from sys.identity_columns where sys.identity_columns.object_id= sys.columns.object_idand sys.columns.column_id = sys.identity_columns.column_id)
(select value from sys.extended_properties where sys.extended_properties.major_id = sys.columns.object_idand 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_idand sys.columns.system_type_id
執行效果