Latest updates

[5]

SQL Delete Statement




The DELETE statement is used to delete records in a table. or to delete rows 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

“Persons” TABLE:
P_Id
LastName
FirstName
Address
City
1
Suhail
Osmani
Maharaj Nagar
Sitapur
2
Maxwel
Tom
Biswan
Sitapur
3
Rahi
Ayon
Okhla
Delhi
4
Nyla
Johan
Bakken 2
Delhi
5
Thoria
Jakob
New Road
Sitapur
Now we want to delete the person "Thoria, Jakob" in “Persons” TABLE.
We use the following SQL statement:
DELETE FROM Persons WHERE LastName='Thoria' AND FirstName='Jakob'
“Persons” TABLE will now look like this:
P_Id
LastName
FirstName
Address
City
1
Suhail
Osmani
Maharaj Nagar
Sitapur
2
Maxwel
Tom
Biswan
Sitapur
3
Rahi
Ayon
Okhla
Delhi
4
Nyla
Johan
Bakken 2
Delhi

 

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
Note: Be very careful when deleting records. You cannot undo this statement!
SQL Delete Statement SQL Delete Statement Reviewed by Admin on 04:18:00 Rating: 5

No comments:

Sora Templates