DBMS LAB EXP-1_2_3_4
DBMS LAB EXP-1_2_3_4
There are two entity sets Employee and Department. These entity sets are participating in a relationship works in. The
relationship set is converted into relation with attributes EmpNo from Employee relation, D_id from Department relation
and Since, the attribute of the relationship set itself.
Symbols Used in ER Model
ER Model is used to model the logical view of the system from a data perspective which consists of these symbols:
Components of ER Diagram
ER Model consists of Entities, Attributes, and Relationships among Entities in a Database System.
Entity=>
An Entity may be an object with a physical existence – a particular person, car, house, or employee – or it may
be an object with a conceptual existence – a company, a job, or a university course.
To draw an ER diagram for the described scenario, we have two entities — Employee and Department — and a
relationship set called "works in." Here's how we can represent it:
Step-by-step breakdown:
1. Entity Sets:An Entity is an object of Entity Type and a set of all entities is called an entity set.
o Employee: This entity set represents employees and includes attributes like EmpNo (Employee
Number).
o Department: This entity set represents departments and includes attributes like D_id (Department
ID).
2. Relationship Set:A Relationship Type represents the association between entity types. The relationship type is
represented by a diamond and connecting the entities with lines.
o
Works in: This relationship links employees to departments, indicating that an employee works in
a department. The relationship will have an additional attribute Since that captures the year or date
when the employee started working in the department.
3. Attributes of Entities:Attributes are the properties that define the entity type.
o Employee has an attribute EmpNo.
o Department has an attribute D_id.
o The Works in relationship has an attribute Since.
4. ER Diagram Components:
o Entities: Represented by rectangles, the Employee and Department entities will be placed in
separate rectangles.
o Relationship: Represented by a diamond, the "works in" relationship will be placed between
Employee and Department.
o Attributes: Represented by ovals, the attributes EmpNo for Employee, D_id for Department, and
Since for the relationship will be connected to their respective entities/relationship.
ER Diagram Layout:
Employee (Entity):
o EmpNo (attribute)
Department (Entity):
o D_id (attribute)
Works in (Relationship):
o Since (attribute)
+----------------+ +------------------+
| Employee | | Department |
|------------------| |--------------------|
| EmpNo | | D_id |
+----------------+ +------------------+
| |
| |
| |
+----------------------------------------+
| Works in (Relationship) |
|------------------------------------------|
| Since |
+----------------------------------------+
| |
| |
Explanation:
Employee and Department are connected to the Works in relationship through lines, indicating that
employees work in departments.
The Since attribute is associated with the Works in relationship, as it reflects when the employee started
working in that department.
EXP-02
Relational Model
To convert the provided ER diagram into a Relational Model, we need to translate the entities and relationships
into relations (tables) and their respective attributes. Here is how we would approach it:
1. Employee Entity:
o Attributes: EmpNo (Employee Number)
o Relation: Employee(EmpNo)
2. Department Entity:
o Attributes: D_id (Department ID)
o Relation: Department(D_id)
3. Works in Relationship:
o Attributes: Since (the date or year the employee started working in the department)
o Relation: WorksIn(EmpNo, D_id, Since)
1. Employee Relation: This table represents the Employee entity with its primary key, EmpNo.
Employee(EmpNo)
Department(D_id)
The relation also includes the Since attribute which is specific to the relationship.
1. Employee Relation:
Employee(EmpNo)
o EmpNo (Primary Key)
2. Department Relation:
Department(D_id)
Summary:
The Employee and Department entities are converted into separate relations.
The WorksIn relationship is converted into a relation with foreign keys pointing to the Employee and
Department relations, and an additional attribute Since representing the start date.
EXP=>03
Normalization
Consider the following table.
a) Normalize the given Relation. Consider the given schema is in first normal form
and Schema(Student id ,Student name, Project Id, Project name, City, country, ZIP)
country->ZIP,ZIP
Eid->EName,Ph.no,Empcity,CityZip PrimaryKey=(EmpId,ProjId)
ProjId->ProjName, ProjLeader
EmpId,ProjId->ProjLeader
EmpCity->CityZip
ProjId->ProjLeader
To solve this problem, we need to normalize the given relation step by step to bring it into Boyce-Codd Normal
Form (BCNF) while considering the provided functional dependencies (FDs).
Schema: Student id, Student name, Project Id, Project name, City, country, ZIP
101 John 98765623, 998234123 P03 Project103 Grey ModelTown Grey 110033
2NF Condition:
The relation is in 2NF if it is in 1NF and all non-prime attributes are fully functionally dependent on the primary
key.
To satisfy this, we must remove partial dependencies (if any), where non-prime attributes are dependent on a part
of the primary key rather than the whole primary key.
FDs like (ProjId -> ProjName) and (Country -> ZIP) suggest that ProjName depends only on ProjId, and ZIP depends
only on Country. Hence, these are partial dependencies.
We need to decompose the relation to remove these partial dependencies.
3NF Condition:
A relation is in 3NF if it is in 2NF and no transitive dependencies exist, i.e., non-prime attributes must not depend
on other non-prime attributes.
(ZIP -> City) is a transitive dependency because City depends on ZIP, and ZIP depends on Country. So, we will
decompose to remove this transitive dependency.
BCNF Condition:
A relation is in BCNF if, for every functional dependency, the left-hand side is a superkey.
(ProjId -> ProjName) violates BCNF because ProjId is not a superkey for the original relation (EmpId, ProjId). We
need to decompose the relation so that the left-hand side of every FD is a superkey.
Step 6: Decompose the Relation
We decompose the relation into several smaller relations to remove partial, transitive dependencies, and to
satisfy BCNF.
This relation will contain the information about the employee's project involvement.
Functional Dependencies:
ProjId ProjName
P03 Project103
P01 Project101
P04 Project104
P02 Project102
Functional Dependency:
This relation will store details about countries and ZIP codes.
Country ZIP
Grey 110033
Christia 110044
Hudson 110028
Petro 110064
Functional Dependency:
This relation stores the information about ZIP and corresponding cities.
ZIP City
110033 Grey
110044 Christia
110028 Hudson
110064 Petro
Functional Dependency:
DDL (Data Definition Language) commands are used to define, modify, or remove database structures like
tables, schemas, indexes, and more. Here’s a quick rundown of common DDL commands:
1. CREATE: Used to create new database objects (like tables, views, or indexes).
2. ALTER: Used to modify existing database objects.
3. DROP: Used to delete existing database objects.
4. TRUNCATE: Used to delete all records in a table but keep the table structure.
5. RENAME: Used to rename an existing database object.
1. CREATE TABLE:
This command creates a new table in the database.
2. ALTER TABLE:
This command is used to modify an existing table.
3. DROP TABLE:
This command deletes an existing table and all of its data.
4. TRUNCATE TABLE:
This command removes all records from a table without deleting the table itself.
5. RENAME TABLE:
This command renames an existing table.