DDL Commands in SQL SERVER: TRUNCATE

DDL: Data Definition Language

Truncate is a simple DDL command in SQL Server.

Truncate command in SQL Server works very similar to DELETE command.

Since TRUNCATE command will not store the logs,  truncated data from a table cannot be restored back.

Here is the syntax for TRUNCATE Command:

Syntax:

TRUNCATE TABLE <Table Name>

Example:

Lets see how we can truncate data from a table with the name MOBILE:

Data in the table before running Truncate command:
















Run the following command in SQL SERVER Query Window:

TRUNCATE TABLE MOBILE

Data in the table After running Truncate command:















Few important points about TRUNCATE Command in SQL Server
  1. Since TRUNCATE Command operates(manipulates) on data in the table ,many people assume it as a DML statement. But, TRUNCATE is a DDL Command.
  2. TRUNCATE Command will not operate on each row (or each data). It will operate on the entire database object. So, it will consume fewer database resources than DELETE Command
  3. TRUNCATE command will not store logs
  4. Data Truncated once cannot be restored back.

Summary:

Here we have learnt about TRUNCATE Command.

This entry was posted in . Bookmark the permalink.

One Response to DDL Commands in SQL SERVER: TRUNCATE