TRUNCATE TABLE and DROP TABLE Commands in SQL
For Complete YouTube Video: Click Here
In this class, we will understand TRUNCATE TABLE and DROP TABLE Commands in SQL.
We have already discussed the concepts of alter table.
Table of Contents
TRUNCATE TABLE and DROP TABLE Commands in SQL
To understand, we will use the user’s table as shown below.
In the above table, we have two rows.
TRUNCATE TABLE Command
The TRUNCATE TABLE statement deletes the data inside a table, but not the table itself.
If we want to delete all the rows in the table, we have to use the truncate command.
With the truncate, we can delete all the rows in the table, but not the table itself.
The syntax for truncate is as shown below.
TRUNCATE TABLE table_name;
Now, we will truncate the user’s table.
TRUNCATE TABLE users;
We will check whether the rows have been deleted or not by using the select command.
In the image below, all the rows are deleted.
The table has been truncated.
DROP TABLE Command
The DROP TABLE statement is used to drop an existing table in a database.
To delete the structure of the table, we use the drop command.
The syntax to drop a table is as shown below.
DROP TABLE table_name;
DROP TABLE users;
The user’s table no more exists.
Let us check with the select command.
The image below shows that the user’s table is not existing.