2014-10-16 87 views
0

功能sp_helpconstraint可會給我一個表的參考外鍵
參考外鍵SYBASE查詢

例如:sp_helpconstraint可TAB1

FK_TAB1 TAB1外鍵(ID)參考文獻TABREFERENCE(ID)

我正在做一個查詢,在裏面我想知道參考表。

回答

2

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如何指向自己。