Wednesday, 10 October 2012

Lesson : 15 - UPDATE Statement


How to update existing data in tables ?

Syntax :

UPDATE  <table name>  SET column1  =  value or expression1, col2=expr2,.... WHERE conditions ;

Update statement is used to  modify existing data in the table.

Where clause in Update statement is optional, if we omit it, it will update the specified column in all the records in that table.

Note  : COMMIT is required to save the changes permanently

Examples :

1)      To update salary to 35000 to everyone

               SQL> UPDATE  emp SET sal=35000;

               SQL> Commit;

2)      To give 25% hike on salary to everyone

SQL> UPDATE emp SET sal= sal + (sal * 25/100);

       SQL> Commit;

3)      To update Prakash’s age as 40 whose employee id is 714

                       SQL> UPDATE emp SET age=40 WHERE empname=’Prakash’ and empid=714;

       SQL> Commit;

 

 

No comments:

Post a Comment