SQL update statement

      No Comments on SQL update statement

The SQL update Statement is used to update existing records in a table. The update statement does not insert or delete a new record. The update statement modifies an existing record in a table.


Syntax:

  • UPDATE table_name
    SET column1=value1,column2=value2,...
    WHERE some_column=some_value;
    

Demo database: Customers

C.idC.nameC.contactC.address
123eed3Ramesh987654321#001,sec-19 c chd
aa22103Tarun987650000#12,sec-14 b chd
00146hhSia812300912#212,sec-86 panchukula
144dcv4Rahul700912366#001,sec-19 c chd

SQL update statement examples:

UPDATE Multiple Columns

To update more than one column, use a comma as seperator.We use the following SQL statement:

UPDATE Customers
SET C.contact='9000001100', C.address='#30,B-street Mexico'
WHERE C.id='aa22103'; 

Result:

C.idC.nameC.contactC.address
123eed3Ramesh987654321#001,sec-19 c chd
aa22103Tarun9000001100#30,B-street Mexico
00146hhSia812300912#212,sec-86 panchukula
144dcv4Rahul700912366#001,sec-19 c chd


UPDATE Multiple Records

In an update statement, it is the WHERE clause that determines how many records which will be updated.

UPDATE Customers
SET C.name='Sam'
WHERE C.address='#001,sec-19 c chd'; 

Result:

C.idC.nameC.contactC.address
123eed3Sam987654321#001,sec-19 c chd
aa22103Tarun9000001100#30,B-street Mexico
00146hhSia812300912#212,sec-86 panchukula
144dcv4Sam700912366#001,sec-19 c chd

Leave a Reply

Your email address will not be published. Required fields are marked *