[MSSQL] 查 資料表 名稱,欄位型態,描述 語法
B1.TABLE_NAME,
B1.COLUMN_NAME,
B1.DATA_TYPE,
B1.PrimaryKey
,ISNULL((B3.value),B1.COLUMN_NAME)[Description]
FROM (
SELECT
A1.TABLE_NAME,
A1.COLUMN_NAME
,lower(A1.DATA_TYPE) DATA_TYPE
,substring(isnull(A2.CONSTRAINT_NAME, ''), 1, 2) PrimaryKey
FROM INFORMATION_SCHEMA.COLUMNS A1 LEFT JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE A2
ON A1.TABLE_SCHEMA = A2.TABLE_SCHEMA AND A1.TABLE_NAME = A2.TABLE_NAME AND A1.COLUMN_NAME = A2.COLUMN_NAME
WHERE A1.TABLE_NAME IN ({0})) B1
LEFT JOIN sys.columns B2 ON B2.Object_ID = Object_ID(B1.TABLE_NAME) AND B1.COLUMN_NAME=B2.name
LEFT JOIN sys.extended_properties B3 ON B2.[object_id]=B3.major_id AND B2.column_id=B3.MINOR_ID