0% found this document useful (0 votes)
9 views

Database Where and Update Queries

DATABASE QUERIES

Uploaded by

asifameerhamza11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Database Where and Update Queries

DATABASE QUERIES

Uploaded by

asifameerhamza11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DATABASE WHERE AND UPDATE QUERIES:

UPDATE QUERY:

An UPDATE query is used to change an existing row or rows in the database. UPDATE queries can
change all tables’ rows, or we can limit the update statement affects for certain rows with the help of
the WHERE clause. Mostly, we use constant values to change the data, such as the following
structures.

Example of this code:

-- Create the employees table

CREATE TABLE employees (

id INT PRIMARY KEY AUTO_INCREMENT,

name VARCHAR(100),

position VARCHAR(50),

salary DECIMAL(10, 2)

);

-- Insert data into the employees table

INSERT INTO employees (name, position, salary) VALUES ('Alice Smith', 'Manager', 75000.00);

INSERT INTO employees (name, position, salary) VALUES ('Bob Johnson', 'Developer', 60000.00);

INSERT INTO employees (name, position, salary) VALUES ('Carol Williams', 'Designer', 50000.00);

-- Select all employees

SELECT * FROM employees;

-- Select employees with a salary greater than 60000

SELECT * FROM employees WHERE salary > 60000;


-- Update salary for Bob Johnson

UPDATE employees

SET salary = 65000.00

WHERE name = 'Bob Johnson';

-- Change position for Alice Smith

UPDATE employees

SET position = 'Senior Manager'

WHERE name = 'Alice Smith';

-- Select a specific employee

SELECT * FROM employees WHERE id = 1;

-- Update name for Carol Williams

UPDATE employees

SET name = 'Carol Thompson'

WHERE id = 3;

You might also like