Created
December 13, 2014 06:45
-
-
Save Wind4/ff4bf4a2b7076daf6828 to your computer and use it in GitHub Desktop.
SQLSERVER查询表名、字段名,注释
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
TABLE_CATALOG AS [Database], | |
TABLE_SCHEMA AS Owner, | |
TABLE_NAME AS TableName, | |
COLUMN_NAME AS ColumnName, | |
ORDINAL_POSITION AS OrdinalPosition, | |
COLUMN_DEFAULT AS DefaultSetting, | |
IS_NULLABLE AS IsNullable, DATA_TYPE AS DataType, | |
CHARACTER_MAXIMUM_LENGTH AS MaxLength, | |
DATETIME_PRECISION AS DatePrecision, | |
COLUMNPROPERTY(object_id('[' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']'), COLUMN_NAME, 'IsIdentity') AS IsIdentity, | |
COLUMNPROPERTY(object_id('[' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']'), COLUMN_NAME, 'IsComputed') as IsComputed, | |
(SELECT [prop].value FROM sys.objects [table] | |
INNER JOIN sys.columns [column] ON [table].object_id = [column].object_id AND [table].type = 'u' | |
INNER JOIN sys.extended_properties [prop] ON [prop].major_id = [table].object_id AND [prop].minor_id = [column].column_id AND [prop].class = 1 | |
WHERE [table].name = TABLE_NAME AND [column].name = COLUMN_NAME) AS [Description] | |
FROM INFORMATION_SCHEMA.COLUMNS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT [table].name AS TableName, [column].name AS ColumnName, [prop].value AS [Description] | |
FROM sys.objects [table] | |
INNER JOIN sys.columns [column] ON [table].object_id = [column].object_id | |
AND [table].type = 'u' | |
INNER JOIN sys.extended_properties [prop] ON [prop].major_id = [table].object_id | |
AND [prop].minor_id = [column].column_id | |
AND [prop].class = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment