SQL: Truncate, Drop, Rename Query

  • March 15, 2023
  • DBMS
UPDATE QUERY

The various DDL commands that are used to redefine the tables will be covered in this tutorial.

Truncate Query:

TRUNCATE statement is a Data Definition Language (DDL) operation that is used to mark the extent of a table for deallocation (empty for reuse). This method instantly deletes all of the data from a table while often evading several integrity-checking techniques. It was introduced formally in the SQL:2008 standard. The DELETE FROM mytable statement and the TRUNCATE TABLE mytable statement are similar theoretically but not physically (without a WHERE clause).

Syntax:

TRUNCATE TABLE  table_name;

Example:

Student_IDStudent_NameStudent_CourseStudent_Marks
1AnujB.tech88
2RamanMCA98
3ShyamBBA92
Student

Query to truncate the table:

TRUNCATE TABLE  Student;

The above query will delete all the records from the table Student.

Output:

Student_IDStudent_NameStudent_CourseStudent_Marks
Student
Drop Query:

The drop command is used to completely remove a table from a database and erases the table’s structure. The drop command deletes all of the table’s indexes, constraints, triggers, and other definitional elements. When the DROP command is performed, the data kept in the database is also gone and cannot be restored.

Syntax:

DROP TABLE table_name;  

Example:

This query deletes the created Student table from the database:

DROP TABLE Student;  
Rename Query:

The RENAME command in a database can be used to rename a table. The syntax for the rename command is as follows:

RENAME TABLE old_table_name to new_table_name

Example:

Query to rename the Student table to Student_Details.

RENAME TABLE Student to Student_Details

Output:

Student_IDStudent_NameStudent_CourseStudent_Marks
Student_Details

Note: also read about SQL: ALTER command

Follow Me

Please follow me to read my latest post on programming and technology if you like my post.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Leave a Reply

Your email address will not be published. Required fields are marked *