Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

sql server如何查询一个表中的一个列是否存在唯一约束 比如查询 AA表的 BB列

$
0
0

 

示例:

 

CREATE TABLE AA (
  BB INT UNIQUE
);

 

SELECT
  tab.name AS [表名],
  idx.name AS [约束名称],
  col.name AS [约束列名]
FROM
  sys.indexes idx
    JOIN sys.index_columns idxCol
      ON (idx.object_id = idxCol.object_id
          AND idx.index_id = idxCol.index_id
          AND idx.is_unique_constraint = 1)
    JOIN sys.tables tab
      ON (idx.object_id = tab.object_id)
    JOIN sys.columns col
      ON (idx.object_id = col.object_id
          AND idxCol.column_id = col.column_id)
WHERE
  tab.name = 'AA'

 

 

结果:

表名 约束名称 约束列名
AA UQ__AA__3214B5C34460231C BB

作者:bugDemo 发表于2013-3-30 13:45:48 原文链接
阅读:0 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>