SQLite classic ...login
SQLite classic tutorial
author:php.cn  update time:2022-04-13 17:05:02

SQLite Truncate Table


In SQLite, there is no TRUNCATE TABLE command, but you can use SQLite's DELETE command to delete all data from an existing table, but it is recommended to use DROP The TABLE command deletes the entire table and then recreates it.

Syntax

The basic syntax of the DELETE command is as follows:

sqlite> DELETE FROM table_name;

The basic syntax of DROP TABLE is as follows:

sqlite> DROP TABLE table_name;

If you use the DELETE TABLE command Delete all records. It is recommended to use the VACUUM command to clear unused space.

Example

Suppose the COMPANY table has the following records:

ID          NAME        AGE         ADDRESS     SALARY
----------  ----------  ----------  ----------  ----------
1           Paul        32          California  20000.0
2           Allen       25          Texas       15000.0
3           Teddy       23          Norway      20000.0
4           Mark        25          Rich-Mond   65000.0
5           David       27          Texas       85000.0
6           Kim         22          South-Hall  45000.0
7           James       24          Houston     10000.0

The following is an example of deleting the records in the above table:

SQLite> DELETE FROM COMPANY;
SQLite> VACUUM;

Now, the records in the COMPANY table Completely removed, there will be no output using the SELECT statement.

php.cn