TRUNCATE TABLE statement in SQL
The TRUNCATE TABLE statement is used to completely delete records from an existing table in SQL.
The TRUNCATE TABLE statement is used to completely delete records from an existing table in SQL.
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
You should read it
- The difference between Truncate and Delete in Microsoft SQL Server
- The TRUNCATE TABLE command in SQL Server
- DELETE TOP command in SQL Server
- DELETE command in SQL Server
- Instructions for deleting table paths in Word
- Trick to quickly delete a table in Word
- DROP TABLE command in SQL Server
- Delete a Table in Word - Delete a Table in Word
- How to delete table format in Excel
- TEMPORARY TABLE temporary table in SQL
- How to delete table borders in Word
- Reg delete command in Windows