简体   繁体   中英

Insert statement using MySql

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);

I have problem inserting my enquiry values in. Error state that cannot add or update child row.

Your inserts should probably look like this:

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

You should not be inserting into the auto-incremented primary key. Let the database do the work for you there.

I am guessing that the "0" values for the other columns are intended to mean "no reference". If so, let the database just insert NULL s. Otherwise, you need to be sure that each reference table has a "0" value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM