但是如果表格內有欄位描述時,使用sp_name是無法顯示出來,
此時可以利用下述語法,透過SQL查詢顯示結果!
DECLARE @TableNa VARCHAR(20)='XXX' SELECT IST.Table_schema +'.'+IST.Table_name as 表格名稱 ,ISC.COLUMN_NAME as 欄位名稱 ,ISC.DATA_TYPE as 資料型別 ,isnull(ISC.CHARACTER_MAXIMUM_LENGTH,'') as 長度 ,isnull(ISC.COLUMN_DEFAULT,'') as 預設值 ,ISC.IS_NULLABLE as 允許空值 ,( SELECT value FROM fn_listextendedproperty (NULL, 'schema', IST.Table_schema, 'table', IST.TABLE_NAME, 'column', default) WHERE name='MS_Description' and objtype='COLUMN' and objname Collate Chinese_Taiwan_Stroke_CI_AS = ISC.COLUMN_NAME ) as 欄位備註 FROM INFORMATION_SCHEMA.TABLES IST LEFT JOIN INFORMATION_SCHEMA.COLUMNS ISC ON IST.TABLE_NAME = ISC.TABLE_NAME WHERE TABLE_TYPE='BASE TABLE' AND IST.Table_name=@TableNa ORDER BY IST.TABLE_NAME , ISC.ORDINAL_POSITION
參考自-忘記出處= =
沒有留言:
張貼留言