下面是一个示例查询,它将返回带有序号的表名和注释:
使用 sys.tables 和 sys.extended_properties 表:
SELECT ROW_NUMBER() OVER (ORDER BY t.name) AS 序号, t.name AS 表名, p.value AS 注释 FROM sys.tables AS t LEFT JOIN sys.extended_properties AS p ON t.object_id = p.major_id AND p.minor_id = 0 AND p.name = 'MS_Description'
使用 INFORMATION_SCHEMA.TABLES 和 INFORMATION_SCHEMA.TABLES 表:
SELECT ROW_NUMBER() OVER (ORDER BY t.TABLE_NAME) AS 序号, t.TABLE_NAME AS 表名, c.value AS 注释 FROM INFORMATION_SCHEMA.TABLES AS t LEFT JOIN sys.extended_properties AS c ON OBJECT_ID(t.TABLE_NAME) = c.major_id AND c.minor_id = 0 AND c.name = 'MS_Description'
这些查询将返回带有序号的表名和相关的注释(如果有的话)。
请注意,序号是通过 ROW_NUMBER() OVER (ORDER BY ...)
部分指定的表名字段进行排序而生成的。您可以根据自己的需求调整排序规则。