PHP上的MYSQL PHPMYADMIN - 创建表关系

时间:2012-11-23 10:21:33

标签: mysql phpmyadmin relationship create-table

我想与MYSQL PHPMYADMIN创建表关系。 但不是约束。

这就是我所做的:

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和部门创建表中的code_department之间创建名为run的表关系。

但是对于一些未知的原因,当我进入desinger时它只是没有建立关系。 所以,如果有人知道我的问题的答案,欢迎你告诉我因为你疯了。

1 个答案:

答案 0 :(得分:1)

你试过吗

FOREIGN KEY ( columnName ) REFERENCES tableName(columnName)
您的查询中似乎缺少

tableName。 外键需要引用其他表中的列。

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.