SQL DELETE FROM

The purpose of the DELETE FROM statement is to delete one or more rows from a table.

Example: you want to delete rows in the table revenues
corresponding to the year 2010. The syntax is the following:

delete from revenues
where year=2010

In this query:

  • revenues is the table in which we delete the rows.
  • where year=2014: we delete only rows for which year = 2014.

What happens if you do not put any where statement?”>

If you do not put any where statement, you will delete all rows in the table.

Will the rows be deleted permanently?

Yes, this command deletes the rows permanently. In a professional environment, information is not permanently deleted. Instead we use one of the following strategies:

  • each customer data has a status. We change this status from “active” to “inactive” instead of deleting the data.
  • if we ever delete a row, we make a copy of it in another database before deleting it.

Why deleting data to put it in another database?

Let us take the example of a website accessing data from a database. The more the rows in this database, the more time it takes for the website to retrieve data from it.

To improve the performance:

  • we copy the data that is not useful to a database not accessed by the website (called an archive database).
  • if the copy was successful, we delete this data from the database accessed by the website.

As a result:

  • the data is not lost forever (it is present in the archive database).
  • there are fewer rows in the database accessed by the website, which increases its performance.

I invite you to go to the next chapter about database administration.
 
Share on:

Something not clear? Ask your question here:

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
 

Author:
Last udpated: September 10, 2017
Created: September 18, 2014