UPDATE-COMMAND-SQL-SQL

Update Command in Structured Query Language (SQL)

Sometimes you may need to update   table in SQL   which you have created. For this  you need to use UPDATE command with SET option.

In this post,  you will know that how you can update a record  of SQL database.

You can see in the below program that a database school is created  and inside school database students table is created having  three columns and two rows.

When command SELECT * FROM students runs both rows gets printed.

 
CREATE DATABASE  IF NOT EXISTS SCHOOL;
USE school;
CREATE TABLE  IF NOT EXISTS students(NAME VARCHAR(10), regno INT,marks INT );
INSERT INTO students VALUES ("A", 101, 67), ("B", 102, 65);
SELECT * FROM students;

UPDATE-COMMAND-SQL

Now I am going to modify marks of B which is 65 , and after updating it would be 70, for this I will use command

UPDATE students SET marks=70 WHERE regno=102, this code will modify marks of B to 70.

CREATE DATABASE  IF NOT EXISTS SCHOOL;
USE school;
CREATE TABLE  IF NOT EXISTS students(NAME VARCHAR(10), regno INT,marks INT );
INSERT INTO students VALUES ("A", 101, 67), ("B", 102, 65);
SELECT * FROM students;
UPDATE students SET marks=70 WHERE regno=102;

UPDATE-COMMAND-SQL-SQL

Leave a Comment

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

©Postnetwork-All rights reserved.