0% found this document useful (0 votes)
13 views14 pages

Dbms Lab1

Dbms 1

Uploaded by

solutionsw36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views14 pages

Dbms Lab1

Dbms 1

Uploaded by

solutionsw36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Course Name and Code: Database Systems and Application (S1-24_CSIWZC337)

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:

/* Database Creation with Name Chandra*/

Step1: Setup the Database Schema - Create the tables with the provided schema

Query:

Create table Employees (EmployeeID int,

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');

Insert into Employees


(EmployeeID,FirstName,Lastname,DateofBirth,Gender,HireDate,DepartmentID,PositionID,Salary,Manag
erID,Email)

values (1,'manu','rastogi','2012-05-12','M','2024-06-13',20,20,75000,10,'manu@123');

Insert into Employees


(EmployeeID,FirstName,Lastname,DateofBirth,Gender,HireDate,DepartmentID,PositionID,Salary,Manag
erID,Email)

values (1,'Prabhakar','yadav','2012-05-12','M','2024-06-13',10,10,85000,10,'Prakharyadav@123');

Insert into Employees


(EmployeeID,FirstName,Lastname,DateofBirth,Gender,HireDate,DepartmentID,PositionID,Salary,Manag
erID,Email)

values (1,'Musakn','Muskan','2012-05-12','F','2024-06-13',30,30,95000,10,'muskan@123');
Department table

/* Department Table creation */

Create table Departments (DepartmentID int(5),

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 (10001, 'Finance',


'Kodathi');

Insert into Departments (DepartmentID, DepartmentName, Location) values (10002, 'Marketing',


'Kodathi');

Insert into Departments (DepartmentID, DepartmentName, Location) values (10003, 'Operations',


'Grater Noida');

Insert into Departments (DepartmentID, DepartmentName, Location) values (10004, 'Human Resource',
'Mumbai');
/ Creation of Attendance table */

create table Attendance (AttendanceID int(3),

EmployeeID int(5),

Date DATE,

Status ENUM('Present','Absent','Leave')

);

/ * Inserting data in Attendance Table */

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 */

create table Projects (ProjectID int(5),

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 */

Create table EmployeesProjects (EmployeeProjectID int(5),

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');

/* Position Table Creation */

create table Positions (PositionID int(5),

PositionName varchar(15),

Basesalary decimal(5,2)

);
/* Inserting Data in Positions Tabel */

Insert into Positions (PositionID,PositionName,Basesalary) values (10,'Developer',50000);

Insert into Positions (PositionID,PositionName,Basesalary) values (12,'Mainfraime',50000);

Insert into Positions (PositionID,PositionName,Basesalary) values (10,'Software',50000);

Insert into Positions (PositionID,PositionName,Basesalary) values (10,'Engineering',50000);

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

select * from Employees;


/* Insert new data in Insertion Table */

Insert into Employees


(EmployeeID,FirstName,Lastname,DateofBirth,Gender,HireDate,DepartmentID,PositionID,Salary,Manag
erID,Email) values (10,'R ushrani','R','2012-05-12','F','2024-06-13',50,60,95000,10,'RUshrani@123');

Select * from Employees;

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

Update Departments set DepartmentName='People Management' where DepartmentName='Human


Resource';

select * from Departments;

Question 4:

Write a query to find employees who were hired before 2019 and retrieve all employees who joined
after January 1 2024.

select * from Employees where HireDate < '2019-01-01';


select * from Employees where HireDate > '2024-01-01';

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.

Before add constraint key on email address

After adding constraint key on email address

ALTER TABLE Employees ADD CONSTRAINT unique_email UNIQUE (Email);

Insert into Employees


(EmployeeID,FirstName,Lastname,DateofBirth,Gender,HireDate,DepartmentID,PositionID,Salary,Manag
erID,Email)

values (1,'Niharika','Pal','2012-05-12','M','2025-06-13',10,10,65000,10,'Niharika@123');
Question 6:

Update your employee DepartmentID with DBSA Course ID <ZC337>

Note : Here we have modified the column int to varchar for updating the data in DepartmentID
column

ALTER TABLE Employees

MODIFY COLUMN DepartmentID VARCHAR(20);

UPDATE Employees SET DepartmentID='ZC337' WHERE EmployeeID= 5;

You might also like