-- Day 2
Q.1)
1) Create database Emp info
2) create table Employee and add columns Emp id, Emp name, age, Salary)
3) Insert the 5 records in Employee table
4) Display all the information from table
Q.2)
1) Create table department and add column dept id , dept name and use size 50
2) Insert 10 records
3) Display all the table with values
-- Day 3
1) Create a patients table and add the column
Pid, Pname, DOB, DOA datetime, Gender, fees, contactNo
Insert 5 records into patients table
Display the table
-- Day 4
Q.1) Create a table employee and add
EMP_ID it should not be duplicate and not null and it should be auto increment,
EMPNAME should not be null ,
AGE will be greater than 21,
DOB should not be null ,
DOJ default date will be 2025-02-10,
SALARY should be greater than 25000,
DOE it should be > doj
ANS :
Create table employee(
emp_id int primary key auto_increment,
emp_name varchar(50) not null,
age tinyint check(age>21),
dob date not null,
doj date default "2025-02-10",
salary decimal(10,5) check (salary>25000.000),
doe date check(doe>doj)
);
Use Appropriate column as a primary key and foreign key also On delete and On
update cascade
1. Products Table
The Products table contains details about products, including their names,
categories, and unit prices. It provides reference data for linking product
information to sales transactions.
Use Appropriate column as a primary key
2. Sales Table
The Sales table records information about product sales, including the quantity
sold, sale date, and total price for each sale. It serves as a transactional data
source for analyzing sales trends.
-- Insert sample data into Sales table
INSERT INTO Sales (sale_id, product_id, quantity_sold, sale_date, total_price)
VALUES
(1, 101, 5, '2024-01-01', 2500.00),
(2, 102, 3, '2024-01-02', 900.00),
(3, 103, 2, '2024-01-02', 60.00),
(4, 104, 4, '2024-01-03', 80.00),
(5, 105, 6, '2024-01-03', 90.00);
-- Insert sample data into Products table
INSERT INTO Products (product_id, product_name, category, unit_price) VALUES
(101, 'Laptop', 'Electronics', 500.00),
(102, 'Smartphone', 'Electronics', 300.00),
(103, 'Headphones', 'Electronics', 30.00),
(104, 'Keyboard', 'Electronics', 20.00),
(105, 'Mouse', 'Electronics', 15.00);
1. Retrieve all columns from the Sales table.
2. Retrieve the product_name and unit_price from the Products table.
3. Retrieve the sale_id and sale_date from the Sales table.
4. Filter the Sales table to show only sales with a total_price greater than $100.
5. Filter the Products table to show only products in the 'Electronics' category.
6. Retrieve the sale_id and total_price from the Sales table for sales made on
January 3, 2024.
7. add column country in products table after category column
8. update products table country = India where product_id = 105
9. delete record from sales where quantity < 4