UPDATE Statement in SQL – Beginner Friendly Guide

🛠️ UPDATE Statement in SQL

The UPDATE statement in SQL is used to modify the existing records in a table. Let's understand it step by step.

1. Create a Table


CREATE TABLE Employee (
   Id INT,
   Name VARCHAR(20),
   City VARCHAR(20)
);
  

2. Insert Data into Table


INSERT INTO Employee VALUES (3, 'Arjit', 'Jiaganj');
  

3. View Table Data


SELECT * FROM Employee;
  
Initial table data

4. Update a Record

Update the employee with Id = 1 to new values:


UPDATE Employee
SET Name = 'Sonu', City = 'Haryana'
WHERE Id = 1;
  
Updated one row

5. Update Multiple Records

The WHERE clause determines which records are updated. This example changes all employees in Haryana to have the name Kishore.


UPDATE Employee
SET Name = 'Kishore'
WHERE City = 'Haryana';
  
Update multiple rows

📞 Contact Us