The DELETE statement is used
to delete records in a table.
SQL DELETE Syntax
DELETE FROM table_name
WHERE some_column=some_value |
Note: Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!
SQL DELETE Example
The "Persons" table:
Id
|
LastName
|
FirstName
|
Address
|
City
|
1
|
Navis
|
Anto
|
Madras
|
TVL
|
2
|
Ji
|
Bala
|
Bombay
|
TVL
|
3
|
Christopher
|
Franklin
|
America
|
KK
|
4
|
Nilsen
|
Johan
|
Bakken 2
|
KK
|
5
|
Tjessem
|
Jakob
|
Nissestien 67
|
TVL
|
Now we want to delete the person "Tjessem, Jakob" in the "Persons" table.
We use the following SQL statement:
DELETE FROM Persons
WHERE LastName='Tjessem' AND FirstName='Jakob' |
The "Persons" table will now look like this:
Id
|
LastName
|
FirstName
|
Address
|
City
|
1
|
Navis
|
Anto
|
Madras
|
TVL
|
2
|
Ji
|
Bala
|
Bombay
|
TVL
|
3
|
Christopher
|
Franklin
|
America
|
KK
|
4
|
Nilsen
|
Johan
|
Bakken 2
|
KK
|
Delete All Rows
It is possible to delete all rows in a table without deleting the
table. This means that the table structure, attributes, and indexes will be
intact:
DELETE FROM table_name
or DELETE * FROM table_name |
Note: Be very careful when deleting records. You cannot undo this statement!
0 comments:
Post a Comment