0% found this document useful (0 votes)
19 views1 page

Deleteion Query

The document discusses three SQL commands: truncate, drop, and rename. The truncate command removes all records from a table but keeps the table structure and resets the primary key. The drop command completely removes a table, destroying its structure. The rename command changes the name of an existing table to a new name.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Deleteion Query

The document discusses three SQL commands: truncate, drop, and rename. The truncate command removes all records from a table but keeps the table structure and resets the primary key. The drop command completely removes a table, destroying its structure. The rename command changes the name of an existing table to a new name.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL queries to Truncate, Drop or Rename a Table

truncate command
truncate command removes all records from a table. But this command will not destroy the table's structure. When
we apply truncate command on a table its Primary key is initialized. Following is its Syntax,
truncate table table-name
Here is an Example explaining it.
truncate table Student;
The above query will delete all the records of Student table.
truncate command is different from delete command. delete command will delete all the rows from a table whereas
truncate command re-initializes a table(like a newly created table).
For eg. If you have a table with 10 rows and an auto_increment primary key, if you use delete command to delete
all the rows, it will delete all the rows, but will not initialize the primary key, hence if you will insert any row after using
delete command, the auto_increment primary key will start from 11. But in case of truncate command, primary key is
re-initialized.

drop command
drop query completely removes a table from database. This command will also destroy the table structure. Following
is its Syntax,
drop table table-name
Here is an Example explaining it.
drop table Student;
The above query will delete the Student table completely. It can also be used on Databases. For Example, to drop
a database,
drop database Test;
The above query will drop a database named Test from the system.

rename query
rename command is used to rename a table. Following is its Syntax,
rename table old-table-name to new-table-name
Here is an Example explaining it.
rename table Student to Student-record;
The above query will rename Student table to Student-record.

You might also like