【问题标题】:MYSQL ON PHPMYADMIN - CREATE TABLE RELATIONSHIPPHPMYADMIN 上的 MYSQL - 创建表关系
【发布时间】:2012-11-23 10:21:33
【问题描述】:

我想用 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 之间创建名为运行的表关系。

但是由于一些未知的原因,当我进入设计者时,它只是没有建立关系。 所以如果有人知道我的问题的答案,欢迎告诉我,因为我在这里发疯了。

【问题讨论】:

    标签: mysql phpmyadmin relationship create-table


    【解决方案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.

    【讨论】:

    • 好吧,我已经添加了这个,但我的老师说我不需要它。并感谢您的回答!
    • 你能再帮我一次吗?我的数据库中还有一个创建表,外键在同一个名为学生的创建表中。你知道我是怎么做到的吗?
    • 设置一个新问题并解释,添加一些代码来演示你的问题,我会在那里检查你的问题。
    猜你喜欢
    • 2014-05-30
    • 2013-01-14
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    相关资源
    最近更新 更多