sp_helpconstraint [<objname>][, detail]
<objname>
是具有 create table 或 alter table 语句定义的一个或多个完整性约束的表的名称。
detail
返回有关约束的用户的信息或错误消息。
显示 pubs3 数据库中 store_employees 表的约束信息。store_employees 表具有 stores 表的外键(stor_id)以及自身参照(mgr_id 引用 emp_id):
sp_helpconstraint store_employees
name defn
--------------------------- --------------------------------
store_empl_stor_i_272004000 store_employees FOREIGN KEY
(stor_id) REFERENCES stores(stor_id)
store_empl_mgr_id_288004057 store_employees FOREIGN KEY
(mgr_id) SELF REFERENCES
store_employees(emp_id)
store_empl_2560039432 UNIQUE INDEX( emp_id) :
NONCLUSTERED, FOREIGN REFERENCE
(3 rows affected)
Total Number of Referential Constraints: 2
Details:
-- Number of references made by this table: 2
-- Number of references to this table: 1
-- Number of self references to this table: 1
Formula for Calculation:
Total Number of Referential Constraints
= Number of references made by this table
+ Number of references made to this table
<ul><li>Number of self references within this table
显示有关 pubs3..pubs3..salesdetail 约束的更详细信息,包括约束类型和所有约束错误消息:
sp_helpconstraint titles, detail
name type defn
msg
------------------------ -------------- ----------------------------
--------------------------------------------
datedflt default value create default datedflt as getdate()
typedflt default value create default typedflt as "UNDECIDED"
titles_pub_id_96003373 referential constraint titles FOREIGN KEY (pub_id)
REFERENCES publishers(pub_id)
standard system error message number : 547
roysched_title__144003544 referential constraint roysched FOREIGN KEY (title_id)
REFERENCES titles(title_id)
standard system error message number : 547
salesdetai_title__368004342 referential constraint salesdetail FOREIGN KEY (title_id)
REFERENCES titles(title_id)
standard system error message number : 547
titleautho_title__432004570 referential constraint titleauthor FOREIGN KEY (title_id)
REFERENCES titles(title_id)
standard system error message number : 547
titles_800033162 unique constraint UNIQUE INDEX ( title_id) :
NONCLUSTERED, FOREIGN REFERENCE
standard system error message number : 2601
(7 rows affected)
Total Number of Referential Constraints: 4
Details:
-- Number of references made by this table: 1
-- Number of references to this table: 3
-- Number of self references to this table: 0
Formula for Calculation:
Total Number of Referential Constraints
= Number of references made by this table
+ Number of references made to this table
</li></ul><ul><li>Number of self references within this table.
显示 pubs3 数据库中所有表的列表:
sp_helpconstraint
id name Num_referential_constraints
----------- ----------------- ---------------------------
80003316 titles 4
16003088 authors 3
176003658 stores 3
256003943 salesdetail 3
208003772 sales 2
336004228 titleauthor 2
896006223 store_employees 2
48003202 publishers 1
128003487 roysched 1
400004456 discounts 1
448004627 au_pix 1
496004798 blurbs 1
(11 rows affected)
使用 sp_helpconstraint 时,还存在一些其它注意事项: