When the data in the table is not needed, you should delete the data and release the space occupied, and the data in the table can be deleted using the DELETE statement or the TRUNCATE statement, described separately below.
For example: Delete data from the users Table of UserID ' 001 ': Delete from users where userid= ' 001 ';
(2) Unconditionally delete the entire table data
Syntax format: delete table_name;
For example, delete all data in the user table: delete users;
Second, the TRUNCATE statement
Use the TRUNCATE statement to delete all records in a table.
Syntax format: Truncate [table] table_name;
(1) Delete all records do not keep the record occupied space
Truncate [TABLE] table_name [drop storage];
For example, deleting all data in the users table does not save space: Truncate table users drop storage; Drop storage can be omitted because the drop storage keyword is used by default;
(2) Delete all records to keep records occupied space
Truncate [TABLE] table_name [reuse storage];
For example, delete all data in the users table and save space: Truncate table users reuse storage;
comparison of two kinds of deletion statements
Because the DELETE statement deletes a record, the record is deleted one at a time, and the TRUNCATE statement does not produce rollback information when it deletes data, so using delete when you need to delete a large amount of data consumes more system resources and is much faster if you use truncate.
Insert into users values (' 001 ', ' gavindream ', ' 123456 '); 3. Inserting tens of thousands of data using the Copy insertion method
Insert into the Users (userid,username,userpass) select * from users; I inserted 4,194,304 data, using delete Delete to take time: 90.964 seconds, The data is then inserted twice times, but using truncate takes time only for 2.215 seconds, as shown in the following illustration:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.