Back-End Development SQL basics

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:

Demo database: Customers

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #001,sec-19 c chd
aa22103 Tarun 987650000 #12,sec-14 b chd
00146hh Sia 812300912 #212,sec-86 panchukula
144dcv4 Rahul 700912366 #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:


Result:

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #001,sec-19 c chd
aa22103 Tarun 9000001100 #30,B-street Mexico
00146hh Sia 812300912 #212,sec-86 panchukula
144dcv4 Rahul 700912366 #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.


Result:

C.id C.name C.contact C.address
123eed3 Sam 987654321 #001,sec-19 c chd
aa22103 Tarun 9000001100 #30,B-street Mexico
00146hh Sia 812300912 #212,sec-86 panchukula
144dcv4 Sam 700912366 #001,sec-19 c chd