Categories: SQL

SQL UPDATE Statement

How to update data in a Table?

Answer is to use UPDATE query. It is used with WHERE clause to avoid accidental update in all the columns rather than updates required for one column only.

Syntax:

UPDATE "tableName"
set columnName1 = value1,
columnName2 = value2,
....  ,
columnNameN = valueN
WHERE columnName = value;

Parameters :

tableName : Name of the table in which we are going to insert data.

column1, column2, columnN : Columns name of the table which will have specified data in it.

value1, value2, valueN : Values which are going to stored in table for e.g. column1 will have value1, column2 will have value2 and so on columnN will have value valueN.

columnName, value : They will be used as criteria i.e columnName in the table containing specified value in it.

UPDATE with one column : We will be using the same table which we have created in the CREATE TABLE and data which is added during insert query.

Using Select to see all the records before update.

SELECT * FROM `employee`;

before-update-query-execution-example1

UPDATE  `employee`  SET  `name` = ‘sachin’  WHERE `id` = 3;

Using Select to see all the records after update.

UPDATE with some sql operators is below :

Using Select to see all the records before update.

SELECT * FROM `employee`;

UPDATE  `employee`  SET  `salary` = 60000  WHERE `age` >= 30 ;

Using Select to see all the records after update.

Example 2 :

UPDATE  `employee`  SET  `salary` = 70000  WHERE `age` = 35 and name=’Leena’ ;

Note : we can use multiple combination of operators in WHERE clause.

Note : 1. You should add WHERE clause to avoid accidental updates of values in all columns.

2. Please remember about the datatypes of your column to avoid errors while updating data in table.
jyoti rani

Recent Posts

Modern Toys, Magical Moments: Why the Best Toy Shop in Noida Is More Than Just a Store

When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…

2 months ago

Rediscovering Joy: A New Era of Creativity & Comfort in Toy Stores

In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…

2 months ago

Unboxing Imagination: Discovering the Joy of Play at a Toy Store in Noida

In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…

2 months ago

Imagination Unboxed: Discover Joy at the Toy Shop in Delhi

In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…

2 months ago

Play with Purpose: Discovering the Ultimate Toy Store in Noida

When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…

2 months ago

From Tears to Toys: Exploring Modern Childhood through Delhi’s Favorite Toy Shop

In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…

2 months ago