MySQL DROP TABLE Statement
MYSQL uses a Drop Table statement to delete the existing table. This statement removes the complete data of a table along with the whole structure or definition permanently from the database. So, you must be very careful while removing the table because we cannot recover the lost data after deleting it.
Syntax
The following are the syntax to remove the table in MySQL:
DROP TABLE table_name;
MySQL DROP TABLE Example
The following SQL statement drops the existing table “Customers”:
Example
DROP TABLE Customers;
MySQL TRUNCATE TABLE
The TRUNCATE TABLE statement is used to delete the data inside a table, but not the table itself.
Syntax
TRUNCATE TABLE table_name;
MySQL TRUNCATE TABLE Example
The following SQL statement truncate the existing table “Customers”:
Example
TRUNCATE TABLE Customers;
MySQL TRUNCATE Table vs. DROP Table
You can also use the DROP TABLE command to delete the complete table, but it will remove complete table data and structure both. You need to re-create the table again if you have to store some data. But in the case of TRUNCATE TABLE, it removes only table data, not structure. You don’t need to re-create the table again because the table structure already exists.
No comments:
Post a Comment