sql获取表字段名、描述和类型

SELECT TableName = OBJECT_NAME(c.object_id), ColumnsName = c.name, Description = ex.value, ColumnType=st.name, Length=c.max_length 

FROM 

sys.columns c 

LEFT JOIN 

sys.extended_properties ex 

ON 

ex.major_id = c.object_id 

AND ex.minor_id = c.column_id 

AND ex.name = 'MS_Description' 

LEFT JOIN

systypes st 

on c.system_type_id=st.xtype 

WHERE 

OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0 

AND OBJECT_NAME(c.object_id) ='tablename'

talbename为表名,比如我们要获取Order表中的字段名、字段描述、字段类型、类型长度,可以把tablename替换为Order即可

欢迎加入群:254082423

一起学习讨论asp.net mvc 

你可能感兴趣的:(sql)