sql2005取得TABLE主鍵及欄位名稱,說明
SELECT i.name AS IndexName, OBJECT_NAME(ic.OBJECT_ID) AS TableName, COL_NAME(ic.OBJECT_ID,ic.column_id) AS ColumnName,
isnull(e.[value], '') as evalue
FROM sys.indexes AS i
INNER JOIN sys.index_columns AS ic ON i.OBJECT_ID = ic.OBJECT_ID AND i.index_id = ic.index_id
left join sys.extended_properties e on e.major_id=ic.object_id and e.minor_id=ic.Column_id and e.class=1
WHERE i.is_primary_key = 1
and ic.OBJECT_ID=object_id('tablename')
order by ic.column_id
isnull(e.[value], '') as evalue
FROM sys.indexes AS i
INNER JOIN sys.index_columns AS ic ON i.OBJECT_ID = ic.OBJECT_ID AND i.index_id = ic.index_id
left join sys.extended_properties e on e.major_id=ic.object_id and e.minor_id=ic.Column_id and e.class=1
WHERE i.is_primary_key = 1
and ic.OBJECT_ID=object_id('tablename')
order by ic.column_id