2010-06-18 44 views
0
> i am getting following error in sql 
> server express while defining foreign 
> key could any body resolve my problem 
> 
> > 'tbl_branch' table saved successfully 
> > 'tbl_students' table 
> > - Unable to create relationship 'FK_tbl_students_tbl_branch'. 
> > Introducing FOREIGN KEY constraint 
> > 'FK_tbl_students_tbl_branch' on table 
> > 'tbl_students' may cause cycles or 
> > multiple cascade paths. Specify ON 
> > DELETE NO ACTION or ON UPDATE NO 
> > ACTION, or modify other FOREIGN KEY 
> > constraints. Could not create 
> > constraint. See previous errors. 
> > 
> > > Blockquote 
+1

向我們展示您在所有涉及表和您正在創建的表中所擁有的外鍵。 – HLGEM 2010-06-18 13:38:22

+1

數據庫表的圖表也將有所幫助 – HLGEM 2010-06-18 13:39:08

回答

1

我敢肯定,這是警告,你有一個「循環引用」你的外鍵;即tbl_branch有一個指向tbl_students的外鍵,而tbl_students有一個指向tbl_branch的外鍵。

具體而言,問題在於您打開了級聯刪除或更新。這意味着當您刪除tbl_branch中的一行時,它會嘗試刪除tbl_students中的關聯記錄,這會嘗試刪除tbl_branch中的關聯記錄等。換句話說,您可能會導致循環級聯刪除。

可以關閉級聯刪除/更新或刪除「循環」外鍵。

+0

分支有一個外鍵course_id .... 可以告訴我什麼是循環引用以及如何解決它... – 2010-06-18 13:33:37

+0

做這兩個表都有一個外鍵指向另一張桌子? – 2010-06-18 13:44:39

+1

最簡單形式的循環引用是當你從表A到表B有一個FK,而另一個從表B到表A.你也可以有A-> B-> C-> A等,這是一個問題,因爲例如,如果您有級聯更新,則服務器可能陷入無限循環。 – 2010-06-18 13:45:42