0

我已经坚持了很多小时,我需要你的帮助。

我有两个数组:

CREATE TABLE if not exists chr(
id_chr int(10) NOT NULL AUTO_INCREMENT,
number int(10),
genename varchar(30) not null,
ensembleid varchar(30) not null,
strand int(10) not null,
band varchar(10) not null, 
genestart int(30) not null,
geneend int(30) not null,
biotype varchar(30),
status varchar(10),
transcriptsnum int(10),
gc float(10) not null,
PRIMARY KEY(id_chr)
);

CREATE TABLE if not exists gene(
id_gene int(10) NOT NULL AUTO_INCREMENT,
name varchar(30) not null,
transcriptid int(30) not null,
idchr int(10) not null,
PRIMARY KEY(id_gene)
);

到目前为止,我已经将值插入到 chr 表中(大约 8000 行),并且我还想要一个表基因的多重插入。

我得到错误:

Error: Cannot add or update a child row: a foreign key constraint fails

问题是,foreign key由于我必须插入多行,我如何插入值?

4

1 回答 1

0
Try this:

INSERT INTO gene(name,transcriptid,idchr)
select value1,value2,id_chr from char
于 2012-09-22T04:41:46.580 回答