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

Dell PowerEdge 2950 6x 300GB SAS 32Gb Windows 2012 R2 SQL 2014 no CAL's Required

Price: $1699.99
Buy It Now
Microsoft SQL Server 2005 Enterprise x64 Edition Includes 25 CAL'S EDU

Current Price: $9.99
Current Bids: 1
Microsoft SQL Server 2008 Standard Edition inc 10 CAL 228-08394

Price: $3751.08
Buy It Now
Open Box - 228-04023 Microsoft SQL Server 2005 Standard Edition 5 CAL

Price: $615
Buy It Now
Microsoft SQL Server 2008 - Enterprise with 25 CAL's

Price: $27500
Buy It Now
Microsoft SQL Server 2005 Standard Edition x64 inc 5 CAL 228-04013

Price: $1718.4
Buy It Now

Copyright 2014 - TSQLTutorials.com