gpt4 book ai didi

mysql - 无法将数据添加到具有外键约束的数据库中

转载 作者:行者123 更新时间:2023-11-30 00:36:34 24 4
gpt4 key购买 nike

引用我之前的问题

Unable to add foreign keys to mysql database

我想知道,由于外键约束已经存在,将新数据插入该部分、获取和教导表的最佳方法是什么?我不想删除表并重建架构,因为需要重新输入的数据太多。

有什么建议吗?

最佳答案

您可以将值插入到表中,例如

insert into table_name values("a", "b", "c");

这是插入语句的常用语法。来到您的餐 table 上

在插入其他表时,还要确保没有违反主键和外键约束。

例如:

Student:
ID name Dept_name tot_credit
1 abc EE 3
2 def CS 3

Department:

Deptname building budget
EE 1 200
CS 2 299
IS 3 900

course:
courseid title dept_name credits
44 Algorithms CS 3
899 OS CS 3

现在,如果您尝试插入部分,它应该像这样:

insert into section values(44, 199, 5, 2000, 500, 50, "Whatever format");

因为这仅指类(class)表

好的,试试这个:

insert into teaches values(instructor_id(existing in instructor table), course_id(match section table), secid(from section table), semester(from section table), year(from section table));

祝你好运。

关于mysql - 无法将数据添加到具有外键约束的数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22122244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com