You are on page 1of 4

1.

Create a new database called "e-commerce" with the following tables and
insert 6 rows for each table.

1. customers (columns: id, name, age,email, phone, address)


2. orders (columns: id, customer_id, product_id, quantity, price, order_date)
3. products (columns: id, name, description, price,
stock)

Task:
1. Add a new column "age" to the "customers" table with the
data type "int".
2. Rename the "orders" table to "customer_orders".
3. Delete the "products" table.
4. Insert the following information into the "customers" table:
Name: John Smith, Age: 25, Email: john.smith@email.com, Phone:
555-1234, Address: 123 Main St, Anytown USA
5. Write a SQL statement to retrieve the name and email of all customers from
the "customers" table.
6. Write a SQL statement to update the email of customer with id = 2 to
"sarah.johnson123@email.com".
7. Delete all customers whose age is less than 18.
8. List the customer name who’s name starting with the letter ‘S’.
2. Create the following tables and insert 5 rows for each tables then write
the queries.

1. Students (Sid Int, SName String)


2. Teachers(Tid Int, TName String, Salary Number, DateofJoining )
3. Subjects(Subid Int, S_Name String , Affiliation String, Credits Int,
TName String)
4. Grades(Sid Int, Sname String,Tid Int, Subid Int, Grades int)

Task:
1. List the students as per their alphabetic order
2. List the Subjects ID in Descending order
3. List the students who has enroll for DBMS.
4. Write a query to find the average grade of particular subject.
5. Alter the Teacher table and add Phone number.
6. Find the student who has opted for ‘DBMS’ and ‘FCC’ and has an
avg grade of 7.5.
7. List the student name who’s name starting with the letter ‘S’.
8. Display the rows with not null Values.
3.

CREATE TABLE weather (


id INT PRIMARY KEY,
city VARCHAR(30) NOT NULL,
date DATE NOT NULL,
temperature INT NOT NULL,
weather_condition VARCHAR(30) NOT NULL,
precipitation FLOAT NOT NULL
);

INSERT INTO weather (id, city, date, temperature, weather_condition,


precipitation)

VALUES
(1, 'New York', '2022-01-01', 32, 'Snow', 4.5),
(2, 'London', '2022-01-02', 40, 'Rain', 0.8),
(3, 'Tokyo', '2022-01-03', 50, 'Sunny', 0),
(4, 'Beijing', '2022-01-04', 20, 'Snow', 6.2),
(5, 'Sydney', '2022-01-05', 70, 'Sunny', 0),
(6, 'Paris', '2022-01-06', 30, 'Rain', 2.5),
(7, 'Berlin', '2022-01-07', 25, 'Snow', 5),
(8, 'Toronto', '2022-01-08', 20, 'Snow', 7.8),
(9, 'Moscow', '2022-01-09', 10, 'Snow', 9.5),
(10, 'Rome', '2022-01-10', 45, 'Rain', 3.2);
TASK: DATA MANIPULATION

EXERCISE FOR USING SELECT, WHERE, ORDER BY, DESC, ASC,


DELETE, UPDATE, AND DROP

1. SELECT all columns from the weather table.


2. SELECT all columns from the weather table where the temperature is
greater than 32:
3. SELECT all columns from the weather table ordered by
temperature in ascending order:
4. UPDATE the weather condition of a record with id=5 to "cloudy".
5. DELETE a record with id=7 from the weather table.
6. SELECT all columns from the weather table where the weather
condition is "snow" and precipitation is greater than 5.
7. SELECT the average temperature for all cities in the weather table.
8. DROP the weather table.

You might also like