I'm a very beginner to relations, so this may sound dumb. But, what is the difference (in MySQL) between truncating a table and removing all the records (this answer says only about performance)?
I was playing (in phpMyAdmin) with one of my test tables, to check, how can I reset auto_increment
value of table and run into situation, where I was able to delete all the records:
DELETE from managers;
But when I tried to truncate this table (TRUNCATE managers
), I've got warning: Cannot truncate a table referenced in a foreign key constraint (probes, CONSTRAINT probes_ibfk_4 FOREIGN KEY (manager_id) REFERENCES managers (id));
.
I had to "reset" the auto_increment
value with ALTER TABLE managers AUTO_INCREMENT = 1;
.
Isn't that something odd? Up until now, I thought, that TRUNCATE
= DELETE from managers
(in terms of checking and effects, because performance can be different, but this is not the key here).
How can constraint warning pop on TRUNCATE
but not on "delete all"?