DBMS
DBMS
(Unit 2)
An Entity-Relationship (ER) model is a conceptual framework used in
database design to represent the data and its relationships within a
system. It helps in defining the structure of a database by identifying the
entities, attributes, and the relationships between entities. Here's a
breakdown of the key components and concepts of an ER model:
1. Entities
Entities are objects or things in the real world that have a distinct
existence. They can be physical objects like "Employee" or "Product," or
they can be more abstract like "Project" or "Department." In the ER model,
entities are represented as rectangles.
2. Attributes
Example: The Course entity might have attributes like CourseID, CourseName,
and Credits.
3. Relationships
5. ER Diagram Components
Entities: Rectangles.
Attributes: Ovals connected to their respective entities.
Relationships: Diamonds connected to the entities involved.
Cardinality: Lines and symbols (such as 1, N, or M) indicating the
type of relationship.
6. Keys
Example ER Diagram
Entities:
o Student (StudentID, Name, DateOfBirth)
o Course (CourseID, CourseName, Credits)
o Professor (ProfessorID, Name, Department)
Relationships:
o Enrolls (StudentID, CourseID) showing that a student enrolls in a
course.
o Teaches (ProfessorID, CourseID) showing that a professor teaches a
course.
An ER diagram helps visualize how these entities interact and how data
should be structured. It serves as a blueprint for creating a database
schema in a relational database management system (DBMS).
EER model
An Enhanced Entity-Relationship (EER) model extends the traditional
Entity-Relationship (ER) model by incorporating additional concepts and
features that allow for more complex and detailed database design. The
EER model introduces advanced constructs that address certain
limitations of the basic ER model, making it suitable for modeling more
sophisticated databases. Here’s a look at the key concepts of the EER
model:
2. Aggregation
o Aggregation is a higher-level abstraction that represents a
relationship between a whole and its parts. It helps to simplify
complex ER diagrams by grouping related entities and their
relationships into a single higher-level entity.
4. Multi-valued Attributes
o Multi-valued attributes are attributes that can hold multiple
values for a single entity instance. They are represented by
double ovals in an EER diagram.
5. Derived Attributes
o Derived attributes are attributes that can be calculated from
other attributes. They are usually represented by a dashed
oval in an EER diagram.
Example
CODD Rules
1. Information Rule
Example: Data should be stored in tables with rows and columns, where
each column represents an attribute and each row represents a record.
Example: You should be able to access any piece of data in the database
using a straightforward query based on table names and column names.
Example: A column for PhoneNumber might have a null value if the phone
number is not provided, and this should be treated distinctly from an
empty string.
Example: If you have a view showing StudentName and Course, you should
be able to update the student's name in the view, and the change should
be reflected in the underlying Student table.
Example: You should be able to insert multiple rows into a table with a
single command, such as INSERT INTO Students (Name, Age) VALUES ('Alice', 20),
('Bob', 22);.
Example: Changing the way data is stored on disk (e.g., moving from one
type of storage device to another) should not require changes to the
database schema or application queries.
While not all database systems strictly adhere to every rule (especially
older systems or those not designed around pure relational principles),
these rules provide a benchmark for evaluating the relational capabilities
of a database system. Modern relational database systems like MySQL,
PostgreSQL, and Oracle strive to meet these principles, though
implementations can vary.
1. Tables (Relations)
o Definition: A table, or relation, is a collection of rows and
columns where each row represents a unique record, and
each column represents an attribute of the record.
o Structure: Each table is defined by its schema, which
includes the table name, column names, and data types.
o Example: A table named Employee might have columns
EmployeeID, Name, Department, and Salary.
2. Rows (Tuples)
o Definition: A row, or tuple, represents a single record or
instance of an entity in a table.
o Characteristics: Each row contains values for each attribute
defined by the columns of the table.
o Example: The row (1, Alice, HR, 60000) represents an employee
with EmployeeID 1, named Alice, working in the HR department
with a salary of 60,000.
3. Columns (Attributes)
o Definition: Columns, or attributes, represent the properties
or characteristics of the entity modeled by the table.
o Characteristics: Each column has a specific data type (e.g.,
integer, varchar) and defines the kind of data that can be
stored.
o Example: The Salary column in the Employee table might have
a data type of INTEGER.
4. Keys
o Primary Key: A unique identifier for each row in a table. It
ensures that each record is unique and can be identified
without ambiguity.
Example: EmployeeID in the Employee table is a primary
key.
o Foreign Key: An attribute in one table that links to the
primary key of another table, establishing relationships
between tables.
Example: A DepartmentID column in an Employee table
that references the DepartmentID in a Department table.
5. Integrity Constraints
o Entity Integrity: Ensures that each table has a primary key
and that the primary key columns contain unique values and
are not null.
o Referential Integrity: Ensures that foreign keys match
primary keys in the referenced table or are null, maintaining
consistency across relationships.
o Domain Integrity: Ensures that all column values conform to
a specified domain (data type, length, format).
6. Relationships
o One-to-One (1:1): Each row in Table A is related to at most
one row in Table B, and vice versa.
Example: A Person table and a Passport table where each
person has at most one passport and each passport is
assigned to one person.
o One-to-Many (1
Definition: A table is in First Normal Form if all its attributes contain only
atomic (indivisible) values, and each column contains only one value per
row.
Requirements:
To convert this to 1NF, we need to ensure each cell contains only one
value:
Requirements:
Student Table:
Student StudentNa
ID me
1 Alice
2 Bob
Course Table:
Course CourseNa
ID me
101 Math
102 Science
Enrollment Table:
Student Course
ID ID
1 101
Student Course
ID ID
1 102
2 101
Requirements:
Employee Table:
Department Table:
Departmen DepartmentN
tID ame
10 HR
20 IT