SQL CE Compact 3.5 Identity columns for a table

谁说我不能喝 提交于 2019-12-24 00:06:39

问题


Is there a query I can write against an INFORMATION_SCHEMA or against the system tables to determine if a column is an identity column in SQL CE version 3.5?


回答1:


Use COLUMNPROPERTY . For ur reference

a) COLUMNPROPERTY (Transact-SQL)

b) Identity Columns




回答2:


Try the following query:

;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


来源:https://stackoverflow.com/questions/1656472/sql-ce-compact-3-5-identity-columns-for-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!