When doing data migration, data cleaning or writing web projects, the data needs to be replaced and updated, so sometimes the table needs to be cleared
Commonly used clearing There are two types of SQL statements for the data table:
delete from 表名;
truncate table 表名;Run the testI am using MySql. The table to be tested has 20,000 records. Make two copies of it for testing. Run two SQL statements to clear the table respectively It can be seen from the results that both statements can achieve the purpose of clearing the table, and the difference between the two is: truncate is more efficient than deletetruncate does not clear the data. Recording logs, data cannot be restored, which is equivalent to retaining the structure of the mysql table. This table is re-created, and all states are equivalent to new tables. Delete clears the data and records logs. Data can be restored, which is equivalent to Delete all the records in the table one by oneWhich method to choose depends on the actual situation. I usually use the delete method. Although it is slower, it is saferRelated tutorials:
The above is the detailed content of How to clear data in the table in mysql database. For more information, please follow other related articles on the PHP Chinese website!