The various DDL commands that are used to redefine the tables will be covered in this tutorial.
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).
TRUNCATE TABLE table_name;
Query to truncate the table:
TRUNCATE TABLE Student;
The above query will delete all the records from the table Student.
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.
DROP TABLE table_name;
This query deletes the created Student table from the database:
DROP TABLE Student;
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
Query to rename the Student table to Student_Details.
RENAME TABLE Student to Student_Details
Note: also read about SQL: ALTER command
Please follow me to read my latest post on programming and technology if you like my post.
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.