UNIT-1 DBMS (1)
UNIT-1 DBMS (1)
Conceptual View
Conceptua
l Level
Interna
l Internal View
Level
Presentation Tier
user client
application client
Application Tier
network
application server
Database Tier
server
database system
student-name
Issue date
Degree of relationship
The degree of a relationship is the number of entity types that participate in the
relationship.
The three most common relationships in ER models are Unary, Binary and Ternary.
A unary relationship is when both participant entities in the relationship are the same
entity.
Example: Subjects may be prerequisites for othersubjects.
subject
is prerequisite for
J
2 – Data Models
teacher teaches
subject
course
A1 ___________ B1
A2 ___________ B2
A3 B3
A4 ___________ B4
s
An entity in A is associated with at most (only) one entity in B and an entity in B is
associated with at most (only) one entity in A.
customer-name customer-address
A1 __________________________________ B1
A2 B2
A3 __________________________________ B3
A4 B4
An entity in A is associated with any number (zero or more) of entities in B and an entity
in B is associated with at most (only) one entity in A.
customer-name customer-address
loan-no amount
customer-id customer-city
In the one-to-many relationship a loan is connected with only one customer using borrower
and a customer is connected with more than one loans using borrower.
2 – Data Models
Many-to-one relationship
A B
A1 __________________________________ B1
A2 B2
A3 __________________________________ B3
A4 B4
customer-name customer-address
loan-no amount
customer-id customer-city
In a many-to-one relationship a loan is connected with more than one customer using
borrower and a customer is connected with only one loan using borrower.
Many-to-many relationship
A B
A1 __________________________________ B1
A2 B2
A3 __________________________________ B3
A4 B4
J
2 – Data Models
An entity in A is associated with any number (zero or more) of entities in B and an entity
in B is associated with any number (zero or more) of entities in A.
customer-name customer-address
A customer is connected with more than one loan using borrower and a loan is connected
with more than one customer using borrower.
J
2 – Data Models
customer-name customer-address
payment-date
Strong Entity
Weak Entity Relationship Weak Entity
J
2 – Data Models
Explain the Superclass and Subclass in E-R diagram with the help of example.
Superclass
A superclass is an entity from which another entity can be derived.
A superclass is a generic entity set which has a relationship with one or more subclasses.
For example, an entity set account has two subsets saving_account and
current_account. So an account is superclass.
Each member of subclass is also a member of superclass. So any saving account or a
current account is a member of entity set account.
Subclass
A subclass is an entity that is derived from another entity.
A class is a subset of entities in an entity set which has attributes distinct from those in
other subset.
For example, entities of the entity set account are grouped in to two classes
saving_account and current_account. So saving_account and current_account are
subclasses.
superclass
account
person
employee
customer
ISA
officer-number hours-worked
station-number hours-worked
Participation Constraint
Determines whether every member in super class must participate as a member of a
subclass or not.
It may be total (mandatory) or partial (optional).
1. Total (Mandatory)
Total specifies that every entity in the superclass must be a member of some subclass in the
specialization.
Specified by a double line in EER diagram.
2. Partial (Optional)
Partial specifies that every entity in the super class not belong to any of the subclass of
specialization.
Specified by a single line in EER diagram.
Based on these two different kinds of constraints, a specialization or generalization can be
one of four types
Total, Disjoint
Total, Overlapping
Partial, Disjoint
Partial, Overlapping.
work
hours hours
name id number name id number
machinery machinery
uses
id id
machinery
Fig. A Fig. B
Relationship sets work and uses could be combined into a single set. We can combine
them by using aggregation.
Aggregation is an abstraction through which relationships are treated as higher-level
entities.
For our example, we treat the relationship set work and the entity sets employee and
project as a higher-level entity set called work.
Transforming an E-R diagram with aggregation into tabular form is easy. We create a
table for each entity and relationship set as before.
The table for relationship set uses contains a column for each attribute in the primary
key of machinery and work.
It is highly recommended that every table should start with its primary key attribute
conventionally named as TablenameID.
Consider the following simple ER diagram:
PersonID Person
Phone
Name
Address Email
The initial relational schema is expressed in the following format writing the table names
with the attributes list inside a parentheses as shown below
Persons( personid, name, address, email )
Person
personid name address Email
Persons and Phones are Tables and personid, name, address and email are Columns
(Attributes).
personid is the primary key for the table : Person
PersonID Person
Phone
If you have a multi-valued attribute, take that multi-valued attribute and turn it into a new
entity or table of its own.
Then make a 1:N relationship between the new entity and the existing one.
In simple words.
1. Create a table for that multi-valued attribute.
2. Add the primary (id) column of the parent entity as a foreign key within the
new table as shown below:
First table is Persons ( personid, name, address, email )
Second table is Phones ( phoneid , personid, phone )
personid within the table Phones is a foreign key referring to the personid of Persons
Phone
phoneid personid phone
2 – Data Models
Step 3: 1:1 Relationship
WifeID Name
Wife
Have
PersonID Person
Phone
Name
Address Email
Let us consider the case where the Person has one wife. You can place the primary key of
the wife table wifeid in the table Persons which we call in this case Foreign key as shown
below.
Persons( personid, name, address, email , wifeid )
Wife ( wifeid , name )
Or vice versa to put the personid as a foreign key within the wife table as shown below:
Persons( personid, name, address, email )
Wife ( wifeid , name , personid)
For cases when the Person is not married i.e. has no wifeID, the attribute can set to
NULL
Persons Wife
personid name address email wifeid wifeid name
OR
Persons Wife
personid name address email wifeid name personid
2 – Data Models
Address
Has
PersonID Person
Phone
Name
Address Email
For instance, the Person can have a House from zero to many, but a House can have only
one Person.
In such relationship place the primary key attribute of table having 1 mapping in to the
table having many cardinality as a foreign key.
To represent such relationship the personid as the Parent table must be placed within the
Child table as a foreign key.
It should convert to :
Persons( personid, name, address, email )
House ( houseid, name , address, personid)
Persons House
personid name address email houseid name address personid
Has
PersonID Person
Phone
Name
Address Email
2 – Data Models
For instance, The Person can live or work in many countries. Also, a country can have
many people. To express this relationship within a relational schema we use a separate
table as shown below:
It should convert into :
Persons( personid, name, address, email )
Countries ( countryid, name)
HasRelat ( hasrelatid, personid , countryid)
Persons Countries
personid name address email countryid name
HasRelat
hasrelatid personid Countryid
What is E-R model (Entity-Relationship) model (diagram) also draw various symbols using
in E-R diagram.
E-R model
Entity-relationship (ER) model/diagram is a graphical representation of entities and their
relationships to each other with their attributes.
2 – Data Models
1. Hierarchical Model
The hierarchical model organizes data into a tree-like structure, where each record has a
single parent or root.
department
student professor
2 – Data Models
The hierarchy starts from the Root data, and expands like a tree, adding child nodes to the
parent nodes.
In hierarchical model, data is organized into tree-like structure with one-to-many
relationship between two different types of data, for example, one department can have
many professors and many students.
2. Network Model
This is an extension of the hierarchical model, allowing many-to-many relationships in a
tree-like structure that allows multipleparents.
B C
D E F
3. Entity-relationship Model
In this database model, relationships are created by dividing object of interest into entity
and its characteristics into attributes.
customer-name customer-address
4. Relational Model
In this model, data is organized in two-dimensional tables and the relationship is
maintained by storing a common attribute.
2 – Data Models
Rno StudentName Age SubjectID SubjectName Teacher
1 Raj 21 1 DBMS Patel
2 Meet 22 2 DS Shah
Integrity constraints are a set of rules. It is used to maintain the quality of information.
Integrity constraints ensure that the data insertion, updating, and other processes have to be
performed in such a way that data integrity is not affected.
Thus, integrity constraint is used to guard against accidental damage to the database.
Various Integrity Constraints are:
1. Check
This constraint defines a business rule on a column. All the rows in that
column must satisfy this rule.
Limits the data values of variables to a specific set, range, or list of values.
The constraint can be applied for a single column or a group of columns.
E.g. value of SPI should be between 0 to 10.
2. Not null
This constraint ensures all rows in the table contain a definite value for the
column which is specified as not null. Which means a null value is not
allowed.
E.g. name column should have some value.
2 – Data Models
3. Unique
This constraint ensures that a column or a group of columns in
each row have a distinct (unique) value.
A column(s) can have a null value but the values cannot be duplicated.
E.g enrollmentno column should have unique value.
4. Primary key
This constraint defines a column or combination of columns
which uniquely identifies each row in the table.
Primary key = Unique key + Not null
E.g enrollmentno column should have unique value as well as can’t be
null.
5. Foreign key
A referential integrity constraint (foreign key) is specified between two
tables.
In the referential integrity constraints, if a foreign key column in
table 1 refers to the primary key column of table 2, then every
value of the foreign key column in table 1 must be null or be
available in primary key column of table 2.