sql server 查询表结构

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'tableName'
ORDER BY ORDINAL_POSITION

或者

sp_Columns 'tableName'

包含注释信息

SELECT A.name AS table_name,B.name AS column_name,D.IS_NULLABLE,D.DATA_TYPE,D.CHARACTER_MAXIMUM_LENGTH,C.value AS column_description

FROM sys.tables A INNER JOIN sys.columns B

ON B.object_id = A.object_id LEFT JOIN sys.extended_properties C

ON C.major_id = B.object_id AND C.minor_id = B.column_id

INNER join INFORMATION_SCHEMA.COLUMNS D on D.COLUMN_NAME=B.name and D.table_name=A.name

WHERE A.name ='tableName'

参考资料

Get Table information (Column Name, Data Type) in SQL Server
SQL Server 的所有表查询和注释说明查询

posted @ 2020-04-13 11:02  Lulus  阅读(580)  评论(0编辑  收藏  举报