Table of Contents
This guide covers truncate table statement in SQL with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
This command works similar to DROP TABLE to delete the entire table, but TRUNCATE Will delete the entire table structure from the Database and if you need to store some data with such a table structure, you will have to re-create the table again. .
The Syntax for Using TRUNCATE TABLE in SQL
The basic syntax of The TRUNCATE TABLE command To remove records from the table is as follows:
TRUNCATE TABLE ten_bang;
Example of TRUNCATE TABLE in SQL
Suppose the NHANVIEN Table has the following records:
+----+----------+-----+-----------+----------+ | ID | TEN |TUOI | DIACHI | LUONG | +----+----------+-----+-----------+----------+ | 1 | Thanh | 32 | Haiphong | 2000.00 | | 2 | Loan | 25 | Hanoi | 1500.00 | | 3 | Nga | 23 | Hanam | 2000.00 | | 4 | Manh | 25 | Hue | 6500.00 | | 5 | Huy | 27 | Hatinh | 8500.00 | | 6 | Cao | 22 | HCM | 4500.00 | | 7 | Lam | 24 | Hanoi | 10000.00 | +----+----------+-----+-----------+----------+
Execute the Truncate statement as follows:
SQL > TRUNCATE TABLE NHANVIEN;
Now, the NHANVIEN Table has been removed from the records and the results from the SELECT statement returned are:
SQL> SELECT * FROM NHANVIEN;Empty set (0.00 sec)
In the next section, we will learn How to use VIEW in SQL , please remember to follow.
Previous article: Index (INDEX) in SQL
Next lesson: The view VIEW framework in SQL
FAQ
What should I check before following these steps?
Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.
Why might the process not work?
Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.
Can I undo the changes if necessary?
That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.
Reader Comments 0
Sign in with email or Google to join the discussion.