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_ID | Student_Name | Student_Course | Student_Marks |
---|---|---|---|
1 | Anuj | B.tech | 88 |
2 | Raman | MCA | 98 |
3 | Shyam | BBA | 92 |
Query to truncate the table:
TRUNCATE TABLE Student;
The above query will delete all the records from the table Student.
Output:
Student_ID | Student_Name | Student_Course | Student_Marks |
---|---|---|---|
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_ID | Student_Name | Student_Course | Student_Marks |
---|---|---|---|
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
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Leave a Comment