TRUNCATE TABLE statement 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
May be interested
- HAVING clause in SQLthe having clause in sql is used to filter records and retrieve only those records that match the requirements or are actually needed.
- The clause combines UNION data in SQLin sql, you can combine the same structured data from multiple tables into one query using the union and union all operators.
- Frame view VIEW in SQLin sql, a view view is a virtual table in a database whose content is defined through a certain sql statement.
- TRANSACTION in SQLa transaction is successfully performed when all commands are successful, then all data changes made in the transaction are saved to the database.
- The WILDCARD operator is in SQLwildcard is also known as a wildcard used with the like statement in sql.
- Function handles DATE / TIME in SQL - Part 1in this article, quantrimang lists all the important functions used to handle date / time in sql.