我有一个查询,它给了我列名、数据类型、最大长度、可空...
如果该列具有外键,我还需要知道该列所引用的表的名称。
这是我的查询
SELECT
c.name 'Column Name',
t.Name 'Data type',
c.max_length 'Max Length',
c.is_nullable,
ISNULL(i.is_primary_key, 0) 'Primary Key'
FROM
sys.columns c
INNER JOIN
sys.types t ON c.system_type_id = t.system_type_id
LEFT OUTER JOIN
sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id
LEFT OUTER JOIN
sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
WHERE
c.object_id = OBJECT_ID('Table_Name')