• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

  • Home
  • Test Case Examples
  • Interview Questions
  • Interview Questions Asked
  • Java
  • Selenium
  • Manual Testing
  • SQL Tutorial For Beginners
  • Difference
  • Tools
  • Contact Us
  • Search
SoftwareTestingo » SQL » SQL Tutorial » SQL TRUNCATE

SQL TRUNCATE

Last Updated on: February 28, 2023 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • What Does the SQL SERVER TRUNCATE TABLE Statement Do?
  • SQL Truncate Example

The SQL TRUNCATE / SQL SERVER TRUNCATE command is a data definition language statement that can delete all the information from an existing database table without removing the table itself. This will free up space within the table, but users should remember that these changes may not be reversible on some databases. As it’s a DDL statement, there’s no need to commit each step – when you run this command, it automatically commits at completion. Use caution with this, as mistakes cannot generally be undone!

The TRUNCATE statement functions similarly to the DELETE statement, But you cannot use a WHERE clause when using this SQL TRUNCATE command.

Syntax

The basic syntax for the Sql Server Truncate statement is:

TRUNCATE TABLE table_name;

What Does the SQL SERVER TRUNCATE TABLE Statement Do?

The SQL SERVER TRUNCATE TABLE statement in SQL works by removing all rows from an existing table and resetting it to zero entries. This means that after running a truncate statement on the table, you will no longer have any row records stored there.

When you truncate a table, its structure of it, including columns, indexes, constraints, and relationships, is still intact. It’s similar to erasing data from a table but leaving the overall shape in place.

SQL Truncate Example

Let us take an example for a better understanding of SQL server truncate statements. Here are the Person table details:

SQL TRUNCATE 1

Now, let us run the SQL truncate statement.

TRUNCATE TABLE Person;
SELECT * FROM Person;

After running the above script, all the rows will be deleted.

SQL TRUNCATE 2

Note: The TRUNCATE clause doesn’t support the WHERE clause.

Truncating Large Tables

Microsoft SQL Server can delete or empty a table with more than 128 extents without acquiring locks. This makes it possible to truncate/drop large tables quickly and efficiently.

Conclusion:

This tutorial has provided the information needed to use SQL Server TRUNCATE TABLE statements to quickly remove all data from a table, especially if it is large. If you have any questions after reviewing this article, please comment in the comment section.

    SQL SELECT Statement
    SQL SELECT Statement
    SQL Data Types
    SQL Data Types
    SQL Alter Table Add Column & DROP Column SQL Server
    SQL Alter Table Statement
    SQL Delete Row Table Statement
    SQL Delete
    SQL Tutorial For Beginners
    SQL Tutorial For Beginners
    SQL Constraints
    SQL Constraints
    SQL Database
    SQL Database
    SQL Table
    SQL Table
    Difference Between TRUNCATE , DELETE and DROP in SQL Server
    Difference Between TRUNCATE , DELETE and DROP in SQL Server
    SQL Comment
    SQL Comment

    Filed Under: SQL Tutorial

    Reader Interactions

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Categories

    Footer

    Java Tutorial for Beginners | Selenium Tutorial | Manual Testing Tutorial | SQL Tutorial For Beginners | GitHub Tutorial For Beginners | Maven Tutorial

    Copyright © 2023 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy ~ Testing Careers