Unit-2 Database Design using ER Model and Relational Model (E-next.in)
Unit-2 Database Design using ER Model and Relational Model (E-next.in)
4 The relationship between one strong The relation between two strong entities is
and a weak entity set is represented by denoted by a single diamond simply called
a double diamond sign. It is known as relationship.
identifying relationship.
5 Weak entity always has total Strong entity may or may not have total
participation in the identifying participation in the relationship.
relationship shown by double line.
6 The member of weak entity set is called The member of strong entity set is called as
as subordinate entity set. dominant entity set.
7 The line connecting weak entity set The line connecting strong entity set with
with the identifying relationship is the relationship is single.
double.
8 Total participation in the identifying Total participation in the relationship may
relationship always exist. or may not exist.
9 It contains a Partial Key or discriminator It contains a primary key represented by an
represented by a dashed underline. underline.
Keys:
Keys play an important role in relational database.
It is used for uniquely identify any record or row of data from the table. It is also
used to establish and identify relationships between tables.
For example:
In Student table, ID is used as a key because it is unique for each student. In PERSON
table, passport_number, license_number, SSN are keys since they are unique for
each person.
Primary Key:
Also known as PK, a primary key is a special kind of entity attribute that uniquely
defines a record in a database table.
In other words, there must not be two (or more) records that share the same value
for the primary key attribute.
A Candidate Key that is used by the database designer for unique identification of
each row in a table is known as Primary Key.
Primary key uniquely identifies each record in a table.
It must have unique values and cannot contain nulls.
A Primary Key can consist of one or more attributes of a table.
Foreign Key:
Also known as FK, a foreign key is a reference to a primary key in table.
Foreign keys are the column of table which is used to point to the primary key of
another table.
In a company, every employee works in a specific department and employee and
department are two different entities. So we can't store the information of the
department in the employee table. That's why we link these two tables through the
primary key of one table.
It is used to identify the relationships between entities. .
They act as a cross-reference between tables.
Note that foreign keys need not to be unique.
Multiple records can share the same values.
We add primary key of DEPARTMENT table, Department_Id as a new attribute in the
EMPLOYEE table.
Now in the EMPLOYEE table, Department_Id is the foreign key and both the tables
are related.
Candidate key:
It can be defined as minimal Super Key or irreducible Super Key.
In other words an attribute or a combination of attribute that identifies the record
uniquely but none of its proper subsets can identify the records uniquely.
Minimal set of attributes necessary to uniquely identify an entity
A superkey for which no subset is a superkey – minimal superkey
Candidate key is an attribute or set of attribute which can uniquely identify a tuple.
The remaining attributes except primary key which is as strong as primary key are
considered as candidate key.
For example: In the EMPLOYEE table, id is best suited for primary key. Rest of the attributes
like: SSN, Passport_Number and License_Number etc. are considered as candidate key.
Super Key:
An attribute or a combination of attribute that is used to identify the records
uniquely is known as Super Key.
A table can have many Super Keys.
Super key is a set of attribute which can uniquely identify a tuple.
Super key is a superset of candidate key.
For example:
In the above EMPLOYEE table, for (EMPLOEE_ID, EMPLOYEE_NAME) the name of
two employees can be same but their EMPLYEE_ID can't be same. Hence, this
combination can also be a key.
The super key would be: EMPLOYEE-ID, (EMPLOYEE_ID, EMPLOYEE-NAME) etc.
Composite Key:
If we use multiple attributes to create a Primary Key then that Primary Key is called
Composite Key (also called a Compound Key or Concatenated Key).
E.g. of Composite Key, if we have used “Name, Address” as a Primary Key then it will
be our Composite Key.
Alternate Key:
Alternate Key can be any of the Candidate Keys except for the Primary Key.
E.g. of Alternate Key is “Name, Address” as it is the only other Candidate Key which
is not a Primary Key.
Secondary Key:
The attributes that are not even the Super Key but can be still used for identification
of records (not unique) are known as Secondary Key.
E.g. of Secondary Key can be Name, Address, Salary, Department_ID etc. as they can
identify the records but they might not be unique.
For example:
Center entity offers the Course entity act as a single entity in the relationship which
is in relationship with another entity visitor. In the real world, if a visitor visits a
coaching center then he will never enquire about the Course only or just about the
Center rather he will ask enquire about both.
Generalization:
Generalization is like a bottom-up approach in which two or more entities of lower
level combine to form a higher level entity if they have some attributes in common.
In generalization, entity of higher level can also combine with the entities of lower
level to form further higher level entity.
Generalization is more like subclass and super-class system but the only difference is
the approach. Generalization uses the bottom-up approach.
In generalization, entities are combined to form a more generalized entity i.e.
subclasses are combined to make a super-class.
Process of identifying some common characteristics of a collection of entity sets and
creating a new entity set that contains entities possessing these common
characteristics
For example:
Faculty and Student entities can be generalized and create a higher level entity with
name Person.
Specialization:
Specialization is a top-down approach and it is opposite to Generalization. In
specialization, one higher level entity can be broken down into two lower level
entities.
Process of identifying subsets of an entity set that share some distinguishing
characteristics
Consider an entity set Person {name, street, city}. A Person may be – Customer,
Employee
Additional attributes – Customer {credit_rating}, Employee {salary}
The ISA relationship is also referred to as a superclass-subclass relationship.
It is a top-down design approach
An entity of a subclass inherits all attributes of the superclass
For example:
In an Employee management system, EMPLOYEE entity can be specialized as TESTER
or DEVELOPER based on what role they play in company.
Association:
An association defines a relationship between two entity objects based on common
attributes.
The relationship can be:
1. one-to-one
2. one-to-many
3. many-to-many
Daigram
Q.8 What is Entity Relationship Diagram (ER-Diagram)? Explain with its advantage.
ER model:
There are two techniques used for the purpose of data base designing from the
system requirements. These are:
1. Top down Approach known as Entity-Relationship Modeling
2. Bottom Up approach known as Normalization.
Entities:
They are represented using the rectangle shape box. These rectangles are named
with the entity set they represent.
ER modeling is a top-down structure to database design that begins with identifying
the important data called entities and relationships in combination between the data
that must be characterized in the model.
Then database model designers can add more details such as the information they
want to hold about the entities and relationships which are the attributes and any
constraints on the entities, relationships, and attributes.
ER modeling is an important technique for any database designer to master and
forms the basis of the methodology.
Entity type:
It is a group of objects with the same properties that are identified by the enterprise
as having an independent existence.
The basic concept of the ER model is the entity type that is used to represent a group
of ‘objects’ in the ‘real world’ with the same properties.
An entity type has an independent existence within a database.
Relationships:
Relationships are represented by diamond-shaped box. All the entities (rectangle
shaped) participating in a relationship gets connected using a line.
Concepts:
1. Tables
In relational data model, relations are saved in the format of Tables. This format
stores the relation among entities.
A table has rows and columns, where rows represents records and columns
represent the attributes.
2. Tuple
A single row of a table, which contains a single record for that relation is called a
tuple.
3. Relation instance
A finite set of tuples in the relational database system represents relation instance.
Relation instances do not have duplicate tuples.
4. Relation schema
A relation schema describes the relation name (table name), attributes, and their
names.
5. Relation key
Each row has one or more attributes, known as relation key, which can identify the
row in the relation (table) uniquely.
6. Attribute domain
Every attribute has some pre-defined value scope, known as attribute domain.
Constraints:
Every relation has some conditions that must hold for it to be a valid relation.
These conditions are called Relational Integrity Constraints.
There are three main integrity constraints:
1. Key constraints
2. Domain constraints
3. Referential integrity constraints
1. Key Constraints
There must be at least one minimal subset of attributes in the relation, which can
identify a tuple uniquely.
This minimal subset of attributes is called key for that relation.
If there are more than one such minimal subsets, these are called candidate keys.
Key constraints force that −in a relation with a key attribute, no two tuples can have
identical values for key attributes.
A key attribute can not have NULL values.
Key constraints are also referred to as Entity Constraints.
2. Domain Constraints
Attributes have specific values in real-world scenario. For example, age can only be a
positive integer.
The same constraints have been tried to employ on the attributes of a relation.
Every attribute is bound to have a specific range of values.
For example, age cannot be less than zero and telephone numbers cannot contain a
digit outside 0-9.
2. Default constraint:
This defines what value the column should use when no value has been supplied
explicitly when inserting a record in the table.
3. Nullability constraint:
This defines that if a column is NOT NULL or allow NULL values to be stored in it.
5. Unique constraint:
This defines that the values in a column must be unique and no duplicates should be
stored.
Sometimes the data in a column must be unique even though the column does not
act as Primary Key of the table.
For example CategoryName column is unique in categories table but CategoryName
is not primary key of the table.
7. Check constraint:
This defines a validation rule for the data values in a column so it is a user-defined
data integrity constraint.
This rule is defined by the user when designing the column in a table.
Not every database engine supports check constraints.
As of version 5.0, MySQL does not support check constraint. But you can use enum
data type or set data type to achieve some of its functionalities that are available in
other Relational Database Management Systems (Oracle, SQL Server, etc).