Skip to main content

SQL DELETE Statement

Body

When you insert data into your table you may need to update it sometimes. Not so often we inserted or updated a wrong data. That’s why there is a Delete statement.

To delete some record from the database tables we use the SQL Delete statement, the Delete Statement deletes the data row from the table which meets the condition specified in the where clause.

The delete command has the following syntax:

DELETE FROM table_name WHERE column= value

Consider that we want to delete all the users from the table who are married, and then the delete statement will be like:

DELETE FROM users WHERE martialstatus=”married”

The resulting data of users table will be as

Users:

Firstname Lastname Age Maritalstatus Country
Bill Steve 20 Single Usa
Steve Hills 30 Single france
Tom Jerry 20 Single USA

Similarly we can delete some row with multiple conditions.

Say we want to delete users who are from france and are single then the SQL delete statement will be like:

DELETE FROM users WHERE (Maritalstatus=”Single” and Country=”france”)

The resulting data will be like:

Firstname Lastname Age Maritalstatus Country
Bill Steve 20 Single Usa
Tom Jerry 20 Single USA

Never ever forget to write the where clause in the delete command, if you accidently forgot to include the where clause in the delete command then all the data of the table will be flushed (wiped away).

Consider this example:

DELETE FROM users

Then all data will be erase.

Firstname Lastname Age Maritalstatus Country

So, you can simply exclude the where clause if you wish to erase all the data from the table.

Comments

Submitted byAnonymous (not verified)on Sun, 08/14/2011 - 15:55

I don't know how to usethe delete code...! can u help me...?

Add new comment