Home » Online Computer Education » Learn online DBMS “Update Command in MySQL” Complete Lesson 12

Learn online DBMS “Update Command in MySQL” Complete Lesson 12

UPDATE COMMAND– This command is used to update the attribute values of one or more tuples in a table. For example in the Teacher table, we want to update the Dept_No of teachers teaching computer science to 123. This can be done using the following command:

UPDATE Teacher

SET Dept_No=123

WHERE Subject=”Computer Science”;

update1

We can also use the SELECT command in the WHERE clause of UPDATE command if we have to update the table based on result of a query. For example:

UPDATE Teacher

SET Subject=”Business Management”

WHERE Dept_No IN ( SELECTDept_ID

                                FROM Department

               WHERE Dept_Name=”Commerce”);

Thus the above command would set the subject of all the teachers that belong to the “Commerce” department to “Business Management”.

We can also have an algebraic expression in the SET clause. Suppose it is required to reduce the theTeacher_ID of a Teacher “Sanya” by 1, the command would be:

UPDATE Teacher

SET Teacher_ID=Teacher_ID-1update2

WHERETeacher_Name=”Shanaya”;

update2

 

About

The main objective of this website is to provide quality study material to all students (from 1st to 12th class of any board) irrespective of their background as our motto is “Education for Everyone”. It is also a very good platform for teachers who want to share their valuable knowledge.

Leave a Reply

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