The SQL Standard has a TRUNCATE TABLE statement that clears all the contents of the table. However, SQLite does not support this statement. You can use "DELETE from TableName" directly in SQLite. For most DBMS, using delete is not as fast as truncate, because TRUNCATE does not have to access the entire table without logging data changes.
Although SQLite does not support truncate, it is optimized for DELETE: "When the WHERE are omitted from a DELETE statement and the table being deleted have no TR Iggers, SQLite uses an optimization to erase the entire table content without have to visit each row of the table Indivi Dually. This "truncate" optimization makes the delete run much faster. "
Usually, when you clear the table, you also need to reset the self-increment column to zero. Here's how to define a self-increment column in SQLite:
CREATE TABLE TableName (id INTEGER PRIMARY KEY autoincrement, ...);
A table named Sqlite_sequence is automatically created when the SQLite database contains a self-increment column. This table consists of two columns: name and seq. The name records the table where the increment column is located, and the SEQ record is the current ordinal (the number of the next record is the current ordinal plus 1). If you want to set the ordinal of a self-increment column to zero, you only need to modify the Sqlite_sequence table.
UPDATE sqlite_sequence SET seq = 0 WHERE name = ' TableName ';
You can also delete the record directly:
DELETE from sqlite_sequence WHERE name = ' TableName ';
To reset all the table's self-increment columns to zero, empty the Sqlite_sequence table directly:
DELETE from Sqlite_sequence;
Delete a table using the drop statement and recreate the table, and the table's primary key is regenerated.
DROP TABLE TableName
Welcome to scan QR Code, follow the public number
SQLite clears the table and zeros the self-increment column