January 2019
Beginner
556 pages
14h 19m
English
Another statement that can also change the data, but not the data structure, is TRUNCATE. It clears a table completely and almost instantly. It has the same effect as the DELETE statement without the WHERE clause. So, it's useful on large tables:
car_portal=> TRUNCATE TABLE car_portal_app.a;TRUNCATE TABLE
The TABLE keyword is optional.
TRUNCATE can clear several tables at a time. To do so, use a list of tables in the command, as follows:
TRUNCATE car_portal_app.a, car_portal_app.b;
If there are sequences used to auto generate values that are owned by fields of the table being cleared, the TRUNCATE command can reset those sequences. To do this, the following command could be used:
TRUNCATE some_table RESTART IDENTITY; ...
Read now
Unlock full access