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).
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 |
---|---|---|---|
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;
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
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.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…