Tuesday, May 1, 2012

SQL DELETE

Hello Friends, Welcome to this post, where I will discuss about another SQL query known as the DELETE query.

Now we have to be extra cautious with this DELETE query, as with the DELETE query we can delete records or a whole Table.

Syntax:

DELETE FROM table_name
WHERE some_column=some_value


So lets look at our Employee Table:

PID    Name        Designation
222     Whiskey       Moderator
444    Onty             Admin
111     Gaurav         Admin
333    Kumaar        Admin
555    Rishabh        Admin
666    Rose             Admin

Now manager walks into My cabin and says, you know I have thrown out Whiskey from our company, so delete all his records.

So our Query would be:

DELETE FROM Employee
WHERE Name="Whiskey"


To be more specific,

DELETE FROM Employee
WHERE Name="Whiskey" AND PID=222


So our result set will be:

PID    Name        Designation
444    Onty             Admin
111     Gaurav         Admin
333    Kumaar        Admin
555    Rishabh        Admin
666    Rose             Admin

Now, if you do this:

DELETE * FROM Employee

All the records of Employee Table will be deleted. And you would find the Manager walking into your cabin the next moment screaming at you and saying, "Even you are fired from job with Whiskey"

So you see how hazardous one statement can be, and you have to be very careful using this query.

Hope this was informative, and don't forget to check my next post.

Thank You!

0 comments:

Post a Comment