Project
Project
This will help set up a database for the Employee Management System (EMS) to manage the
following functionalities:
1. Employee Details:
Store and manage information about individual employees, including their names,
addresses, genders, and salary details.
2. Department Details:
Maintain records of different departments within the organization, including their
names and locations.
3. Project Details:
Track information related to various projects in the organization, including project
names, budgets, and locations.
4. Salary Records:
Manage salary records for employees, including salary amounts, start dates, and
end dates.
5. Attendance Records:
Keep track of employee attendance records, including attendance dates and
statuses (e.g., Present, Absent).
We will use MySQL Workbench as the DBMS to create the database and its related
operations.
1. Open the MySQL website on a browser. Click on the following link: MySQL
Downloads.
6. It will ask for permission; when it does, click Yes. The installer will then open. Now,
it will ask to choose the setup type, here, select Custom.
7. Click on Next. With this, you will be able to install MySQL server, MySQL
Workbench, and MySQL shell.
8. Open MySQL Servers, select the server you want to install, and move it to the
Products/Features to be installed window section. Now, expand Applications, choose
MySQL Workbench and MySQL shell. Move both of them to ‘Products/Features to be
installed’.
9. Click on the Next button. Now, click on the Execute button to download and install
the MySQL server, MySQL Workbench, and the MySQL shell.
10. Once the product is ready to configure, click on Next. Under Type and Networking,
go with the default settings and select Next.
13. Go for the default windows service settings and under apply configuration, click on
execute. Once the configuration is complete, click on finish.
14. Complete the installation. This will now launch the MySQL Workbench and the
MySQL Shell.
Once MySQL Workbench is installed, select the Local instance and enter the password.
Now, you can use the MySQL query tab to write your SQL queries.
Identify Entities
Start by identifying the main entities in your system. These are the objects or concepts
about which you want to store data.
Each entity should correspond to a table in your database.
Define Attributes
For each entity, list the attributes (properties or fields) that describe it.
These attributes will become columns in the corresponding database table.
Identify Relationships
Determine how entities are related to each other. There are three types of relationships:
one-to-one (1:1), one-to-many (1:N), and many-to-many (N:M).
Represent these relationships using lines connecting the entities.
1. One-to-One: When each entity in each entity set can take part only once in the
relationship, the cardinality is one-to-one. Let us assume that a male can marry one
female and a female can marry one male. So the relationship will be one-to-one.
Many-to-Many: When entities in all entity sets can take part more than once in the
relationship cardinality is many to many.
Cardinality Notation
Cardinality represents the number of times an entity of an entity set participates in a relationship
set. Or we can say that the cardinality of a relationship is the number of tuples (rows) in a
relationship.
Use notation (such as Crow's Foot Notation or Chen Notation) to indicate the cardinality
of each relationship.
Cardinality describes how many instances of one entity are related to how many instances
of another entity.
Common notations include:
One (1)
Zero or one (0..1)
Many (N)
Zero or many (0..N)
Optional:
Add Attributes and Constraints
Include additional information in your ERD, such as primary keys, foreign keys, and
constraints (e.g., unique constraints).
let’s identify the attributes and relationships of each entity for the Employee Management
System.
Employee
Attributes:
EmployeeID (Primary Key): A unique identifier for each employee.
2. Department
3. Salary
4. Project
5. Attendance
ERD Diagram
In this ERD:
Using MySQL Workbech, create a new database for your Employee management system.
Query:
create database employeedata;
Using a database
Query:
use employeedb;
Query:
Delete Queries
-- Delete an employee by EmployeeID (e.g., EmployeeID = 1)
DELETE FROM Employee
WHERE EmployeeID = 1;
-- Delete a department by DepartmentID (e.g., DepartmentID = 2)
DELETE FROM Department
WHERE DepartmentID = 2;
-- Delete a project by ProjectID (e.g., ProjectID = 3)
DELETE FROM Project
WHERE ProjectID = 3;
-- Delete an attendance record by AttendanceID (e.g., AttendanceID = 3)
DELETE FROM Attendance
WHERE AttendanceID = 3;
Other Queries
1. Retrieve Employees Managed by a Specific Manager:
-- Retrieve employees managed by a specific manager (e.g., ManagerID = 3)
SELECT * FROM Employee WHERE ManagerID = 3;