I have several tables in my schema that I'm having a problem truncating. My structure is:
country
->PK countryId
->name
city
->PK cityId
->FK countryId
->name
address
->PK addressId
->FK cityId
customer
->PK customerId
->FK addressId
appointment
->PK appointmentId
->FK customerId
Now I am not the one who made this table, it was supplied to me, nor am I any sort of expert in SQL, hardly a beginner actually, but I need to be able to truncate the data as it's for a test application and I have simulated data that I no longer need.
This is the error I am getting:
TRUNCATE TABLE country Error Code: 1701. Cannot truncate a table referenced in a foreign key constraint (`U05FKQ`.`city`, CONSTRAINT `city_ibfk_1` FOREIGN KEY (`countryId`) REFERENCES `U05FKQ`.`country` (`countryId`)) 0.547 sec
I have also attempted to run this:
TRUNCATE TABLE appointment;
TRUNCATE TABLE customer;
TRUNCATE TABLE address;
TRUNCATE TABLE city;
TRUNCATE TABLE country;
Which succeeds on the appointment truncation but fails on customer, and doesn't continue.
Another large issue I have noticed while doing single deletions on data from my application is that the auto incremented id's do not adjust. Nor does deleting an entire table full of data, IE if I delete a full table of 3 entries even though I only have a single entry in the table after addition it still shows me 4 for the ID, is there a fix for this?
I don't have access to the original DB creation script.