Dbms File 2
Dbms File 2
Database tier:
3-tier architecture separates it tier from each other on basis of users
At this tier, only database resides.
Database along with its query processing languages sits in layer-3 of 3-tier architecture.
It also contains all relations and their constraints.
Application (Middle) Tier
At this tier, the application server and program, which access database, resides.
For a user this application tier works as abstracted view of database.
Users are unaware of any existence of database beyond application.
For database-tier, application tier is the user of it.
Database tier is not aware of any other user beyond application tier.
This tier works as mediator between the two.
User (Presentation) Tier
An end user sits on this tier.
From a user’s aspect, this tier is everything.
He/she doesn’t know about any existence or form of database beyond this layer.
At this layer multiple views of database can be provided by the application.
All views which are generated by an application, resides in application tier.
1
Relationship between 2 entities is called binary relationship.
E.g. book is issued by student where book and student are entities and issue is relation.
Relationship set
Relationship set is a set of relationships of the same type.
Attributes
Attributes are properties hold by each member of an entity set.
E.g. entity is student and attributes of student are enrollmentno, name, address, cpi etc
Types of attributes
Simple attribute: It cannot be divided into subparts. E.g. cpi, rollno
Composite attribute: It can be divided into subparts. E.g. name (first-name, middle- name, last-
name), address.
Single valued attribute: It has single data value. E.g. enrollmentno, birthdate
Multi valued attribute: It has multiple data value. E.g. phoneno (may have multiple phones).
Stored attribute: It’s value is stored manually in database. E.g. birthdate
Derived attribute: It’s value is derived or calculated from other attributes. E.g. age (can be
calculated using current date and birthdate).
Descriptive attributes
A relationship may also have attributes like an entity. These attributes are called descriptive
attributes.
E.g. Student gets degree certificate on 14th March 2011. Student and Degree are entities, gets
certificate is relation and certificate date is an attribute of relationship.
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 other subjects.
subject
is prerequisite for
A binary relationship is the relationship
rel between two different entities.
The University might need to record which teachers taught which subjects.
course
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.
3
loan
A customer is connected with only one loan using the relationship borrower and a loan is
connected with only one customer using borrower.
One-to-many Relationship
lationship
A B
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.
loan
In the one-to-many
many relationship a loan is connected with only one customer using borrower and a
customer is connected with more than one loans using borrower.
Many-to-one relationship
A B
An entity in A is associated with at most (only) one entity in B and an entity in B is associated
with any number (zero or more) of entities in A.
loan
In a many-to-one
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-man relationship
A B
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.
loan
A customer is connected with more than one loan using borrower and a loan is cconnected with
more than one customer using borrower.
loan
Strong Entity
Weak Entity Relationship Weak Entity
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 entityset 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
salary
employee customer
ISA
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. Moral (Mandato )
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
o Total, Disjoint
o Total, Overlapping
o Partial, Disjoint
o Partial, Overlapping.
hours hours
number name id number
work uses
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.
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 )
Persons
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
PersonlD 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 withinthe
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
Phones
phoneid personid phone
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 wifelD, the attribute can set to NULL.
• 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
personid name address email
Countries
countryid name
HasRelat
hasrelatid personid countryid
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
• 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 multiple parents.
3. Entity-relationship Model
• In this database model, relationships are created by dividing object of interest into entity and
its characteristics into attributes.
4. Relational Model
• In this model, data is organized in two-dimensional tables and the relationship is maintained
by storing a common attribute.