DBMS Module1
DBMS Module1
MODULE 1: Chapter-1
Introduction to Database Management System
Overview:
Data means known fact that can be recorded and that have implicit meaning.
A database is a collection of related data which are known facts that can be recorded and
that have implicit meaning.
o For example, consider the names, telephone numbers, and addresses of the people
we know. We may have recorded this data in an indexed address book or you may
have stored it on a hard drive, using a personal computer and software such as
Microsoft Access or Excel. This collection of related data with an implicit meaning
is a database.
A database management system (DBMS) is a collection of programs that enables users to
create and maintain a database. The DBMS is a general-purpose software system that
facilitates the processes of defining, constructing, manipulating, and sharing databases
among various users and applications.
o Defining a database involves specifying the data types, structures, and constraints
of the data to be stored in the database. The database definition or descriptive
information is also stored by the DBMS in the form of a database catalog or
dictionary, it is called meta-data.
o Constructing the database is the process of storing the data on some storage
medium that is controlled by the DBMS.
o Manipulating a database includes functions such as querying the database to
retrieve specific data, updating the database to reflect changes in the mini-world,
and generating reports from the data.
o Sharing a database allows multiple users and programs to access the database
simultaneously.
An application program accesses the database by sending queries or requests for data to
the DBMS. A query typically causes some data to be retrieved. A transaction may cause
some data to be read and some data to be written into the database.
Other important functions provided by the DBMS include protecting the database and
maintaining it over a long period of time.
The below figure illustrates the database system. The database and DBMS software together is
called as a database system.
Page 1
DBMS Dept of CSE
An example database
Consider a UNIVERSITY database for maintaining information concerning students,
courses, and grades in a university environment.
The database is organized as five files, each of which stores data records of the same type.
To define this database, we must specify the structure of the records of each file by
specifying the different types of data elements to be stored in each record.
o For example: each STUDENT record includes data to represent the student’s Name,
Studentnumber, Class and Major(like CS)such as freshman or ‘1’, sophomore or ‘2’,
and so forth), and records and have many relationships among the records.
We must also specify a data type for each data element within a record.
o For example, we can specify that Name of STUDENT is a string of alphabetic
characters, Studentnumber of STUDENT is an integer, and Grade of
GRADE_REPORT is a single character from the set {‘A’, ‘B’, ‘C’, ‘D’, ‘F’, ‘I’}.
Page 2
DBMS Dept of CSE
To construct the UNIVERSITY database, we store data to represent each student, course,
section, grade report, and prerequisite as a record in the appropriate file.
The records in the various files may be related. For example, the record for Smith in the
STUDENT file is related to two records in the GRADE_REPORT file that specify Smith’s
grades in two sections.
Page 4
DBMS Dept of CSE
Example: if A want to transfer 5000rs to B's account. In this case A's Account should
be debited and B's account should be credited with the same amount. Let suppose A's
account is debited with 5000rs and the transaction fails due to some problem. Now
transaction is incomplete because B's account is not credited. These type of problem
occurs in file system because there is no procedure to stop such type of anomalies.
Transaction atomicity is a special feature of DBMS. In DBMS either a transaction
completed fully or none of the action is performed.
Security Problems -In file system there is no or very less security. General security
provided by file systems are locks, guards etc. Whereas DBMS provides a way for
different users have different level of access to database. It will provide security in
Different level.
Data Isolation –In file system there is no standard format of data or we can say data is
scattered in various formats or files which also make data retrieval difficult. In DBMS
system, due to the centralized system the format of similar type of data remains same.
8. Integrity constraints cannot be provided Integrity constraints can be applied when data is
predefined created.
9. Security is less- backup, restore problems Security is more – backup and restore can be done.
Page 5
DBMS Dept of CSE
Advantages of DBMS:
Minimize Data Redundancy -In File Processing System, duplicate data is created in
many places because all the programs have their own files. This creates data
redundancy which in turns wastes labor and space. In Database Management System, all
the files are integrated in a single database. The whole data is stored only once at a single
place so there is no chance of duplicate data.
For example: A student record in library or examination can contain duplicate values, but
when they are converted into a single database, all the duplicate values are removed.
Complete redundancy can be removed because somehow we need duplicate value to relate
tables with each other. But still DBMS controls data redundancy that saves lots of labor and
time.
Data Consistency - DBMS controls data redundancy which in turn controls data
consistency. Data consistency means if you want to update data in any files then all the
files should not be updated again. As in DBMS, data is stored in a single database so
data becomes more consistent in comparison to file processing system. Also updated
values are available to all the users immediately.
Data Integrity - Data integrity means unification of so many files into a single file. In
DBMS data is stored in different tables. A database contains different tables that are
linked to each other. Many users feed entries in these tables so it is important to
maintain data items and association between data items. DBMS allows data integrity
that makes it easy to decrease data duplicity Data integration reduces redundancy as
well as data inconsistency.
Search Capability - Users of database may require to fetch data from the database.
There are numerous queries users may ask about the data. Search speed of the database
must be fast to produce quick results. If users execute any query, then it is required that
he get fastest results from the database. It is an objective of database to maintain
flexible search capability.
Security - Data security means protecting your precious data from unauthorized access.
Data in database should be kept secure and safe to unauthorized modifications. Only
authorized users should have the grant to access the database. There is a username set
for all the users who access the database with password so that no other guy can access
this information. DBMS always keep database tamperproof, secure and theft free.
Page 6
DBMS Dept of CSE
Privacy - Privacy means up to what extent a user can access the data. It is
predetermined by the DBA that who will access the data and up to what level he will be
able to access it. Let say when you make a Facebook page then you have the power to
give rights to other users that who will be the promoter, editor and admin.
Simplicity - Simplicity means to represent the overall logical view of data in a simple
and clear manner. DBMS is very simple for its users who use it. All the operations like
insert, delete, create and update are very easy to implement.
Backup and Recovery - Data loss is a very big problem for all the organizations. In
traditional file processing system, a user needs to back up the database after a regular
interval of time that wastes lots of time and resources. If the volume of data is large then
this process may take a very long time.
DBMS solves this problem of taking back up again and again because it allows
automatic backup and recovery of database. For examples, if a system fails in the
middle of any process then DBMS stores the values of that state in which database were
before query execution.
Integrity Constraints - Constraints are used to store accurate data because there are
many users who feed data in database. Data stored in database should always be correct
and accurate. DBMS provides the capability to enforce these constraints on database.
For example, the maximum marks obtained by the students can never be more than
100. Also account balance of Banks like Axis should not be less than 2500 otherwise
you will be penalized.
Data Atomicity - Any complete transaction in database is called atomic unit. It is the
duty of DBMS to store a complete transaction in database. If any transaction is partially
completed, then it roll backs them.
For example, in railway reservation system, if user has completed the process of ticket
reservation then his record will be stored and amount of money will be deducted from
his account otherwise no amount will be deducted and if deducted it will be given back.
Concurrency Control - If two users are accessing data simultaneously and they both
want to update values of same record then it may create concurrency. DBMS has the
power to control concurrency so that no transactions are lost.
Maintaining Cost is lower - DBMS systems are costly but after purchasing them their
maintenance cost is very less. It can be maintained by few programmers that is not
costly for an enterprise.
Very Less Chances of Data Loss - As there is lot of security constraint made on
database so chances of data loss are minimum. One can store their precious data or
Page 7
DBMS Dept of CSE
Other Data Models In addition to the relational data model are the Hierarchical model
(e.g., used in IBM’s IMS DBMS), Network model (e.g., used in IDS and IDMS), the
Page 8
DBMS Dept of CSE
Object oriented model (e.g., used in Object store and Versant), and the object-
relational model (e.g., used in DBMS products from IBM, Informix, Object Store,
Oracle, Versant, and others). While there are many databases that use the hierarchical
and network models, and systems based on the object-oriented and object-relational
models are gaining acceptance in the marketplace. The dominant model today is the
relational model.
Page 9
DBMS Dept of CSE
Physical Schema
It describes the physical storage structure of the database. Which uses a physical data
model and describes the complete details of data storage and access paths for the
database.
The physical schema specifies additional storage details. Essentially, the physical
schema summarizes how the relations described in the conceptual schema are actually
stored on secondary storage devices such as disks and tapes. We must decide what file
organizations to use to store the relations, and create auxiliary data structures called
indexes to speed up data retrieval operations.
A sample physical schema for the university database follows:
o Store all relations as unsorted files of records. (A file in a DBMS is either a
collection of records or a collection of pages, rather than a string of characters as in
an operating system.)
o Create indexes on the first column of the Students, Faculty, and Courses relations,
the sal column of Faculty, and the capacity column of Rooms.
Decisions about the physical schema are based on an understanding of how the data is
typically accessed. The process of arriving at a good physical schema is called physical
database design.
External Schema
External schemas allow data access to be customized (and authorized) at the level of
individual users or groups of users.
Any given database has exactly one conceptual schema and one physical schema
because it has just one set of stored relations, but it may have several external schemas,
each tailored to a particular group of users.
Each external schema consists of a collection of one or more views and relations from
the conceptual schema.
A view is conceptually a relation, but the records in a view are not stored in the DBMS.
Rather, they are computed using a definition for the view, in terms of relations stored in
the DBMS. The external schema design is guided by end user requirements.
For example, we might want to allow students to find out the names of faculty members
teaching courses, as well as course enrollments. This can be done by defining the
following view:
o Courseinfo (cid: string, fname: string, enrollment: integer)
A user can treat a view just like a relation and ask questions about the records in the
view. Even though the records in the view are not stored explicitly, they are computed
as needed.
Data Independence
Page 10
DBMS Dept of CSE
Data independence is the capacity to change the schema at one level of a database
system without having to change the schema at the next higher level.
The following are the types of data independence:
o Logical data independence
o Physical data independence
Page 11
DBMS Dept of CSE
Queries in DBMS :
A query is a request for data or information from a database table or combination of
tables. Or A query is a question, often expressed in a formal way.
A database query can be either a select query or an action query. A select query is
a data retrieval query, while an action query asks for additional operations on the data,
such as insertion, updating or deletion.
Example :
1. What is the name of the student with student id 123456?
2. What is the average salary of professors who teach the course with cid CS564?
3. How many students are enrolled in course CS564?
4. What fraction of students in course CS564 received a grade better than B?
5. Is any student with a GPA less than 3.0 enrolled in course CS564?
Such questions involving the data stored in a DBMS are called queries.
A DBMS provides a specialized language, called the query language, in which queries
can be posed.
Relational calculus is a formal query language based on mathematical logic, and
queries in this language have an intuitive, precise meaning.
Relational algebra is another formal query language, based on a collection of operators
for manipulating relations, which is equivalent in power to the calculus.
A DBMS enables users to create, modify, and query data through a data manipulation
language (DML). Thus, the query language is only one part of the DML, which also
provides constructs to insert, delete, and modify data.
Transaction Management :
A transaction is any one execution of a user program in a DBMS. (Executing the same
program several times will generate several transactions.) Partial transactions are not
allowed, and the effect of a group of transactions is equivalent to some serial execution
of all transactions.
Transaction Management: A transaction is one or more SQL statements that make up
a unit of work performed against the database, and either all the statements in
a transaction are committed as a unit or all the statements are rolled back as a unit.
Two main issues deals with transaction
1. Failure of various kinds, such as hardware failure and system crashes.
2. Concurrent execution of multiple transaction.
Page 12
DBMS Dept of CSE
Page 13
DBMS Dept of CSE
A DBMS must ensure that the changes made by such incomplete transactions are
removed from the database.
For example, if the DBMS is in the middle of transferring money from account A to
account B, and has debited the first account but not yet credited the second when the
crash occurs, the money debited from account A must be restored when the system
comes back up after the crash.
DBMS supports atomicity. Atomicity means a transaction must be all -or-nothing
i.e. the transaction must either fully happen, or not happen at all. It must not
complete partially.
Example: if A want to transfer 5000rs to B's account. In this case A's Account
should be debited and B's account should be credited with the same amount. Let
suppose A's account is debited with 5000rs and the transaction fails due to some
problem. Now transaction is incomplete because B's account is not credited. These
type of problem occurs in file system because there is no procedure to stop such
type of anomalies.
To handle incomplete transaction, the DBMS maintains a log of all writes to the
database. A crucial property of the log is that each write action must be recorded in
the log (on disk) before the corresponding change is reflected in the database itself.
Suppose if system crashes data can be restored with the help of this log file. If the
system crashes just after making the change in the database but before the change is
recorded in the log, the DBMS would be unable to detect and undo this change. This
property is called Write-Ahead Log.
Structure of DBMS:
The structure of a DBMS based on the Relational Data Model.
The DBMS acts as an interface between the user and the database. The user requests the DBMS to
perform various operations such as insert, delete, update and retrieval on the database.
The components of DBMS perform these requested operations on the database and provide
necessary data to the users.
The DBMS accepts SQL commands generated from a variety of user interfaces.
The Query Evaluation Engine evaluates and executes a plan against the database, and returns the answer.
1. When a user issues a query, the parser, parses the given request i/p into machine understandable
language, and query optimizer optimizes and produces a plan for evaluating the query like how the
data is stored to produce an efficient plan for evaluating the query
2. An execution plan is a blueprint for evaluating a query, represented as a tree of relational operators
(operators serves as a building blocks for evaluating queries posed against data, which brings the
needed data to the main memory)
Page 14
DBMS Dept of CSE
Structure of DBMS
6. Transaction manager ensures that transactions request and release locks according to a locking
protocol and schedules the execution transactions
7. Lock manager keeps track of request of locks and grants on database objects when they are available.
8. DBMS supports Concurrency control and Crash Recovery by carefully scheduling user requests and
maintaining a log of all changes to the database.
9. Recovery manager maintains a log and restores the system to a consistent state when a crash occurs.
Page 15
DBMS Dept of CSE
Responsibilities of DBA:
DBA designs the conceptual schema (what relations to store) and physical schema (how to store
them)
DBA ensures that unauthorized data access is not permitted.
DBA ensures security by granting permissions to different users to access the only certain views
and relations.
DBA ensures crash recovery and takes necessary steps to restore the data to a consistent state.
DBA ensures data tuning i.e, takes the responsibility for modifying the database, in particular
conceptual and physical schema (basing on users’ requirements)
Page 16
DBMS
MODULE 1
Chapter-2 Data Model
Data Model
A Data Model is a logical structure of Database. It describes the design of database to reflect
entities, attributes, relationship among data, constrains etc. that determine how data can be
stored and accessed.
Data models define how the logical structure of a database is modeled. Data Models are
fundamental entities to introduce abstraction in a DBMS.
Data models define how data is connected to each other and how they are processed and
stored inside the system.
Data models can facilitate interaction among the designer, the applications programmer, and
the end user.
Depending on the levels of data, data model divided into 3 categories
1. Object Based
2. Physical and
3. Record based Data models.
Page 1
DBMS
It is one of the important data model which forms the basis for the all the designs in the
database world. It defines the mapping between the entities in the database.
ER model represents the all these entities, attributes and their relationship in the form of
picture to make the developer understand the system better.
Advantages
Disadvantages
1. No standard notations are available for ER diagram. There is great flexibility in the
notation. It’s all depends upon the designer, how he draws it.
2. It is meant for high level designs. We cannot simplify for low level design like coding.
Page 2
DBMS
address and phone number? We write two separate procedure sp_getAddress and
sp_getPhone.
Advantages
Because of its inheritance property, we can re-use the attributes and functionalities. It
reduces the cost of maintaining the same data multiple times. Also, these informations are
encapsulated and, there is no fear being misused by other objects.
If we need any new feature we can easily add new class inherited from parent class and
adds new features. Hence it reduces the overhead and maintenance costs.
Because of the above feature, it becomes more flexible in the case of any changes.
Codes are re-used because of inheritance.
Since each class binds its attributes and its functionality, it is same as representing the
real world object. We can see each object as a real entity. Hence it is more
understandable.
Disadvantages
It is not widely developed and complete to use it in the database systems. Hence it is not
accepted by the users.
It is an approach for solving the requirement. It is not a technology. Hence it fails to put it
in the database management systems.
Page 3
DBMS
Page 4
DBMS
Advantages
This model groups the related data into tables and defines the relationship between the
tables, which is not addressed in flat files.
Page 5
DBMS
Disadvantages
Redundancy: - In such case, we have to store same project information for more than
one department. This is duplication of data and hence a redundancy. So, this model does
not reduce the redundancy issue to a significant level.
If we need to fetch any data in this model, we have to start from the root of the model and
traverse through its child till we get the result. In order to perform the traversing, either
we should know well in advance the layout of model or we should be very good
programmer. Hence fetching through this model becomes bit difficult.
Advantages
Accessing the records in the tables is easy since it addresses many to many relationships.
One can easily navigate among the tables and get any data.
It is designed based on database standards – ANSI/SP ARC.
Page 6
DBMS
Disadvantages
If there is any requirement for the changes to the entities, it requires entire changes to the
database.
There is no independence between any objects. Hence any changes to the any of the object
will need changes to the whole model. Hence difficult to manage.
It would be little difficult to design the relationship between the entities, since all the entities
are related in some way.
Page 7
DBMS
Advantages
Structural independence:- Any changes to the database structure, does not affect the
way we are accessing the data.
Simplicity: - This model is designed based on the logical data. It does not consider how
data are stored physically in the memory.
Because of simplicity and data independence, this kind of data model is easy to maintain
and access.
This model supports structured query language – SQL.
Disadvantages
Compared to the advantages above, the disadvantages of this model can be ignored.
High hardware cost
Sometimes, design will be designed till the minute level, which will lead to complexity in
the database.
Importance of data model :
1. Higher quality. A data model helps define the problem, enabling us to consider different
2. Reduced cost. You can build applications at lower cost via data models. Data modeling
typically consumes less than 10 percent of a project budget, and can reduce the 70 percent of
budget that is typically devoted to programming. The models promote clarity of thought and
provide the basis for generating much of the needed database and programming code.
Page 8
DBMS
3. Quicker time to market. You can also build software faster by catching errors early. In
addition, a data model can automate some tasks – design tools can take a model as an input and
generate the initial database structure, as well as some data access code.
4. Clearer scope. A data model provides a focus for determining scope. It provides something
tangible to help business sponsors and developers agree over precisely what is included with the
software and what is omitted.
6. Better documentation. Models document important concepts and jargon, proving a basis for
long-term maintenance.
7. Fewer application errors. A data model causes participants to crisply define concepts and
resolve confusion. As a result, application development starts with a clear vision. Developers can
still make detailed errors as they write application code, but they are less likely to make deep
errors that are difficult to resolve.
8. Managed risk. You can use a data model to estimate the complexity of software, and gain
insight into the level of development effort and project risk. We should consider the size of a
model, as well as the intensity of inter-table connections.
9. A good start for data mining. The documentation inherent in a model serves as a starting
point for analytical data mining.
Page 9
Database Management System
MODULE 1 : CHAPTER 3
ENTITY-RELATIONSHIP MODEL
(ER-MODEL)
Entity-Relationship (ER) model :
Which is a popular high-level conceptual data model, this model and its variations are
frequently used for the conceptual design of database applications, and many database design
tools employ its concepts.
ER-Models are used in the design of conceptual schemas for database applications. The
diagrammatic notation associated with the ER model, known as ER diagrams.
ENTITY TYPES, ENTITY SETS, ATTRIBUTES, AND KEYS
ATTRIBUTES
Each entity has attributes, which are the particular properties that describe it.
Example: EMPLOYEE entity may be described by the employee’s name, age,
address, salary, and job.
A particular entity will have a value for each of its attributes.
The below Figure shows two entities and the values of their attributes. The
EMPLOYEE entity e1 has four attributes: Name, Address, Age, and Home_phone
and their values are ‘John Smith,’ ‘2311 Kirby, Houston, Texas 77001’, ‘55’, and
‘713-749-2630’, respectively.
The COMPANY entity c1 has three attributes: Name, Headquarters, and President
and their values are ‘Sunco Oil’, ‘Houston’, and ‘John Smith’, respectively.
Page 1
Database Management System
TYPES OF ATTRIBUTES
1. Simple attributes.
2. Composite attributes.
3. Single valued attributes.
4. Multi valued attributes.
5. Stored attributes.
6. Derived attributes
Simple Attribute:
An attribute that cannot be divided into smaller independent attribute is known as atomic
attribute.
Example: assume Student is an entity and its attributes are Name, Age, Address and
Phone no. Here the age (attribute) of student (entity) cannot further divide. In this
example age is atomic attribute.
Composite attribute:
An attribute that can be divided into smaller independent attribute is known ascomposite
attribute.
Example: assume Student is an entity and its attributes are Name, Age, Address and
Phone no. Here the address (attribute) of student (entity) can be further divide into House
no, city and so on. In this example address is not atomic attribute.
The notation for this:
Page 2
Database Management System
An attribute that can have multiple values for an entity is known as multi valued
attribute.
Example: assume Student is an entity and its attributes are Name, Age, Address and
Phone no. Here the Phone no (attribute) of student (entity) can have multiple value
because a student may have many phone numbers. Here, Phone no is multi valued
attribute.
The notation for this:
Stored attribute
An attribute that cannot be derived from another attribute is known as stored attribute.
Example: birth date cannot derive from age of student.
Derived attribute
An attribute that can be derived from another attribute is known as derived attribute.
Example: age cannot derive from birth date of student.
The notation for this:
Page 3
Database Management System
Complex Attributes:
Composite and Multivalued attributes can be nested arbitrarily. Such attributes are
called as complex attributes.
Composite attributes can be represented by grouping components of a composite
attribute between parentheses () and separating the components with commas, and
by displaying multivalued attributes between braces { }.
Example: if a person can have more than one residence and each residence can
have a single address and multiple phones, an attribute Address_phone for a
person can be specified as shown in below Figure 7.5. Both Phone and Address
are themselves composite attributes.
Page 4
Database Management System
The process of taking the union of two or more lower level entity sets to produce a higher level
entity set.
It starts from the number of entity sets and creates high level entity set using some common features.
The process of creation of sub-groups within an entity is called specialization.
It is Top-down approach.
The process of taking a sub set of higher level entity set to form a lower level entity set.
It starts from a single entity set and creates different low level entity sets using some different
features.
Page 5
Database Management System
Data models use three types of relationships: one-to-many, many-to-many, and one-to-one.
Constraint: is a restriction placed on the data. Constraints are important because they
help to ensure data integrity. And it's normally expressed in the form of rules.
Example: An employee's salary must have values that are between 6000 and 350000 Each class must have
one and only one teacher
An entity type defines a collection (or set) of entities that have the same attributes. Each
entity type in the database is described by its name and attributes.
Example: a company employing hundreds of employees may want to store
similar information concerning each of the employees. These employee entities
share the same attributes, but each entity has its own value(s) for each attribute.
The collection of all entities of a particular entity type in the database is called an entity
set. The entity set is usually referred to using the same name as the entity type.
Example: EMPLOYEE refers to both a type of entity as well as the current set of
Page 6
Database Management System
Key Attributes of an Entity Type
Key plays an important role in database; it is used for identifying unique rows from
entity. It also establishes relationship entity set.
An entity type usually has one or more attributes whose values are distinct for each
individual entity in the entity set. Such an attribute is called a key attribute, and its
values can be used to identify each entity uniquely.
Example: the Name attribute is a key of the COMPANY entity type in above Figure 7.6
because no two companies are allowed to have the same name. For the PERSON entity
type, a typical key attribute is SSN (Social Security number), for STUDENT entity s_id
is a key attribute, for CAR entity type registration_no is key attribute.
In ER diagrammatic notation, each key attribute has its name underlined inside the oval.
In ER notation, if two attributes are underlined separately, then each is a key on its own.
Some entity types have more than one key attribute. For example, each of the Vehicle_id
and Registration attributes of the entity type CAR .
The Registration attribute is a composite key formed from two simple component
attributes, State and Number, neither of which is a key on its own.
Page 7
Database Management System
Page 8
Database Management System
Page 9
Database Management System
Relationship Degree
The Degree of a Relationship Type is the number of participating entity types.
3 different types of Degree of relationship
Unary Relationship
Binary Relationship
Ternary relationship
Unary Relationship: if number of participating entity type is only one then Its degree is
one. A relationship type of degree one is called Unary Relationship.
Each entity type that participates in a relationship type plays a particular role in the
relationship. The role name signifies the role that a participating entity from the entity
type plays in each relationship instance
For example, in the WORKS_FOR relationship type, EMPLOYEE plays the role of
employee or worker and DEPARTMENT plays the role of department or employer.
In some cases the same entity type participates more than once in a relationship type
in different roles. In such cases the role name becomes essential for distinguishing the
meaning of the role that each participating entity plays. Such relationship types are
called recursive relationships.
Example: The SUPERVISION relationship type relates an employee to a supervisor,
where both employee and supervisor entities are members of the same EMPLOYEE
entity set. Hence, the EMPLOYEE entity type participates twice in SUPERVISION:
once in the role of supervisor (or boss), and once in the role of supervisee (or
subordinate). In Figure 7.11, the lines marked ‘1’ represent the supervisor role, and
those marked ‘2’ represent the supervisee role.
Page 10
Database Management System
Binary Relationship: if number of participating entity type is two then Its degree is
two. A relationship type of degree two is called Binary Relationship.
Example: the WORKS_FOR relationship type is of degree two since two entity types
EMPLOYEE and DEPARTMENT participate.
Ternary relationship : if number of participating entity type is three then Its degree is
three. A relationship type of degree three is called Ternary relationship
Example of a ternary relationship is SUPPLY, shown in Figure in below 7.10, where
each relationship instance ri associates three entities—a supplier s, a part p, and a
project j, whenever s supplies part p to project j.
Page 11
Database Management System
Page 12
Database Management System
The relationship type WORKS_ON shown in below Figure 7.13 is of cardinality ratio
M:N, because the rule is that an employee can work on several projects and a project can
have several employees.
Consider a relationship type WORKS_FOR is of cardinality ratio N:1, because the rule is
that an many employees can work for same department and a department can have
several employees.
Page 13
Database Management System
Page 14
Database Management System
A weak entity type always has a total participation constraint (existence dependency)
with respect to its identifying relationship because a weak entity cannot be identified
without an owner entity.
Example: entity type DEPENDENT, related to EMPLOYEE, which is used to
keep track of the dependents of each employee via a 1:N relationship (Figure 7.2).
DEPENDENT is the weak entity type, EMPLOYEE is the owner Entity type and
DEPENDENTS of is the identifying relationship.
A weak entity type normally has a partial key, which is the attribute that can uniquely
identify weak entities that are related to the same owner entity.
Example: if we assume that no two dependents of the same employee ever have
the same first name, the attribute Name of DEPENDENT is the partial key.
Page 15
Database Management System
Another example, to record the number of hours per week that an employee works on a
particular project, we can include an attribute Hours for the WORKS_ON relationship
type. Another example is to include the date on which a manager started managing a
department via an attribute Start_date for the MANAGES relationship type.
Keys
Any attribute in the table which uniquely identifies each record in the table is called
key. It can be a single attribute or a combination of attributes.
For example, in STUDENT table, STUDENT_ID is a key, since it is unique for each
student.
In PERSON table, his passport number, driving license number, phone number, SSN, email
address is keys since they are unique for each person.
In real world applications, number of tables required for storing the data is huge, and the
different tables are related to each other as well.
Page 16
Database Management System
Also, tables store a lot of data in them. Tables generally extends to thousands of records stored
in them, unsorted and unorganized.
Now to fetch any particular record from such dataset, you will have to apply some conditions,
but what if there is duplicate data present and every time you try to fetch some data by
applying certain condition, you get the wrong data.
How many trials before you get the right data? To avoid all this, Keys are defined to easily
identify any row of data in a table.
PRIMARY KEY
It is the first and foremost key which is used to uniquely identify a record.
It can be a single attribute or a combination of attributes. For an entity, there could be
multiple keys as we saw in PERSON table.
Most suitable key from those lists becomes a primary key.
In the Person table above, we can select SSN as primary key, since it is unique for each
person.
We can even select Passport Number or license number as primary key as they are also
unique for a person.
However, selection of primary key for each entity is based on requirement and
developer.
For a student, STUDENT_ID is a primary key and for an employee EMPLOYEE_ID is a
primary key.
CANDIDATE KEY
The minimal set of attribute which can uniquely identify a tuple is known as candidate key.
In the example, an employee is identified by his ID in his office. Apart from his ID, does he
have any other unique keys, so that he can be identified from others?
Yes, he has passport number, PAN number, SSN number (if applicable), driving license
Page 17
Database Management System
number, email address etc. These are also identifies specific person uniquely.
But we can choose any one of these unique attribute as primary key in the table. Rest of the
attributes, which holds as strong as primary key are considered as Candidate key/secondary
key.
In our example of employee table, EMPLOYEE_ID is best suited for primary key as its from
his own employer. Rest of the attributes like passport number, SSN, license Number etc are
considered as candidate key.
SUPER KEY
Super Key is defined as a set of attributes within a table that can uniquely identify each record
within a table. Super Key is a superset of Candidate key.
In the table super key would include student_id, (student_id, name), phone etc.The student_id
is unique for every row of data, hence it can be used to identity each row uniquely.
Next comes, (student_id, name), now name of two students can be same, but their
student_id can't be same hence this combination can also be a key.
Similarly, phone number for every student will be unique, hence again, phone can also be a
key. So they all are super keys.
Page 18
Database Management System
FOREIGN KEY
In a company there would be different departments - Accounting, Human Resource (HR),
development, Quality, etc.
An employee, who works for that company, works in specific department. But we know
that employee and department are two different entities.
So we cannot store his department information in employee table. Instead what we do is we
link these two tables by means of primary key of one of the table i.e.;
In this case, we pick the primary key of department table - DEPARTMENT_ID and add it
as a new attribute/column in the Employee table.
Now DEPARTMENT_ID is a foreign key for Employee table, and both the tables are
related!
FEATURES OF ER-MODEL
1. KEY CONSTRAINTS
Let’s consider relationship set called Manages between the Employees and Departments
entity sets such that each department has at most one manager, although a single employee
is allowed to manage more than one department.
The restriction that each department has at most one manager is an example of a key
constraint, and it implies that each Departments entity appears in at most one Manages
relationship in any allowable instance of Manages.
This restriction is indicated in the ER diagram of Figure below by using an arrow from
Departments to Manages. Intuitively, the arrow states that given a Departments entity, we
can uniquely determine the Manages relationship in which it appears.
Page 19
Database Management System
3. PARTICIPATION CONSTRAINTS:
The key constraint on Manages tells us that a department has at most one manager. A natural
question to ask is whether every department has a Manager.
Let us say that every department is required to have a manager. This requirement is an example
of a participation constraint.
The participation of the entity set Departments in the relationship set Manages is said to be total.
A participation that is not total is said to be partial.
As an example, the participation of the entity set Employees in Manages is partial, since not
every employee gets to manage a department.
Page 20
Database Management System
4. WEAK ENTITIES:
A weak entity can be identified uniquely only by considering some of its attributes in conjunction
with the primary key of another entity, which is called the identifying owner.
The following restrictions must hold:
The owner entity set and the weak entity set must participate in a one -to-many relationship
set (one owner entity is associated with one or more weak entities, but each weak entity has a
single owner). This relationship set is called the identifying relationship set of the weak
entity set.
The weak entity set must have total participation in the identifying relationship set.
Page 21
Database Management System
6. AGGREGATION:
Page 22
Database Management System
Page 23
Database Management System
Page 24
Database Management System
partial, after consultation with the users indicates that some departments may control no
projects.
SUPERVISION, a 1:N relationship type between EMPLOYEE (in the supervisor role)
and EMPLOYEE (in the supervisee role). Both participations are determined to be
partial, after the users indicate that not every employee is a supervisor and not every
employee has a supervisor.
WORKS_ON, determined to be an M:N relationship type with attribute Hours, after the
users indicate that a project can have several employees working on it. Both
participations are determined to be total.
DEPENDENTS_OF, a 1:N relationship type between EMPLOYEE and DEPENDENT,
which is also the identifying relationship for the weak entity DEPENDENT is total.
Page 25
Database Management System
Page 26
Database Management System
LIBRARY ER DIAGRAM
Page 27