如何在SQL Server 2008 R2中获取表的约束列表及其各自的列名

时间:2015-07-17 19:35:37

标签: sql-server-2008-r2

我想列出所有约束名称及其各自的列名称。我使用下面提到的代码:

select * 
from sys.objects
where parent_object_id = object_id('qw') --this gives me the constraints lists but does not give me columns in which they are applied.

select * 
from sys.columns
where object_id = object_id('qw') -- this gives me the column list of the table.

我的问题是我无法加入这两个查询以获取列及其约束。

1 个答案:

答案 0 :(得分:1)

听起来你需要CONSTRAINT_COLUMN_USAGE