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 Standard 2008 R2 10CAL 228-09180

Price: $2040
Buy It Now
SQL Server 2008 2005 Training Exam Test Developer DVD Enterprise Book mcts 5cal

Current Price: $16.99
Current Bids: 0
★ NEW ★ MS SQL 2005 Server Standard with CAL ★ L@@K PRICE REDUCTION★

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

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

Price: $1450
Buy It Now
Microsoft SQL Server 2005 Workgroup Edition 5 CAL, New Retail, PN A5K-01017

Price: $699.95
Buy It Now







Copyright 2012 - TSQLTutorials.com