Delete - Delete command is used to Remove or delete the data from the Database, Delete command delete the row from table of Database, where cause in sql and mysql delete command is optional, it identify the row in table which we want to delete, no where cause delete all the data from the table
After Performing delete Operation you need to commit or Rollback the transaction to change the permanent or to undo, this operation will cause all the delete trigger in the table
"select count(*) from user_master"
count
-----------------------------------------
14
"delete from user_master where name='xyz' "
3 row deleted.
----------------------------------------------
select count(*) from user_master
count
------------------------------------------
11
if you want to delete all the data from the table then execute below query
delete from user_master;
=======================================================================
Truncate table tablename - syntax
truncate table user_master;
-------------------------------------------------
table truncate
------------------------------------------
select * from user_master;
--------------------------------------
0 row
======================================================================
Syntax - Drop table tablename
drop table user_master;
Drop and Truncate are DDL(Data Definition Language) command, where as DELETE is DML( Data manipulation language). Delete command operation can be roll back(undone) while Drop and Truncate Operation cannot be rolled back.
After Performing delete Operation you need to commit or Rollback the transaction to change the permanent or to undo, this operation will cause all the delete trigger in the table
"select count(*) from user_master"
count
-----------------------------------------
14
"delete from user_master where name='xyz' "
3 row deleted.
----------------------------------------------
select count(*) from user_master
count
------------------------------------------
11
if you want to delete all the data from the table then execute below query
delete from user_master;
=======================================================================
Truncate : Truncate command is used to delete all the row from the table, once you truncate then that operation can not rollback. Truncate is Faster
Truncate table tablename - syntax
truncate table user_master;
-------------------------------------------------
table truncate
------------------------------------------
select * from user_master;
--------------------------------------
0 row
======================================================================
Drop: Drop remove the table from the Database, all the tables, index and privileges will also be removed, this operation cannot roll back. be carefully while using this command.
Syntax - Drop table tablename
drop table user_master;
Drop and Truncate are DDL(Data Definition Language) command, where as DELETE is DML( Data manipulation language). Delete command operation can be roll back(undone) while Drop and Truncate Operation cannot be rolled back.
No comments
Post a Comment