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


Factory Sealed - 228-04023 Microsoft SQL Server 2005 Standard Edition 5 CAL

Price: $425
Buy It Now
Microsoft SQL Server 2016 Standard 10 Cal Part number 228-10602

Price: $2599
Buy It Now
Microsoft SQL Server 2008R2 Standard 5CAL +Server License Pack NEW Short Sale!

Price: $499
Buy It Now
NEW Sealed MICROSOFT SQL Server 7.0 228-00325 5 CAL

Price: $35
Buy It Now
Microsoft SQL Server 2008 R2 Standard 10 CAL +Server License Key Pack Short SALE

Price: $579
Buy It Now
Microsoft SQL Server 2008 R2 Standard 25 CAL +Server License Key Pack SHORT SALE

Price: $610
Buy It Now







Copyright 2016 - TSQLTutorials.com