使用MySql插入语句

时间:2018-02-04 12:13:44

标签: mysql sql

create table enquiry (
    eqid integer not null auto_increment primary key,
    question varchar(500),
    cusID integer(100),
    tpid integer(100),
    staffid integer(100)
 );

alter table enquiry add foreign key(tpid) references tourpackage (tpid) ON DELETE CASCADE ON UPDATE CASCADE;

alter table enquiry add foreign key(staffid) references staff (staffid) ON DELETE CASCADE ON UPDATE CASCADE;

alter table enquiry add foreign key(cusID) references customer (cusID) ON DELETE CASCADE ON UPDATE CASCADE;
insert into enquiry
    values (0, "What is the minimum travel group size?",0,0,0);

insert into enquiry
    values (0, "Can we return at a later date?",0,0,0);

insert into enquiry
    values (0, "I would like to use my KrisFlyer miles points to redeem an air ticket. Is it possible?",0,0,0);

我在插入查询值时遇到问题。无法添加或更新子行的错误状态。

1 个答案:

答案 0 :(得分:0)

您的插页应该如下所示:

insert into enquiry (question)
    values ('What is the minimum travel group size?');

您不应插入自动递增的主键。让数据库为您完成工作。

我在猜测" 0"其他列的值旨在表示"没有参考"。如果是这样,请让数据库插入NULL。否则,您需要确保每个参考表都有一个" 0"值。