SQL Delete Statement Notes
SQL Delete Statement Notes
STATEMENT
The DELETE Statement
the DELETE statement
removes records from a database
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
removes records row by row
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