Tuesday, May 29, 2007

SQL Statement Example for UPDATE and DELETE

UPDATE Statement
UPDATE statement is used to edit and modify the data in a table. Below showing the example for Update and Delete Statement.



Name

Income

Company

Position

Angle4500Ajax Tech LimitedManager
Helen6900Programmingschools LimitedCEO
Micheal4000SQLTutorial LimitedDBA
Nick5000Programmingschools LimitedProgrammer


Table Name: Testing

SQL Statement With Example

UPDATE TESTING SET POSITION='BOSS' WHERE NAME='HELEN'
- Position Column updated from CEO to BOSS using the update statement with 1 condition name=helen.


NameIncomeCompanyPosition
Angle4500Ajax Tech LimitedManager
Helen6900Programmingschools LimitedBOSS
Micheal4000SQLTutorial LimitedDBA
Nick5000Programmingschools LimitedProgrammer




UPDATE TESTING SET POSITION='Head of Department' WHERE NAME='HELEN' AND COMPANY='Programmingschools Limited'
- Position Column updated from BOSS to Head of Department using the update statement with 2 condition name=helen and company=Programmingschools Limited.


NameIncomeCompanyPosition
Angle4500Ajax Tech LimitedManager
Helen6900Programmingschools LimitedHead of Department
Micheal4000SQLTutorial LimitedDBA
Nick5000Programmingschools LimitedProgrammer



DELETE Statement
DELETE FROM TESTING WHERE NAME='Angle'
-Delete row using delete statement with condition name=angle.


NameIncomeCompanyPosition
Helen6900Programmingschools LimitedHead of Department
Micheal4000SQLTutorial LimitedDBA
Nick5000Programmingschools LimitedProgrammer




DELETE FROM TESTING
-Whole table deleted


For more information for SELECT Statement, click here