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

Assignment_1_DBMSLab

The document outlines a series of MySQL queries for creating a database named CompanyDB and managing employee and department records. It includes instructions for creating tables, inserting records, retrieving employee data based on specific criteria, updating salaries, and establishing foreign key relationships. Additionally, it covers queries for aggregating employee counts and calculating average salaries within departments.

Uploaded by

Devansh Mohar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment_1_DBMSLab

The document outlines a series of MySQL queries for creating a database named CompanyDB and managing employee and department records. It includes instructions for creating tables, inserting records, retrieving employee data based on specific criteria, updating salaries, and establishing foreign key relationships. Additionally, it covers queries for aggregating employee counts and calculating average salaries within departments.

Uploaded by

Devansh Mohar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

You might also like