#This article mainly talks about using the clear command in the database. It has certain learning value. If necessary, Friends can find out, I hope it can be helpful to you.
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 表名;
Copy after login
truncate table 表名;
Copy after login
Run the test
I 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 delete
truncate 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 one
Which method to choose depends on the actual situation. I usually use the delete method. Although it is slower, it is safer
Related tutorials:
mysql video tutorial
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!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn