Wednesday, 10 October 2012

UPDATE STATEMENT





The “Update” statement is used to update the existing records in a table

Syntax:
Update Single column:
            UPDATE <Table name>
            SET Column 1= Value
            WHERE SomeColumn=SomeValue

          Example:
                   The table Sample_Table is having six records. Find the below screen 
                      shot for reference.


                   The last record (Record ID is 106) ‘Gender’ is M (Male). I need to
                        update it as ‘F’.

           SQL Statement:
           UPDATE Sample_Table SET Gender='F'
           WHERE ID=106

           Result:



Update multiple columns:
           UPDATE <Table name>
           SET Column 1= Value 1, Column 2=Value 2, …, Column N=Value N
           WHERE SomeColumn=SomeValue

          Example:
          From the same table (Sample_Table) the 5th record, ID is ‘105’,
Name is ‘E’ and Gender is ‘F’. I need to update the Name as ‘H’ and 
Gender as ‘M’.

         SQL Statement:
         UPDATE Sample_Table SET Name='H', Gender='M'
         WHERE ID=105

         RESULT:





No comments:

Post a Comment