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

Factory Sealed - A5K-02817 Microsoft SQL Server 2008 Workgroup R2 5 CAL

Price: $565
Buy It Now
NEW & SEALED Microsoft SQL 2008 R2 Server Standard 5 CAL 32/64-Bit

Current Price: $395
Current Bids: 0
Microsoft SQL 2008 Server Standard R2 5 CAL 32/64-Bit NEW SEALED

Price: $695
Buy It Now
Microsoft SQL Server 2008 Workgroup R2 32 /x64 w/5-CAL Retail Box PN: A5K-02817

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

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

Price: $995
Buy It Now

Copyright 2014 - TSQLTutorials.com