0% found this document useful (0 votes)
20 views

Lecture 2 - Models

The document discusses Entity Relationship (ER) diagrams and the relational database model. It defines ER diagrams and their components such as entities, attributes, and relationships. It also explains how to create an ER diagram and its importance. The document then defines concepts of the relational model such as relations, attributes, tuples, and keys. It discusses relational integrity constraints.

Uploaded by

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

Lecture 2 - Models

The document discusses Entity Relationship (ER) diagrams and the relational database model. It defines ER diagrams and their components such as entities, attributes, and relationships. It also explains how to create an ER diagram and its importance. The document then defines concepts of the relational model such as relations, attributes, tuples, and keys. It discusses relational integrity constraints.

Uploaded by

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

Models

Entity-Relationship model
Relational model
Entity-Relationship model
Preview
• What is an ER Diagram
• What is an ER Model
• History of ER models
• Why Use ER Diagrams in DBMS
• Symbols Used in ER Diagrams
• Components of ER Diagram
• How to Draw an ER Diagram
• Conclusion
What is an ER Diagram ?

 An Entity Relationship Diagram is a diagram that


represents relationships among entities in a database.
It is commonly known as an ER Diagram. An ER
Diagram in DBMS plays a crucial role in designing the
database. Today’s business world previews all the
requirements demanded by the users in the form of an
ER Diagram. Later, it's forwarded to the database
administrators to design the database.
• An Entity Relationship Diagram (ER Diagram)
pictorially explains the relationship between entities
to be stored in a database. Fundamentally, the ER
Diagram is a structural design of the database. It
acts as a framework created with specialized
symbols for the purpose of defining the relationship
between the database entities. ER diagram is
created based on three principal components:
entities, attributes, and relationships.
The following diagram
showcases two entities - Student
and Course, and their
relationship. The relationship
described between student and
course is many-to-many, as a
course can be opted by several
students, and a student can opt
for more than one course.
Student entity possesses
attributes - Stu_Id, Stu_Name &
Stu_Age. The course entity has
attributes such as Cou_ID &
Cou_Name.
What is an ER Model?
An Entity-Relationship Model represents the
structure of the database with the help of a
diagram. ER Modelling is a systematic process
to design a database as it would require you
to analyze all data requirements before
implementing your database.
History of ER models
Peter Chen proposed ER Diagrams in 1971 to
create a uniform convention that can be used
as a conceptual modeling tool. Many models
were presented and discussed, but none
were suitable. The data structure diagrams
offered by Charles Bachman also inspired his
model.
Why Use ER Diagrams in DBMS?
• ER Diagram helps you conceptualize the database and lets you
know which fields need to be embedded for a particular entity
• ER Diagram gives a better understanding of the information to
be stored in a database
• It reduces complexity and allows database designers to build
databases quickly
• It helps to describe elements using Entity-Relationship models
• It allows users to get a preview of the logical structure of the
database
Symbols Used in ER Diagrams

Rectangles: This Entity Relationship


Diagram symbol represents entity
types
Ellipses: This symbol represents
attributes
Diamonds: This symbol represents
relationship types
Lines: It links attributes to entity
types and entity types with other
relationship types
Primary key: Here, it underlines the
attributes
Double Ellipses: Represents multi-
valued attributes
Components of ER Diagram
You base an ER Diagram on three basic concepts:
• Entities
• Weak Entity
• Attributes
• Key Attribute
• Composite Attribute
• Multivalued Attribute
• Derived Attribute
• Relationships
• One-to-One Relationships
• One-to-Many Relationships
• Many-to-One Relationships
Entities
• An entity can be either a living or non-living component.
• It showcases an entity as a rectangle in an ER diagram.
• For example, in a student study course, both the student and the course are
entities.
Weak Entity
• An entity that makes reliance over another entity is called a weak entity
• You showcase the weak entity as a double rectangle in ER Diagram.
• In the example below, school is a strong entity because it has a primary key
attribute - school number. Unlike school, the classroom is a weak entity
because it does not have any primary key and the room number here acts only
as a discriminator.
Attribute
• An attribute exhibits the properties of an entity.
• You can illustrate an attribute with an oval shape in an ER diagram.
Key Attribute
• Key attribute uniquely identifies an entity from an entity set.
• It underlines the text of a key attribute.
• For example: For a student entity, the roll number can uniquely identify a
student from a set of students.
Composite Attribute
• An attribute that is composed of several other attributes is known as a
composite attribute.
• An oval showcases the composite attribute, and the composite attribute oval is
further connected with other ovals.
Multivalued Attribute
• Some attributes can possess over one value, those attributes are called
multivalued attributes.
• The double oval shape is used to represent a multivalued attribute.
Derived Attribute
• An attribute that can be derived from other attributes of the entity is known as
a derived attribute.
• In the ER diagram, the dashed oval represents the derived attribute.
Relationship
• The diamond shape showcases a relationship in the ER diagram.
• It depicts the relationship between two entities.
• In the example below, both the student and the course are entities, and study
is the relationship between them.
One to One Relationship
• When a single element of an entity is associated with a single element of
another entity, it is called a one-to-one relationship.
• For example, a student has only one identification card and an identification
card is given to one person.
One to Many Relationship
• When a single element of an entity is associated with more than one element
of another entity, it is called a one-to-many relationship
• For example, a customer can place many orders, but an order cannot be placed
by many customers.
Many to One Relationship
• When more than one element of an entity is related to a single element of
another entity, then it is called a many-to-one relationship.
• For example, students have to opt for a single course, but a course can have
many students.
Many to Many Relationship
• When more than one element of an entity is associated with more than one
element of another entity, this is called a many-to-many relationship.
• For example, you can assign an employee to many projects and a project can
have many employees.
How to draw ER Diagrams
• First, identify all the Entities. Embed all the entities in a rectangle and
label them properly.
• Identify relationships between entities and connect them using a
diamond in the middle, illustrating the relationship. Do not connect
relationships with each other.
• Connect attributes for entities and label them properly.
• Eradicate any redundant entities or relationships.
• Make sure your ER Diagram supports all the data provided to design the
database.
• Effectively use colors to highlight key areas in your diagrams.
Conclusion

ER Diagram in DBMS is widely used to


describe the conceptual design of databases.
It helps both users and database developers
to preview the structure of the database
before implementing the database.
Relational model
Preview
• Relational Model Concepts in DBMS
• Relational Integrity Constraints
• Operations in Relational Model
• Best Practices for creating a Relational Model
• Advantages of Relational Database Model
• Disadvantages of Relational Model
• Summary
What is Relational Model?
Relational Model (RM) represents the database as a collection of relations. A
relation is nothing but a table of values. Every row in the table represents a
collection of related data values. These rows in the table denote a real-world
entity or relationship.
The table name and column names are helpful to interpret the meaning of
values in each row. The data are represented as a set of relations. In the
relational model, data are stored as tables. However, the physical storage of
the data is independent of the way the data are logically organized.
Relational Model Concepts in DBMS
• Attribute: Each column in a Table. Attributes are the properties which define
a relation. e.g., Student_Rollno, NAME,etc.
• Tables – In the Relational model the, relations are saved in the table format.
It is stored along with its entities. A table has two properties rows and
columns. Rows represent records and columns represent attributes.
• Tuple – It is nothing but a single row of a table, which contains a single
record.
• Relation Schema: A relation schema represents the name of the relation
with its attributes.
• Degree: The total number of attributes which in the relation is called the
degree of the relation.
Relational Model Concepts in DBMS
• Cardinality: Total number of rows present in the Table.
• Column: The column represents the set of values for a specific attribute.
• Relation instance – Relation instance is a finite set of tuples in the RDBMS
system. Relation instances never have duplicate tuples.
• Relation key – Every row has one, two or multiple attributes, which is called
relation key.
• Attribute domain – Every attribute has some pre-defined value and scope
which is known as attribute domain
Relational Integrity Constraints
Relational Integrity constraints in DBMS are referred to conditions which must
be present for a valid relation. These Relational constraints in DBMS are
derived from the rules in the mini-world that the database represents.
There are many types of Integrity Constraints in DBMS. Constraints on the
Relational database management system is mostly divided into three main
categories are:
• Domain Constraints
• Key Constraints
• Referential Integrity Constraints
Domain Constraints
Domain constraints can be violated if an attribute value is not
appearing in the corresponding domain or it is not of the
appropriate data type.

Domain constraints specify that within each tuple, and the value of
each attribute must be unique. This is specified as data types which
include standard data types integers, real numbers, characters,
Booleans, variable length strings, etc.
Key Constraints
An attribute that can uniquely identify a tuple in a relation is called
the key of the table. The value of the attribute for different tuples in
the relation has to be unique. Example:
In the given table, CustomerID is a key attribute of Customer Table. It is most
likely to have a single key for one customer, CustomerID =1 is only for the
CustomerName =” Google”.
CustomerID CustomerName Status
1 Google Active
2 Amazon Active
3 Apple Inactive
Referential Integrity Constraints

Referential Integrity constraints in DBMS are based on the


concept of Foreign Keys. A foreign key is an important
attribute of a relation which should be referred to in other
relationships. Referential integrity constraint state happens
where relation refers to a key attribute of a different or same
relation. However, that key element must exist in the table.
In this example, we have
2 relations, Customer
and Billing.
Tuple for CustomerID =1
is referenced twice in
the relation Billing. So
we know
CustomerName=Google
has billing amount $300
Operations in Relational Model
Four basic update operations performed on relational database
model are
Insert, update, delete and select.
Insert is used to insert data into the relation
Delete is used to delete tuples from the table.
Modify allows you to change the values of some attributes in
existing tuples.
Select allows you to choose a specific range of data.
Whenever one of these operations are applied, integrity constraints
specified on the relational database schema must never be violated.
Insert Operation

• The insert operation gives values of the attribute for a new tuple which
should be inserted into a relation.
Update Operation

• You can see that in the below-given relation table CustomerName=


‘Apple’ is updated from Inactive to Active.
Delete Operation

• To specify deletion, a condition on the attributes of the relation selects


the tuple to be deleted.

In the above-given example, CustomerName= “Apple” is deleted from the table.

The Delete operation could violate referential integrity if the tuple which is
deleted is referenced by foreign keys from other tuples in the same database.
Select Operation

• In the given example, CustomerName=”Amazon” is selected


Best Practices for creating a Relational
Model
• Data need to be represented as a collection of relations
• Each relation should be depicted clearly in the table
• Rows should contain data about instances of an entity
• Columns must contain data about attributes of the entity
• Cells of the table should hold a single value
• Each column should be given a unique name
• No two rows can be identical
• The values of an attribute should be from the same domain
Advantages of Relational Database Model
• Simplicity: A Relational data model in DBMS is simpler than the hierarchical and network
model.
• Structural Independence: The relational database is only concerned with data and not
with a structure. This can improve the performance of the model.
• Easy to use: The Relational model in DBMS is easy as tables consisting of rows and
columns are quite natural and simple to understand
• Query capability: It makes possible for a high-level query language like SQL to avoid
complex database navigation.
• Data independence: The Structure of Relational database can be changed without having
to change any application.
• Scalable: Regarding a number of records, or rows, and the number of fields, a database
should be enlarged to enhance its usability.
Disadvantages of Relational Model
• Few relational databases have limits on field lengths which can’t
be exceeded.
• Relational databases can sometimes become complex as the
amount of data grows, and the relations between pieces of data
become more complicated.
• Complex relational database systems may lead to isolated
databases where the information cannot be shared from one
system to another.
Summary
• The Relational database modelling represents the database as a collection of relations
(tables)
• Attribute, Tables, Tuple, Relation Schema, Degree, Cardinality, Column, Relation instance, are
some important components of Relational Model
• Relational Integrity constraints are referred to conditions which must be present for a valid
Relation approach in DBMS
• Domain constraints can be violated if an attribute value is not appearing in the
corresponding domain or it is not of the appropriate data type
• Insert, Select, Modify and Delete are the operations performed in Relational Model
constraints
• The relational database is only concerned with data and not with a structure which can
improve the performance of the model
• Advantages of Relational model in DBMS are simplicity, structural independence, ease of use,
query capability, data independence, scalability, etc.
• Few relational databases have limits on field lengths which can’t be exceeded.

You might also like