SQL - SPLessons

SQL Truncate Table

Chapter 15

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SQL Truncate Table

SQL Truncate Table

shape Description

SQL is a non-procedural dialect. Client can compose SQL script to execute and SQL compiler consequently produces a method to get to database and convey the fancied output. SQL is a database coding, planned for the recuperation and organisation of data in social database. SQL Truncate command is utilized to erase all rows from the current table in the database.”SQL Truncate Table” command shows how to truncate the rows in a table.

shape Conceptual
figure

shape Syntax

Truncate table <table_name>;

Table_name => Any accurate table.

shape Examples

By viewing the below example, the concept of truncate command can be understood easily.

sql> select * from employee;
+--------+--------+-----------+-------+------------+
| emp_id | ename  | job       | sal   | commission |
+--------+--------+-----------+-------+------------+
|   1001 | kate   | manager   | 14000 |         10 |
|   1002 | jack   | scaleman  | 13000 |         20 |
|   1003 | maddie | business  | 14000 |         30 |
|   1004 | madd   | business  | 14000 |       NULL |
|   1005 | winni  | marketing | 14500 |       NULL |
+--------+--------+-----------+-------+------------+
5 rows in set (0.00 sec)

sql> truncate table employee;
Query OK, 0 rows affected (0.37 sec)

sql> select * from employee;
+--------+--------+-----------+-------+------------+
| emp_id | ename  | job       | sal   | commission |
+--------+--------+-----------+-------+------------+
Empty set (0.37 sec)

The above example, truncate command will delete all the existing data from the table employee.

Summary

shape Key Points

  • SQL Truncate Table – Truncate table is utilized to erase all the lines from the table.