/* SQL 查詢資料表中每個欄位的資訊 */
SELECT a.name AS ColumnName --欄位名稱
,b.[name] AS TableName --資料表名稱
,a.max_length AS Maxlength --最大長度
,c.name AS DataType --資料型別
,a.is_nullable AS IsNullable --是否允許NULL
,a.[precision] AS IntLength --整數個數
,a.[scale] AS DecLength --小數後數字個數
,d.[value] AS Description --描述
FROM sys.columns a
LEFT JOIN sys.tables b ON a.[object_id] = b.[object_id]
LEFT JOIN sys.types c ON a.[system_type_id] = c.[system_type_id]
AND a.[user_type_id] = c.[user_type_id]
LEFT JOIN sys.extended_properties d ON d.[major_id] = a.[object_id]
AND d.[minor_id] = a.[column_id]
WHERE 1 = 1
--AND b.[name] IS NOT NULL
AND b.[name] = 'BMS_Bank'
這查詢有什麼用呢?
1. 寫資料規格書(Table_Schema)時,就會用到了。
2. 系統參數化設定時,也可以拿來用。
範例如下圖:
SELECT a.name AS ColumnName --欄位名稱
,b.[name] AS TableName --資料表名稱
,a.max_length AS Maxlength --最大長度
,c.name AS DataType --資料型別
,a.is_nullable AS IsNullable --是否允許NULL
,a.[precision] AS IntLength --整數個數
,a.[scale] AS DecLength --小數後數字個數
,d.[value] AS Description --描述
FROM sys.columns a
LEFT JOIN sys.tables b ON a.[object_id] = b.[object_id]
LEFT JOIN sys.types c ON a.[system_type_id] = c.[system_type_id]
AND a.[user_type_id] = c.[user_type_id]
LEFT JOIN sys.extended_properties d ON d.[major_id] = a.[object_id]
AND d.[minor_id] = a.[column_id]
WHERE 1 = 1
--AND b.[name] IS NOT NULL
AND b.[name] = 'BMS_Bank'
這查詢有什麼用呢?
1. 寫資料規格書(Table_Schema)時,就會用到了。
2. 系統參數化設定時,也可以拿來用。
範例如下圖:
留言
張貼留言