0
0
SQLquery~5 mins

UPDATE single column in SQL

Choose your learning style9 modes available
Introduction

We use UPDATE to change data in a table. Updating a single column means changing just one piece of information for some rows.

You want to fix a typo in a person's name in your contacts list.
You need to change the price of one product in your store's inventory.
You want to mark a task as completed by changing its status.
You want to update the email address of a user in your database.
Syntax
SQL
UPDATE table_name
SET column_name = new_value
WHERE condition;

The WHERE clause decides which rows get updated. Without it, all rows change!

You only change one column by listing just that column in SET.

Examples
Change salary to 5000 for the employee with ID 3.
SQL
UPDATE employees
SET salary = 5000
WHERE employee_id = 3;
Update the price of the product named 'Notebook'.
SQL
UPDATE products
SET price = 19.99
WHERE product_name = 'Notebook';
Mark task 10 as done.
SQL
UPDATE tasks
SET status = 'done'
WHERE task_id = 10;
Sample Program

This creates a users table, adds three users, then updates Bob's email address. Finally, it shows all users to see the change.

SQL
CREATE TABLE users (
  id INT,
  name VARCHAR(50),
  email VARCHAR(100)
);

INSERT INTO users (id, name, email) VALUES
(1, 'Alice', 'alice@example.com'),
(2, 'Bob', 'bob@example.com'),
(3, 'Charlie', 'charlie@example.com');

UPDATE users
SET email = 'bob.new@example.com'
WHERE id = 2;

SELECT * FROM users ORDER BY id;
OutputSuccess
Important Notes

Always use WHERE to avoid updating every row by mistake.

You can update multiple rows if the WHERE condition matches more than one.

Summary

UPDATE changes data in a table.

You can update just one column by specifying it in SET.

Use WHERE to pick which rows to update.