SQL server 獲取各種 約束資訊
阿新 • • 發佈:2020-12-16
https://bbs.csdn.net/topics/380103485
--獲取約束資訊
select
*
from
information_schema.constraint_column_usage
---可以獲取指定資料庫中的所有約束的資訊以及約束與列的對應關係
go
select
*
from
information_schema.constraint_table_usage
---查詢結果中只包含表和約束的對應關係,並沒有約束對應的列資訊
go
select
*
from
information_schema.table_constraints
---查詢結果中只包含表和約束的對應關係,並沒有約束對應的列資訊
go
select
*
from
information_schema.key_column_usage
---可以獲取指定資料庫中的所有鍵約束的列資訊,包括主鍵約束中的主鍵列,唯一約束中的唯一鍵列和外來鍵約束中的引用列
go
select
*
from
sys.key_constraints
----獲取約束資訊
select
*
from
sys.foreign_keys
--獲取表中的外來鍵約束
select
*
from
sys.foreign_key_columns
--獲取外來鍵約束的列資訊
select
*
from
information_schema.referential_constraints
--獲取外來鍵約束資訊
select
*
from
information_schema.check_constraints
--獲取檢查約束資訊