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
- CREATE TABLE command in SQL Serverin sql server (transact-sql), the create table statement is used to create and define tables.
- How to Write an Artist's Statementit is quite hard to write a really good artist statement, even if you're a good writer. the statement accompanies a piece or set of work you've painted, drawn, photographed, created, and it must sum up such elements as motivation,...
- INSERT statement in SQL Serverthe insert statement in sql server (transact-sql) is used to insert one or more records into a table.
- 35 tools, scripts and plugins to build HTML Tablethere are many ways to visualize data, ie you can design a beautiful infographics or create interactive charts. it all depends on your data and how you want to present them.
- RIGHT JOIN in SQLright join in sql is a type of join that returns all records from the right side table and matching records from the left side table.
- Table fans and box fans, which is the smart choice?electric fans are indispensable household appliances, especially on hot sunny days. in particular, box fans and table fans are cooling devices are quite a lot of users interested. however, the selection of box fans and table fans also makes many people feel puzzled by the similarities of utility and price.
- Should a table drill be used?table drilling machines provide the most accurate drilling holes, meeting the demand for industrial and continuous drilling on wood and metal.
- Table operations in Wordintroduce table operations in word. table operations in word 2013 include: 1. draw cells in a table. - creating a table can not ignore merge cell operation, for example, if you want the column of the school day to have 2 values of even and odd dates, make 2 columns into one.
- How to fix table errors in Word overflowerror word overflow table can be corrected in 2 different ways and very simple to perform, helping to bring the table in word aligned correctly.
- Instructions for naming Excel tablestables in excel are named table 1, table2, table 3,... but if you keep the names like this, it will be difficult to handle the table. therefore, users should change and name the excel table.