Mssql根据表名获取字段
根据表名获取表名、字段、描述和类型长度,正好有需要的朋友们可参考添加自需的字段,sql语句如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 SELECT TableName = OBJECT_NAME(cols.object_id), ColumnsName = props.name, Description = props.value, Length=cols.max_length 2 FROM sys.columns cols inner JOIN sys.extended_properties props ON 3 props.major_id = cols.object_id 4 AND props.minor_id = cols.column_id 5 AND props.name = 'MS_Description' 6 WHERE OBJECTPROPERTY(cols.object_id, 'IsMsShipped')=0 7 AND OBJECT_NAME(cols.object_id) ='sf_project'