函数sp_helpconstraint将为我提供表的引用外键
示例:sp_helpconstraint TAB1
FK_TAB1 TAB1 FOREIGN KEY(ID)参考文献(ID)
我正在进行查询,其中我想知道参考表。
答案 0 :(得分:3)
This example from Sybase.com非常有启发性:
例如,pubs3中store_employees表上的sp_helpconstraint输出类似于:
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
换句话说,store_employees
有2个外键约束:
store
store_employee
表示此人的经理注意表格的FK如何指向自己。