Just a truncation takes place, but not only the deletion of related rows. I.e. if you add, among others, a row with NULL value in foreign key column to the child (referencing) table
INSERTINTO Trun_Ref VALUES(1), (2), (NULL);
this row will be removed also.
Oracle
Oracle has not autoincrement function which could be specified in a column definition. Nevertheless autoincrement behaviour can be imitated with aid of sequence. For example, theTruncate_test table mentioned above could be created in Oracle in such manner:
CREATE SEQUENCE u_seq
START WITH5
INCREMENT BY5;
/
CREATETABLE Truncate_test (id INT PRIMARYKEY, val int);
/
INSERTINTO Truncate_test(id, val)
VALUES(u_seq.NEXTVAL,1);
INSERTINTO Truncate_test(id, val)
VALUES(u_seq.NEXTVAL,2);
INSERTINTO Truncate_test(id, val)
VALUES(u_seq.NEXTVAL,3);
Upon executing TRUNCATE TABLE Truncate_test command, the counter (sequence) is not being reset, and the numbering will be continued.
Cascade operations are not allowed, so TRUNCATE TABLE statement is not available when the table is referenced by a foreign key.
MySQL
The CONTINUE IDENTITY and RESTART IDENTITY options are not supported; a counter (AUTO_INCREMENT) is being reset to zero.
Cascade operations are similar to using DELETE statement, i.e. if foreign key has ON DELETE CASCADE option, related rows will be deleted only. This means that rows with NULL values in the foreign key column are being retained after truncating: