SQL CE Compact 3.5 表的标识列

发布于 2024-08-09 19:11:30 字数 75 浏览 7 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Smile简单爱 2024-08-16 19:11:30

使用COLUMNPROPERTY。供您参考

a)
COLUMNPROPERTY (Transact-SQL)

b)
身份列

Use COLUMNPROPERTY . For ur reference

a)
COLUMNPROPERTY (Transact-SQL)

b)
Identity Columns

撩发小公举 2024-08-16 19:11:30

尝试以下查询:

;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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文