/    /  SQL DELETE

SQL DELETE

In this tutorial, we will discuss about how to delete the data inside a table.

DELETE statement are used to delete the rows from existing tables which are in your schema 

You must fulfill the following two conditions;

  • Mention the name of the table from which you want to delete data.
  • Mention which row should be deleted by using the condition in the WHERE clause.

Syntax:

Delete from table_name 
where condition;

For Example:

I have already created a table called users and we have the four rows of data and I wanted to delete the data where exactly the users who have the age are equal to 26.

SQL 42 (i2tutorials)

What happens whenever you write a query to insert or update data, it will be there only in the ram. So in order to get that one to save to your disk, which is a permanent storage? You need to give a command called commit.

commit;

By using Commit option, it would be also helpful, when you abruptly close the SQL Developer or the SQL plus there will be an auto-commit that will happen in the background. So where your data will be safe.

So let’s use the following example

delete from users where age=26;
select * from users;

Output:

SQL 43 (i2tutorials)

In the above you can see that one row is deleted.

If you don’t give where condition it will be a complete mess up. Why because when there is no condition-based it will delete all the rows in your table. So let me show you even that part as well with the same example.

Example:

delete from users;
select * from users;

Output:

SQL 44 (i2tutorials)

So in this output, you can clearly see that all the rows got deleted, because we haven’t used WHERE condition.