Dbms Lab1
Dbms Lab1
Name-Muskan
Roll no-2023wd15015
Password : Root123$
Objective: The purpose of this lab is to develop skills in database management by implementing stored
procedures, triggers, and cursors, and handling complex SQL operations. This will enhance your ability to
manage and manipulate data efficiently within a relational database system.
Problem statement :
Create a complex MySQL query that combines data from multiple tables to understand and practice
basic MySQL queries such as CREATE, INSERT, ALTER, UPDATE, DELETE through the Employee
Management System database. Steps to be followed:
Step1: Setup the Database Schema - Create the tables with the provided schema
Query:
FirstName varchar(20),
Lastname varchar(15),
DateofBirth date,
Gender char(1),
HireDate date,
DepartmentID int,
PositionID int,
Salary decimal(10,2),
ManagerID int,
Email varchar(30)
);
Insert into Employees
(EmployeeID,FirstName,Lastname,DateofBirth,Gender,HireDate,DepartmentID,PositionID,Salary,Manag
erID,Email)
values (1,'Chandra','Pal','2012-05-12','M','2024-06-13',10,10,65000,10,'chandrapal@123');
values (1,'manu','rastogi','2012-05-12','M','2024-06-13',20,20,75000,10,'manu@123');
values (1,'Prabhakar','yadav','2012-05-12','M','2024-06-13',10,10,85000,10,'Prakharyadav@123');
values (1,'Musakn','Muskan','2012-05-12','F','2024-06-13',30,30,95000,10,'muskan@123');
Department table
DepartmentName varchar(15),
Location varchar(30)
);
/* Inserting Data in Department Table */
Insert into Departments (DepartmentID, DepartmentName, Location) values (10000, 'IT', 'Banglor');
Insert into Departments (DepartmentID, DepartmentName, Location) values (10004, 'Human Resource',
'Mumbai');
/ Creation of Attendance table */
EmployeeID int(5),
Date DATE,
Status ENUM('Present','Absent','Leave')
);
insert into Attendance (AttendanceID, EmployeeID, Date, Status) values (100, 10000, '2002-05-12',
'Present');
insert into Attendance (AttendanceID, EmployeeID, Date, Status) values (101, 10001, '2002-05-13',
'Absent');
insert into Attendance (AttendanceID, EmployeeID, Date, Status) values (102, 10002, '2002-05-14',
'Leave');
/* Creation of Project Table */
ProjectName varchar(20),
StartDate date,
Enddate date,
DepartmentID int(5)
);
Insert into Projects (ProjectID, ProjectName, StartDate, Enddate, DepartmentID) values (10000, 'Aviva',
'1966-09-15', '1998-10-10', 10000);
Insert into Projects (ProjectID, ProjectName, StartDate, Enddate, DepartmentID) values (10001, 'Nokia',
'1966-09-16', '1998-10-11', 20000);
Insert into Projects (ProjectID, ProjectName, StartDate, Enddate, DepartmentID) values (10002, 'US-
Bank', '1966-09-17', '1998-10-12', 30000);
/* Creation EmployeesProjects Table */
EmployeeID int(5),
ProjectID int(5),
Role varchar(15)
);
/* Inserting data in EmployeesProjects */
Insert into EmployeesProjects (EmployeeProjectID, EmployeeID, ProjectID, Role) values (12312, 10000,
10000, 'Developer');
Insert into EmployeesProjects (EmployeeProjectID, EmployeeID, ProjectID, Role) values (12313, 10001,
10001, 'Analist');
Insert into EmployeesProjects (EmployeeProjectID, EmployeeID, ProjectID, Role) values (12314, 10002,
10002, 'Engineer');
PositionName varchar(15),
Basesalary decimal(5,2)
);
/* Inserting Data in Positions Tabel */
Question 1:
Retrieve all employee from the all employees table. Add a new Employee name “<Your student name
>” with the employeeID “<Student bits id >” in the employee management system DB
Question 2:
Update the columns table in the employees “Firstname” to “EmpFirstName” and retrieve the updated
column name
Question 3:
Update the department table “Human Resource” to “People management” in the table and display
the updated data
Question 4:
Write a query to find employees who were hired before 2019 and retrieve all employees who joined
after January 1 2024.
Question 5:
Write a query to add unique constraint to the Email column on Employees table to ensure no two
members can have the same Email address. Retrieve the data to prove the added constraint.
values (1,'Niharika','Pal','2012-05-12','M','2025-06-13',10,10,65000,10,'Niharika@123');
Question 6:
Note : Here we have modified the column int to varchar for updating the data in DepartmentID
column