T-SQL Tutorials - TSQLTutorials.com



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


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:

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
No Records

228-09586 Microsoft SQL Server 2012 Standard 10 CAL (Not to US Version) - Sealed

Price: $1975
Buy It Now
NEW SEALED MS SQL Server 2012 Standard SP1 - 1 Server 5 CAL License 64-Bit

Current Price: $595
Current Bids: 0
A5K-02817 Microsoft SQL Server 2008 Workgroup R2 5 CAL - Sealed

Price: $575
Buy It Now
228-04023 Microsoft SQL Server 2005 Standard 5 CAL - Sealed

Price: $885
Buy It Now
MS SQL Server 2008 R2 Enterprise, 1 Server, with 5 CAL License. New.

Price: $595
Buy It Now
Microsoft SQL Server 2005 Standard 5 CAL License Sheet

Price: $315
Buy It Now

Copyright 2014 - TSQLTutorials.com