T-SQL Tutorials - TSQLTutorials.com

TRUNCATE TABLE Statement


Introduction

The TRUNCATE statement is used for removing all records from a table. The TRUNCATE statement is not a logged transaction. The TRUNCATE Statement has a simple syntax:

  • TRUNCATE tablename

Example

In this example we will assume that the 'Employees' table contains the follow columns: 'Name', 'Position', 'Office' and 'Salary'. SELECT *
FROM Employees
Here is a sample resultset from the above SELECT query:

NamePositionOfficeSalary
Joe GrapeManagerHouston80000
John PlumSoftware DeveloperHouston65000
Frank AppleSoftware DeveloperCleveland62000
Patty PineappleSoftware DeveloperCleveland60000
Judy PeachSoftware DeveloperBoston50000
Jane OrangeProject ManagerHouston75000




We'll use the TRUNCATE statement to remove all the records from the table. TRUNCATE TABLE Employees

Now we'll try to query the table again. We will find out that there are no longer any rows in the table. SELECT *
FROM Employees
NamePositionOfficeSalary
No Records


Microsoft SQL Server 2014 Standard Edition Server w/20 CAL’s

Price: $641.99
Buy It Now
SQL Server 2014 Standard Edition, 32bit & 64bit, Media & License w/25CAL

Price: $549.99
Buy It Now
MSFT SQL Server 2016 Standard Edition x64 64bit | Full Edition |Original| 25CAL

Price: $999.99
Buy It Now
MSFT SQL Server 2016 Standard Edition x64 64bit | Full Editon | Original | 10CAL

Price: $549.99
Buy It Now
MSFT SQL Server 2008 R2 Enterprise Edition 25 CAL 32/64-Bit

Price: $299.99
Buy It Now
MSFT SQL Server 2008 R2 Standard Edition 32/64-Bit 10 CAL Edition

Price: $224.99
Buy It Now







Copyright 2017 - TSQLTutorials.com