Difference Between Delete , Drop and Truncate command in sql

Delete command

The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows. If no WHERE condition is specified, all rows will be removed.

Example:

101 Id is deleted in user table

Delete from user where id='101'; 

delete all records from user table

 
Delete * from user ;

The DROP command removes a table from the database. All the tables' rows, indexes and privileges will also be removed.the operation cannot be rolled back.

Example:

user table removed from a database

Drop table user; 

Truncate command

TRUNCATE removes all rows from a table,not a whole table from a database. The operation cannot be rolled back.

Example:

all rows delete from a user table not a table delete

truncate table user; 

No comments:

Post a Comment