Wednesday, 5 February 2020

Mysql Commands | Update command

MySQL Commands


Update Command

Update command is used to update the data or records.

Syntax for update command:


update table_name
set column_name=value;

This statement updated all the rows. 

or

update table_name
set column_name=value where column_name=condition;

This statement updated only specific rows.


Lets take an example:


mysql update cmd

Update


Suppose we have a table named Employee in which we have to increase/decrease the salary by 10% then we write as :

update employee
set salary=salary+salary*10/100;

For specific Rows we apply condition
as

update employee set salary=salary+ salary*10/100 where empcode=101;


lets take an another example

question: write a mysql command to change the salary by null whose employee code is 102?

Ans:

update employee
set salary =null where empcode=102;



question : write a mysql command to set the salary 1000 whose salary is null?
Ans:

update employee
set salary=1000 where salary is null;

question: write a mysql command to set the designation as Null whose salary is 0?
Ans:
update employee
set designation='Null' where salary =0;

Here we write Null in quotes because designation column is of datatype varchar.
if we write Null value to salary column, we will not write quotes because salary column is of integer datatype.


See Also

Database
Tables
Alter command
Update Command
Count Function



No comments:

Post a Comment

Recent Post

Python Project | Banking System | Project on Banking System using python

  PYTHON PROJECT Banking System import csv import pandas as pd import matplotlib.pyplot as plt import sys import datetime found=False def ne...