Truncate table

SQL Truncate table

To truncate a table from database uses the command TRUNCATE TABLE.
Truncate removes all rows from a table.
Truncate command is used without any clauses.
When the Truncate command is executed, the table is locked automatically.

SQL Truncate table syntax

TRUNCATE TABLE my_table_name;

Example

CREATE TABLE my_lessons
(
ID INT PRIMARY KEY,
TITLE VARCHAR(250) NOT NULL,
);

INSERT INTO my_lessons(id, title) VALUES (1,'SQL'), (2,'T-SQL');

TRUNCATE TABLE my_lessons;