Introduction To DBMS & ER-Diagram: Rishu Gupta & Manish Srivastava
Introduction To DBMS & ER-Diagram: Rishu Gupta & Manish Srivastava
&
ER-Diagram
Rishu Gupta & Manish Srivastava
Database System Overview
Data
Id
Attributes: Id, EName, EAge, Salary
EName
EAge
Employee
Salary
Employee
John E1 32 7L
James E2 28 8L
John E3 32 5L
Rishu Gupta & Manish Srivastava
Relational Model
● Degree of relation is the number of attributes it contains. e.g. Degree of relation below is 4.
● NULL represents the value of an attribute that is currently unknown or not applicable.
● A domain is the set of allowable values for one or more attributes. E.g. EAge Domain(28,29,30,31,32)
John E1 32 7L
James E2 28 8L
John E3 32 NULL
● Composite Key: Any combination of more than one attribute that can uniquely identify an entity in its
entity set.
● Candidate Key: All those super keys that, if broken down further, will no longer be able to uniquely
identify the entity in its entity set. All the candidate keys are “candidate” to be designated as Primary
Key.
● Primary Key: We can choose any appropriate candidate key as Primary Key. Candidate key consists of
one or more attributes, none of the constituent attribute should be null.
● Foreign Key: A foreign key is a set of one or more columns in the child table whose values are
required to match with corresponding columns in the parent table. Foreign key columns on child
tables must be primary key or unique on the parent table. The child table can contain NULL values.
Let us take Employee and Computer tables as provided below
For e.g. try to identify some candidate keys for below relation:
Employee(EmployeeNo, Name, AadharNo, Salary, DateOfBirth)
Thus the choice of candidate key depends upon the business context. Rishu Gupta & Manish Srivastava
Primary Key
It is the candidate key that is selected to uniquely identify a tuple in a relation. The mandatory and desired
attributes for a primary key are:
When two or more columns together identify the unique row then it's referred to as Composite Primary Key.
The combination of Name and DateOfBirth if selected as a primary key would be a composite primary key.
● Computer is the parent table with CompId as the primary key. Employee is the child table with Id as
the primary key. If we want to allocate a maximum of one computer to an employee then CompId
must be made the foreign key in the Employee table. It can only contain values that are present in
Computer table or no values at all. We cannot allocate a computer that does not exist to an
employee.
● Additionally multiple rows in the child table can link to the same row of the parent table depending
upon the type of relationship.
Rishu Gupta & Manish Srivastava
Crow foot notation
● Crow foot notation is one of the ways to represent
cardinality of relationship in an ER Model. The notation
comprises of four symbols and one of them need to be
used for each entity in a relationship.
In 1 : N relationships, the foreign key and relationship attributes are always added to the many (N) side of
the relationship. Hence these attributes are added to Computer table. The reverse solution will not work.
Rishu Gupta & Manish Srivastava
M : N Relationship
● M:N relationship represents association between multiple occurrences of both entities. For e.g.
consider a company where each employee can be allocated many computers and computers can be
shared between employees.
In M : N relationships, the relationship is represented by a completely new table that has a composite
primary key. Such a structure requires two foreign keys on the new table linking to the primary keys of each
of the parent tables. The attribute of the relationship resides on this new table.
Rishu Gupta & Manish Srivastava
Relationship and Foreign Key
Foreign keys need to be created in tables in order to establish relationship between entities. The table in which
foreign key will be created depends upon the cardinality of relationship.