2009-11-01 42 views
2

有沒有可以根據INFORMATION_SCHEMA或針對系統表編寫的查詢來確定列是否是SQL CE版本3.5中的標識列?針對表的SQL CE Compact 3.5標識列

+0

下面是網站鏈接到了答案:HTTP://social.msdn .microsoft.com/Forums/zh-CN/sqlce/thread/f0a5b6ef-9375-4af2-9a17-34db3ca700bd?prof = required&lc = 1033 – rxm0203 2009-11-02 14:53:05

回答

0

使用COLUMNPROPERTY。對於UR參考

一) COLUMNPROPERTY (Transact-SQL)

B) Identity Columns

+0

COLUMNPROPERTY函數在SQL CE Compact 3.5中不可用。以下是供您參考的鏈接: http://msdn.microsoft.com/en-us/library/ms174077.aspx – rxm0203 2009-11-01 17:05:01

0

嘗試以下查詢:

;WITH PK_INFO AS (SELECT CON.TABLE_CATALOG, CON.TABLE_SCHEMA, CON.CONSTRAINT_NAME, USO.COLUMN_NAME 
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS CON 
    JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE USO ON CON.CONSTRAINT_NAME = USO.CONSTRAINT_NAME 
     AND CON.TABLE_CATALOG = USO.TABLE_CATALOG AND CON.TABLE_SCHEMA = USO.TABLE_SCHEMA 
WHERE CON.TABLE_NAME = 'YOUR_TABLE' 
    AND CON.CONSTRAINT_TYPE = 'PRIMARY KEY' 
    ) SELECT DISTINCT CASE WHEN (PK.COLUMN_NAME IS NULL) THEN 0 ELSE 1 END AS COLUMN_IS_PRIMARYKEY, * 
FROM INFORMATION_SCHEMA.COLUMNS COL 
LEFT JOIN PK_INFO PK on COL.COLUMN_NAME = PK.COLUMN_NAME WHERE COL.TABLE_NAME = 'YOUR_TABLE' ORDER BY COL.ORDINAL_POSITION ASC