Monday, July 28, 2008

UPDATE COMMAND

Updating A Table


To make modifications to the data present in a table, update statement is used. Update statement has the following syntax.

Syntax:

Update tablename set Col1=Val1, Col2=Val2, ... ,Col n=Val n [ Where Condition ];

Example 1:
The following update statement changes the name of student with id 3 to ‘NAVEEN’.
Update Student set Sname=’Naveen’ where Sno=3;

Example 2: The following example updates the Marks table by calculating total and average.
Update Marks set Total= (M1 + M2 + M3 ), Aveg = ( M1 + M2 + M3 ) / 3;

If you specify the where clause, then the rows that satisfy the given codition in where clause will only be updated. If you omit the where clause then all rows of the table will be updated.

No comments: