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

TRUNCATE TABLE Employee;

Output

Query OK, 0 rows affected (0.00 sec)

Explanation

The TRUNCATE statement is used to delete all records from the ‘Employee’ table, but retain the table structure for future use.

Example

TRUNCATE TABLE employee;

Output

TRUNCATE TABLE

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

TRUNCATE TABLE Employees;

Output

Command(s) completed successfully.

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

TRUNCATE TABLE employees;

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

TRUNCATE TABLE employees;

Output

Query OK, 0 rows affected (0.01 sec)

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.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.