2012-11-23 73 views
1

我想與MYSQL PHPMYADMIN創建表關係。 但沒有約束。關於PHPMYADMIN的MYSQL - 創建表關係

這裏是我做的:

CREATE TABLE runs (
code_teachers int(8), 
code_department int(8), 
primary key(code_teachers, code_department), 
foreign key(code_teachers)references teachers, 
foreign key(code_department)references department 
); 

因此,大家可以看到我試圖創建一個從教師code_teachers之間運行的命名錶對應關係從部門create table和code_department創建表。

但是對於某些未知的原因,當我進入desinger時,它並沒有使關係。 因此,如果有人知道我的問題的答案,歡迎告訴我因爲ima在這裏瘋狂。

回答

1

你嘗試

FOREIGN KEY (columnName) REFERENCES tableName(columnName) 

表名似乎是從您的查詢失蹤。 外鍵需要引用其他表中的列。

Wikipedia說:

  • In the context of relational databases, a foreign key is a referential constraint between two tables. A foreign key is a field in a relational table that matches a candidate key of another table. The foreign key can be used to cross-reference tables.

mySQL.com說:

  • Foreign key relationships involve a parent table that holds the central data values, and a child table with identical values pointing back to its parent. The FOREIGN KEY clause is specified in the child table.
+0

好在我已加入這一個,但我的老師說我不需要它。並感謝您的回答! –

+0

查看我編輯的答案=) – hermann

+0

謝謝!!!它完美的工作! :D –