0% found this document useful (0 votes)
26 views

The UPDATE Statement

The document compares the DROP, TRUNCATE, and DELETE commands in SQL. DROP removes the table permanently and cannot be undone, while TRUNCATE empties the table faster than DELETE by deleting all rows at once without removing the table. TRUNCATE also resets the auto-increment value, unlike DELETE which deletes rows individually and maintains the existing auto-increment values.

Uploaded by

Hemasundar Oggu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

The UPDATE Statement

The document compares the DROP, TRUNCATE, and DELETE commands in SQL. DROP removes the table permanently and cannot be undone, while TRUNCATE empties the table faster than DELETE by deleting all rows at once without removing the table. TRUNCATE also resets the auto-increment value, unlike DELETE which deletes rows individually and maintains the existing auto-increment values.

Uploaded by

Hemasundar Oggu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

DROP vs TRUNCATE vs DELETE

DROP vs TRUNCATE vs DELETE

column_1
1
2
3
4


10
DROP vs TRUNCATE vs DELETE

DROP

column_1
1
2
3
4


10
DROP vs TRUNCATE vs DELETE

DROP

column_1
1 indexes
2
3
4
+ + constraints


10
DROP vs TRUNCATE vs DELETE

DROP

column_1
1 indexes
2
3
4
+ + constraints


10
DROP vs TRUNCATE vs DELETE

DROP
- you won’t be able to roll back to its initial state, or to the last
COMMIT statement

use DROP TABLE only when you are sure you aren’t going to use the table
in question anymore
DROP vs TRUNCATE vs DELETE

TRUNCATE

column_1
1
2
3
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE ~ DELETE without WHERE

column_1
1
2
3
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE ~ DELETE without WHERE

column_1
1
2
3
4
+

10
DROP vs TRUNCATE vs DELETE

TRUNCATE ~ DELETE without WHERE

column_1
1
2
3
4
+

10
DROP vs TRUNCATE vs DELETE

TRUNCATE
when truncating, auto-increment values will be reset
DROP vs TRUNCATE vs DELETE

TRUNCATE
when truncating, auto-increment values will be reset

column_1
1
2
3
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE
when truncating, auto-increment values will be reset

column_1
1
2
3 TRUNCATE
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE
when truncating, auto-increment values will be reset

column_1 column_1
1
2
3 TRUNCATE
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE
when truncating, auto-increment values will be reset

column_1 column_1
1 11
2
3 TRUNCATE
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE
when truncating, auto-increment values will be reset

column_1 column_1
1 11
2
3 TRUNCATE
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE
when truncating, auto-increment values will be reset

column_1 column_1
1 11 1
2
3 TRUNCATE
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE
when truncating, auto-increment values will be reset

column_1 column_1
1 11 1
2 12
3 TRUNCATE
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE
when truncating, auto-increment values will be reset

column_1 column_1
1 11 1
2 12 2
3 TRUNCATE
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE
when truncating, auto-increment values will be reset

column_1 column_1
1 1
2 2
3 TRUNCATE 3
4 4

… …
10 10
DROP vs TRUNCATE vs DELETE

DELETE
DROP vs TRUNCATE vs DELETE

DELETE
removes records row by row
DROP vs TRUNCATE vs DELETE

DELETE
removes records row by row

DELETE FROM table_name


WHERE conditions;
DROP vs TRUNCATE vs DELETE

DELETE
removes records row by row

DELETE FROM table_name


WHERE conditions;

TRUNCATE ~ DELETE without WHERE


DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


- the SQL optimizer will implement different programmatic approaches
when we are using TRUNCATE or DELETE
DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


- the SQL optimizer will implement different programmatic approaches
when we are using TRUNCATE or DELETE
DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


- the SQL optimizer will implement different programmatic approaches
when we are using TRUNCATE or DELETE

TRUNCATE delivers the output much quicker than DELETE


DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


- the SQL optimizer will implement different programmatic approaches
when we are using TRUNCATE or DELETE

TRUNCATE delivers the output much quicker than DELETE


row by row row by row
DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


- the SQL optimizer will implement different programmatic approaches
when we are using TRUNCATE or DELETE

TRUNCATE delivers the output much quicker than DELETE


row by row row by row
DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


- auto-increment values are not reset with DELETE
DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


- auto-increment values are not reset with DELETE

column_1
1
2
3
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


- auto-increment values are not reset with DELETE

column_1
1
2
3 DELETE
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


- auto-increment values are not reset with DELETE

column_1 column_1
1
2
3 DELETE
4


10
DROP vs TRUNCATE vs DELETE

TRUNCATE vs DELETE without WHERE


- auto-increment values are not reset with DELETE

column_1 column_1
1 11
2 12
3 DELETE 13
4 14

… …
10 20
Next:
Next:
SQL Functions

You might also like