SQL CE Compact 3.5表的标识列

时间:2009-11-01 05:25:43

标签: sql-server sql-server-ce identity-column

我是否可以针对INFORMATION_SCHEMA或系统表编写查询,以确定列是否是SQL CE版本3.5中的标识列?

2 个答案:

答案 0 :(得分:0)

使用 COLUMNPROPERTY 。供你参考

A) COLUMNPROPERTY (Transact-SQL)

b)中 Identity Columns

答案 1 :(得分: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