Book Image

SQL Server 2014 Development Essentials

By : Basit A. Masood-Al-Farooq
Book Image

SQL Server 2014 Development Essentials

By: Basit A. Masood-Al-Farooq

Overview of this book

Table of Contents (14 chapters)
SQL Server 2014 Development Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

The TRUNCATE TABLE statement


The TRUNCATE TABLE statement is another way to delete all rows from a table. Unlike the DELETE statement, SQL Server does not log individual row deletion in a transaction log. Therefore, this operation is not recoverable because when you run the TRUNCATE TABLE statement, SQL Server just logs page deallocations that occur as a result of this operation. The TRUNCATE TABLE statement is much faster when compared to the DELETE statement, with no WHERE clause, because it uses fewer system and database transaction log resources.

You cannot use the TRUNCATE TABLE statement on tables that are referenced by a foreign key constraint, included in an indexed view, or published for transactional or merge replication. In such a situation, you are required to use the DELETE statement without a WHERE clause to remove all rows.

Tip

The TRUNCATE TABLE statement does reset identity value to its seed value, while the DELETE statement does not reset identity value. So, use TRUNCATE TABLE...