mysql - INSERTING and UPDATING SQL tables -
How to INSERT the data in a table that is the key to a mistake? I tried to do this
Insert in City (name, country, population) values ("New Zealand", "Auckland", "80000");
However this has given me an error
# 1452 - The line of a child can not be added or updated: a foreign key constraint Failed (
stu_nall596_compsci_280_c_s2_2014
. city
, CONSTRAINT city_ibfk_2
foreign key ( country
) reference country
( id
))
And in the period of updating an area, how to do it?
To ignore the fact that "New Zealand" is not a city, and "Auckland" is a city And not a country, if you want your involvement to be successful, then you have a line with a consistent id
of "Auckland" in
country
Required entry will allow you to insert a new line in the city
table for the city of that country.
I do not know how your schema looks, but this is a difficult example;
Enter Country (ID, Name) Price (123, 'New Zealand'); Include City (name, country, population) values ('Auckland', 123, 80000);
See before, I can refer to it, country
in the id
of 123
Must be present city
table.
Comments
Post a Comment