TRUNCATE
Example
Section titled “Example”TRUNCATE TABLE Employee;Output
Section titled “Output”Query OK, 0 rows affected (0.00 sec)Explanation
Section titled “Explanation”The TRUNCATE statement is used to delete all records from the ‘Employee’ table, but retain the table structure for future use.
Example
Section titled “Example”TRUNCATE TABLE employee;Output
Section titled “Output”TRUNCATE TABLEExplanation
Section titled “Explanation”The TRUNCATE TABLE statement quickly removes all rows from the employee table while maintaining the structure of the table for future use. It is more efficient than using a DELETE statement without a WHERE clause.
Example
Section titled “Example”TRUNCATE TABLE Employees;Output
Section titled “Output”Command(s) completed successfully.Explanation
Section titled “Explanation”The TRUNCATE TABLE statement is a Data Definition Language (DDL) operation that is used to mark the extents of a table for deallocation (removal). In this case, all data in the ‘Employees’ table would be wiped out, providing you with a fresh but still structured space for data insertion.
Example
Section titled “Example”TRUNCATE TABLE employees;Output
Section titled “Output”No output is generated after executing the above SQL code since TRUNCATE does not return any rows affected. It performs DDL operation.
Explanation
Section titled “Explanation”In the example, the TRUNCATE TABLE statement is used to delete all data from the employees table. Unlike the DELETE statement, TRUNCATE does not generate any undo logs and thus is faster. However, it doesn’t fire DELETE triggers and you cannot rollback data.
Example
Section titled “Example”TRUNCATE TABLE employees;Output
Section titled “Output”Query OK, 0 rows affected (0.01 sec)Explanation
Section titled “Explanation”In the example provided, the TRUNCATE TABLE statement is used to delete the entire data from the ‘employees’ table but not the table structure. The output specifies that the query was executed successfully.