ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
Answer
# 1
truncate basically clears the data from the rows of a 
specified colomn.
e.g. truncate colomn_name from table_name
then this will only empty the colomn

delete is used to simpy delete anything from the table.
e.g. delete table_name
this will remove the whole table from the database.
 
Is This Answer Correct ?    3 Yes 17 No
Xyz
 
  Re: WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
Answer
# 2
if u use delete to remove the data from the table,this will 
delete the data.after using rollback  the removed data can 
be retrived.But in case of, truncate , it will delete the 
data  and that can't ever be retrived.even after using 
rollback also. but the table structure of the table  will 
be there

if u are using drop command , this will delete  entire 
table.and its structure.
 
Is This Answer Correct ?    13 Yes 6 No
Nirmala.s
 
 
 
  Re: WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
Answer
# 3
Both the operations can be rolled back.The difference is, 
DELETE TABLE is a logged operation, so the deletion of each 
row gets
logged in the transaction log, which makes it slow. 
TRUNCATE TABLE
also deletes all the rows in a table, but it won't log the 
deletion of
each row, instead it logs the deallocation of the data 
pages of the
table, which makes it faster.
 
Is This Answer Correct ?    12 Yes 3 No
Archana Motagi
 
  Re: WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
Answer
# 4
truncate is used for deleting  all data from table.
it is similar to delete command without condition.
         main differences b/w delete & truncate are
1.truncate is faster in execution than delete which will
restructure the complete table without bothering of data.
where as delete checks the data row by row wrotes 
information into log and deletes.
2.with truncate we cannot use any conditions
 
Is This Answer Correct ?    9 Yes 0 No
Nageswarao
 
  Re: WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
Answer
# 5
If identity is set on column and current identity col is 10
then if truncate and delete is done then for truncate
identity col will be 1 and for delete then it will be 11.
 
Is This Answer Correct ?    4 Yes 0 No
Firoz Shaikh
 
  Re: WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
Answer
# 6
TRUNCATE TABLE is functionally identical to DELETE 
statement with no WHERE clause: both remove all rows in the 
table. But TRUNCATE TABLE is faster and uses fewer system 
and transaction log resources than DELETE. 

The DELETE statement removes rows one at a time and records 
an entry in the transaction log for each deleted row. 
TRUNCATE TABLE removes the data by deallocating the data 
pages used to store the table's data, and only the page 
deallocations are recorded in the transaction log.

TRUNCATE TABLE removes all rows from a table, but the table 
structure and its columns, constraints, indexes and so on 
remain. The counter used by an identity for new rows is 
reset to the seed for the column. If you want to retain the 
identity counter, use DELETE instead. If you want to remove 
table definition and its data, use the DROP TABLE statement.

You cannot use TRUNCATE TABLE on a table referenced by a 
FOREIGN KEY constraint; instead, use DELETE statement 
without a WHERE clause. Because TRUNCATE TABLE is not 
logged, it cannot activate a trigger. 

TRUNCATE TABLE may not be used on tables participating in 
an indexed view.
 
Is This Answer Correct ?    2 Yes 1 No
Shireen
 
  Re: WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
Answer
# 7
Delete - is logged operation,so deletion of each row get 
logged into the transcation log. 
Truncate - won't logged
Delete - use where condition
Truncate - Can't use where condition
delete - fire the trigger
Trunacte - can't fire the triggger
 
Is This Answer Correct ?    2 Yes 0 No
Hari
 
  Re: WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
Answer
# 8
Delete doesn't reset identity column seed if you have 1
identity column in the table.
Truncate resets identity column seed to the original value.
 
Is This Answer Correct ?    5 Yes 0 No
Monal
 
  Re: WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
Answer
# 9
TRUNCATE DELETE DIFFERENCE

Truncate command will delete all records and the most 
important thing to make note of 

truncate command is since truncate command cannot be rolled 
back one must make 
sure to take proper backup of table data before performing 
the truncate command.

Truncate command is thus used to remove all rows from 
either a table or a cluster.

 If one wants to use the truncatecommand in a cluster they 
can use 
it only in an indexed cluster and not in a hash cluster.

 
Though the functionality of delete and truncate looks on 
the outward same

the main differences between truncate and delete statements 
are 

truncate is a DDL statement whereas 
delete is a DML statement. 


Truncate command cannot be rolled back but 
delete command can be rolled back. 


As a result, as explained 

before truncate command is faster than delete command. 

Another main difference between delete andtruncate command 
is 

delete command can be used with a where clause to delete 
specific rows from a table.

 If the where clause is not specified in a delete 
statement, 
  all rows are deleted from the table. 

Thus delete command can be used to delete specific or all 
rows from a table. 
But truncate command deletes all rows from the table.
The general syntax of truncate command is
TRUNCATE TABLE tablename;
For instance if one wished to truncate a table named as 
exforsys 
it is done by using the command as follows:


TRUNCATE TABLE exforsys;
 
Is This Answer Correct ?    0 Yes 1 No
Nadiya
 
  Re: WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT
Answer
# 10
Guys, Please remember TRUNCATE CAN BE ROLLED BACK.

DELETE TABLE is a logged operation, so the deletion of each
row gets logged in the transaction log, which makes it slow. 

TRUNCATE TABLE also deletes all the rows in a table, but it
won't log the deletion of each row, instead it logs the
De-allocation of the data pages of the table, which makes it
faster. 

Because TRUNCATE TABLE is not logged, it cannot activate a
trigger.
TRUNCATE can not be Rolled back using logs.
TRUNCATE is DDL Command.
TRUNCATE Resets identity of the table.

DELETE
DELETE removes rows one at a time and records an entry in
the transaction log for each deleted row.
If you want to retain the identity counter, use DELETE
instead. If you want to remove table definition and its
data, use the DROP TABLE statement.
DELETE Can be used with or without a WHERE clause
DELETE Activates Triggers.
DELETE Can be Rolled back using logs.
DELETE is DML Command.
DELETE does not reset identity of the table.
 
Is This Answer Correct ?    1 Yes 0 No
Mohammed
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
What is the use of DBCC commands?  1
in tabase table having a column in it empname field is there which having 5 duplicate values is there i want deleted all the duplicates i want showing only one name only.  7
wat is the main diff between sql server 2000and sql server 2005 Jade-Software6
Which virtual table does a trigger use? TCS6
What is indexed views? plz explain with example?  1
What is the difference between a Application Server and a Database Oracle2
What is a view? is View updatable? IBM11
What is a materialized view?  2
What is transcation?Plz give One example?  2
What is the difference between Drop and Truncate  10
how to dispaly a particular row details from a given table  1
Can we have more than one NULL in a column having unique constraint? 247Customer7
What is a join and their types? Challenger-Financial2
explain different types of jions with examples briefly? Zensar3
Assume,there are three tables in a database, Can i have both primary key and foreign key for each table in the same database?  4
what is hash table Teledata2
What is the diff between Static Queries and Dynamic queries give me some examples CSC1
How do you find the number of rows in a table?  5
Rate yourself in .NET and SQL ? Cognizent1
what is the maximum size of a row in sql server 2000 and 2005  2
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com