SQL Truncate Table, SQL Tutorial, Global Guide Line Technology.
Forum | Blog |


Basic SQL Guide.           
SQL Introduction.               
 What is Table?                  
 SQL Create Table.            
 SQL Insert Statement.      
 SQL Select Keyword.        
 SQL Order by clause.        
 SQL Count Statement.      
 SQL Group By Clause.      
 SQL Having Clause.          
 SQL Alias Tables.             
 SQL Join Tables.              
 SQL Outer Join.               
 SQL Update Statement.   
 SQL Delete Statement.    
 SQL Distinct Keyword.      
 SQL Where Keyword.       
 SQL And Or Keyword.      
 SQL In Keyword.              
 SQL Between Keyword.   
 SQL Like Keyword.          
 SQL Functions.                
 SQL Concatenate.           
 SQL Substrings.               
 SQL Trim Function.         
 SQL Constraints.              
 SQL Primary Key.            
 SQL Foreign Key.            
 SQL Create Views.           
 SQL Create Index.           
 SQL Alter Table.             
 SQL Drop Table.             
 SQL Truncate Table.
 SQL Summary.                

SQL Tutorial >> SQL Truncate Table.

     Back             Next     

Sometimes we wish to get rid of all the data in a table. Now SQL Tutorial will explain that one way of doing this is with SQL DROP TABLE command, which we saw in the last lesson of out SQL Tutorial. But what if we wish to simply get rid of the data only and not the entire table itself? For this, we can use the SQL TRUNCATE TABLE command.  With the help of this command we can make the table empty from its data only. 
The syntax for SQL TRUNCATE TABLE is as under

Syntax for SQL Truncate Table

TRUNCATE TABLE "table_name"

So, if we want to truncate the table of Employees that we created in SQL CREATE TABLE section of our SQL Tutorail, we simply type this below query,

Example of SQL Truncate Table


If we try to TRUNCATE a table, and the table is have a relationship with other table like Employees_Salary with the constraint of SQL Foreign Key then we can't TRUNCATE the table with this SQL Truncate Table command, here we need to TRUNCATE the Employees_Salary table first because Employees_Salary is depending on it and that is having some records. That's why we need to TRUNCATE both tables and the sequence is to empty that table which is based on SQL Foreign Key or remove this constraint first. Then we can TRUNCATE any table with SQL Truncate statement.

     Back             Next     

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright 2005 -  2022 www.globalguideline.com All rights reserved. (Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher) 378 visitors are online now