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 2008 R2 Enterprise 25 CAL Pack +Server License Key Sealed!

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

Price: $395
Buy It Now
Lenovo Microsoft Sql Server 2014 - License - 1 User Cal - Oem - Pc -

Price: $241.71
Buy It Now
Retail Microsoft SQL Server 2008 Standard 10 CAL

Price: $1699.99
Buy It Now
Microsoft SQL Server 2014 Standard Edition 1 Server 10 CAL’s 228-10255

Price: $3329.42
Buy It Now
Microsoft Small Business Server SBS 2011 Premium Add-on SQL inc 5 CAL 2XG-00153

Current Price: $900
Current Bids: 0







Copyright 2016 - TSQLTutorials.com