SQL Update Statement

Update Statement

Update Statement :- Update statement is used to modify existing data in Table.Update statement is a DML (Data Manipulation Language)
statement that's why  Rollback is possible for update statement.

Syntax :-  Below is the syntax for delete statement

UPDATE <Table_name> SET <column_name1>=<value1>,<column_name1>=<value1>,.. WHERE <condition>;

Note:- If "where <condition>" is not used in statement then update statement will update all records of table

1) Update all records (Without "Where" clause)
Example1:- Update COURSE to 'BSC' in Student table.
SQL>UPDATE STUDENT set COURSE='BSC' ;

2) Update selected records    
a) Single column update 
Example2:-Update course to BSC where course is BCA
SQL>UPDATE STUDENT set COURSE='BSC' where course='BCA';
 
Example3:-Update course to BSC where regid is less or equal to 105
SQL>UPDATE STUDENT set COURSE='BSC' where regid<=105;

b) multiple column update
 
Example4:-Update course to BSC and DOB to sysdate where course is BCA   
SQL>UPDATE STUDENT set COURSE='BSC',DOB=sysdate  where course='BCA';
 
Example5:-Update course to BSC and regid to regid+10 where regid less or equal to 105
SQL>UPDATE STUDENT set COURSE='BSC',regid=regid+10  where regid<=105;
   
c) Update on one table on basis of another table 
Example6:-  
SQL>UPDATE STUDENT set COURSE='BSC',DOB=sysdate  where regid in (select regno from student1);

1 comment:

  1. Your blog is in a convincing manner, thanks for sharing such an information with lots of your effort and time
    sql server dba online training India
    sql server dba online training Hyderabad

    ReplyDelete