TRUNCATE
TRUNCATE is an SQL statement that is used to delete all rows from a table. Instead of deleting the data row by row, TRUNCATE efficiently deallocates the data pages assigned to the table, providing better performance than DELETE. Important to note, this operation cannot be rolled back.
Example
Output
Explanation
The TRUNCATE statement is used to delete all records from the ‘Employee’ table, but retain the table structure for future use.
Example
Output
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
Output
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
Output
No output is generated after executing the above SQL code since TRUNCATE
does not return any rows affected. It performs DDL operation.
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
Output
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.