2

我在 MySQL 数据库中有 3 个表:

CREATE TABLE bank(
idBank int(11) NOT NULL PRIMARY KEY auto_increment,
nameBank varchar(50)
);
CREATE TABLE region(
idRegion int(11) NOT NULL PRIMARY KEY auto_increment,
address varchar(50) NOT NULL,
district varchar(30) NOT NULL,
city varchar(50) NOT NULL,
tel varchar(15) NOT NULL
);
CREATE TABLE branch(
idBranch int(11) NOT NULL PRIMARY KEY auto_increment,
idBank int(11) NOT NULL,
idRegion int(11) NOT NULL,
quantity int(50) NULL,
president varchar(60) NULL,
FOREIGN KEY (idBank) REFERENCES bank (idBank),
FOREIGN KEY (idRegion) REFERENCES region (idRegion)
);

当我尝试将值插入表中时,它适用于前两个,但不记录到分支表中。为什么?

4

1 回答 1

1

What do you try to insert, and what error do you get? Since your tables have foreign key constraints, it means that you cannot insert a new line into these tables where the value for the foreign key does not exist in the referenced table. In English: You cannot add a record in the branch table if there is no corresponding bank to which it belongs, same goes for region.

于 2013-05-27T11:24:11.993 回答