Q1 a) Write a MySQL query to create a database named CompanyDB.
b) Create a table employees with the following attributes:
emp_id (INT, Primary Key, Auto Increment)
emp_name (VARCHAR(50), NOT NULL)
department (VARCHAR(30))
salary (DECIMAL(10,2))
joining_date (DATE)
Q2 a) Insert the following records into the employees table:
emp_name department salary joining_date
Alice HR 50000 2022-03-15
Bob IT 70000 2021-07-20
Charlie Finance 60000 2020-11-10
b) Write a query to retrieve all employees who joined after January 1,
2021.
c) Write a query to retrieve all employees who earn more than 60,000.
Q3 a) Write a query to increase Bob's salary to 75,000.
b) Write a query to delete all employees from the HR
department.
Q4 a) Create a table departments with the following columns:
dept_id (INT, Primary Key, Auto Increment)
dept_name (VARCHAR(50), Unique)
b) Insert the following records into departments:
dept_name
HR
IT
Finance
c) Add a foreign key constraint in the employees table so that the
department column references departments(dept_name).
d) Write a query to retrieve employees along with their department
names using a JOIN.
Q5 a) Write a query to display the total number of employees in each
department.
b) Write a query to display the average salary of employees in the IT
department.