Thursday 4 December 2014

Deleting and Truncating a Table

Deleting a Table 
The DELETE statement is used to delete rows in a table.

Delete All Data 

Query :
delete from tablename  

Example :
delete from empdetails

Delete Particular Row - using Where clause

Query :
delete from tablename where columnname = value

Example :
delete from empdetails where id = 1

Be very careful when deleting records. You cannot undo this statement!

Tuncating a Table
The TRUNCATE statement is used to removes all rows from a table. The operation cannot be rolled back and no triggers will be fired. As such, TRUCATE is faster and doesn't use as much undo space as a DELETE.

Query :
truncate table tablename  

Example :
truncate table empdetails.

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Replies
    1. TRUNCATE removes all rows from a table. The operation cannot be rolled back and no triggers will be fired. As such, TRUCATE is faster and doesn't use as much undo space as a DELETE.

      We cannot use Where Clause in TRUNCATE .

      Delete