- SQL Basics
- SQL Introduction
- SQL Syntax
- SQL Sample Database
- SQL SELECT
- SQL WHERE
- SQL ORDER BY
- SQL DISTINCT
- SQL LIMIT
- SQL FETCH
- SQL AND
- SQL OR
- SQL BETWEEN
- SQL IN
- SQL LIKE
- SQL IS NULL
- SQL Comparison Operators
- SQL Logical Operators
- SQL Alias
- SQL CASE
- Joins and Subqueries
- SQL INNER JOIN
- SQL LEFT JOIN
- SQL RIGHT JOIN
- SQL FULL OUTER JOIN
- SQL SELF JOIN
- SQL CROSS JOIN
- SQL Subquery
- SQL Correlated Subquery
- SQL UNION
- SQL INTERSECT
- SQL EXCEPT
- Aggregate Functions
- SQL AVG
- SQL COUNT
- SQL MAX
- SQL MIN
- SQL SUM
- SQL GROUP BY
- SQL HAVING
- SQL ROLLUP
- SQL CUBE
- SQL GROUPING SETS
- Database Management
- SQL CREATE DATABASE
- SQL ALTER DATABASE
- SQL DROP DATABASE
- SQL BACKUP DATABASE
- SQL SHOW DATABASES
- SQL SELECT DATABASE
- Table Management
- SQL CREATE TABLE
- SQL ALTER TABLE
- SQL ADD COLUMN
- SQL DROP COLUMN
- SQL DROP TABLE
- SQL TRUNCATE TABLE
- SQL SHOW TABLES
- SQL RENAME TABLE
- SQL Constraints
- SQL Primary Key
- SQL Foreign Key
- SQL UNIQUE Constraint
- SQL CHECK Constraint
- SQL NOT NULL Constraint
SQL TRUNCATE TABLE
The TRUNCATE TABLE
statement in SQL is used to remove all rows from a table without deleting the table structure.
Key Features of SQL TRUNCATE TABLE
- Removes all records from a table but keeps the structure intact.
- Resets identity columns (Auto Increment values).
- Faster than
DELETE
because it does not log individual row deletions. - Cannot be rolled back in some databases.
SQL TRUNCATE TABLE Syntax
TRUNCATE TABLE table_name;
Example: Truncating a Table
TRUNCATE TABLE Employees;
- Deletes all rows from the
Employees
table but keeps the structure.
Difference Between TRUNCATE and DELETE
Summary
TRUNCATE TABLE
removes all rows from a table efficiently.- It resets auto-increment values.
- It is faster than
DELETE
as it does not log each row deletion. - It cannot be rolled back in some databases.