我想与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时它只是没有建立关系。 所以,如果有人知道我的问题的答案,欢迎你告诉我因为你疯了。
答案 0 :(得分:1)
你试过吗
FOREIGN KEY ( columnName ) REFERENCES tableName(columnName)
您的查询中似乎缺少tableName。 外键需要引用其他表中的列。
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.
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.