DELETE:
DELETE
Statement is used to delete rows from a table.
The Syntax of a SQL DELETE statement is:
Syntax to DELETE a table:
DELETE
FROM table_name [WHERE Condition];
|
TRUNCATE:
TRUNCATE
command is used to delete all the rows from the table and free the space
containing the table.
Syntax to TRUNCATE a table:
TRUNCATE
TABLE table_name
|
Differentiate
between DELETE and TRUNCATE:
DELETE
|
TRUNCATE
|
DELETE
is a DML Command.
|
TRUNCATE
is a DDL command.
|
DELETE
statement is executed using a row lock, each row in the table is locked for
deletion.
|
TRUNCATE
TABLE always locks the table and page but not each row.
|
We
can specify filters in where clause
|
Cannot
use Where Condition.
|
It
deletes specified data if where condition exists.
|
It
Removes all the data.
|
Delete
activates a trigger because the operation are logged individually.
|
TRUNCATE
TABLE cannot activate a trigger because the operation does not log individual
row deletions.
|
Slower
than truncate because, it keeps logs.
|
Faster
in performance wise, because it doesn't keep any logs.
|
Rollback
is possible.
|
Rollback
is not possible.
|
No comments:
Post a Comment