DBMS Unit-1
DBMS Unit-1
G. Sunil Reddy
Assistant Professor
Email : [email protected]
2
Course
DATABASE MANAGEMENT SYSTEMS
(22CS104)
3
DATABASE MANAGEMENT SYSTEMS
Credits 4
4
Course Specific Learning Outcomes (CO)
At the end of the course, You will be able to
● CO1: Understand the principles and concepts of the design, modeling of database
Systems
● CO2: To gain proficiency in handling the data management using SQL
● CO3: Analyze to design consistent structures of database
● CO4: Become familiar with the issues of concurrency control and transaction
processing
● CO5: Gain an insight into latest database technologies and trends
5
Course format/policies
• Lectures will be interactive
• You will be called on randomly to answer questions
• Lecture notes will be shared at the end of the unit
• Simple quiz assessments will be done at regular intervals
• On Learning Management Systems will host lecture notes, quiz answers,
homework, and general announcements
6
Attendance Policy
● At least 75% attendance in the course is mandatory
● A maximum of 5% shall be allowed under medical grounds
and 5% on representing the University on official events
outside like sports, hackathons, NCC, NSS etc
● Students with less than 65% of attendance shall be prevented
from writing the final assessment
7
Text and Reference Books
Text Books:
● “Data base Management Systems”, Raghurama Krishnan, Johannes Gehrke,
TATA McGraw-Hill 3rd Edition 2022
● “Data base System Concepts”, Silberschatz, Korth, McGraw hill, Sixth Edition
● “MongoDB: The Definitive Guide” by Kristina Chodorow and Shannon
Bradshaw 2019
Reference Books:
● “Fundamentals of Database Systems”, Elmasri Navathe Pearson Education
● “An Introduction to Database systems”, C. J. Date, A. Kannan, S. Swami Nadhan,
Pearson, Eight Edition
8
Assessment
Components of Course Evaluation Marks
Mid Term Examination 20
End Term Examination 40
Continuous Lab Evaluation 10
Lab Exam 10
Quiz 10
Certification 10
9
Unit-1
10
Syllabus:
● Data base System Applications, Purpose of Database Systems, View of Data –
Data Abstraction, Instances and Schemas – data Models – the ER Model –
Relational Model – Other Models
● Database Languages – DDL – DML – database Access for applications Programs –
data base Users and Administrator – Transaction Management – data base
Architecture – Storage Manager – the Query Processor
● Data base design and ER diagrams – ER Model - Entities, Attributes and Entity
sets Relationships and Relationship sets – ER Design Issues – Concept Design –
Conceptual Design for University Enterprise 11
Data
● A data mean known facts or raw facts that can be recorded and that have implicit
meaning
● Word ‘Data’ is originated from the word ‘datum’ that means ‘single piece of
information’
● In computing, Data is information that can be translated into a form for efficient
movement and processing
● Data is interchangeable
● For example − Employee name, Product name, Name of the student, Marks of the
student, Mobile number, Image etc 12
Information
● Information is the data that has been converted into more useful or intelligent
form
● For example: Report card sheet
● The information is needed for the following reasons −
13
Knowledge
● The human mind purposefully organizes the information and evaluates it to
produce knowledge.
● Example of data, information and knowledge:
A student secures 450 marks. Here 450 is data, marks of the student is
the information and hard work required to get the marks is knowledge
14
Database
● Database is a large collection of related data that can be stored generally
15
Cont…
● A database is an organized collection of data, so that it can be easily accessed and
managed
● You can organize data into tables, rows, columns, and index it to make it easier to
find relevant information
● The main purpose of the database is to operate a large amount of information by
storing, retrieving, and managing data
● There are many databases available like MySQL, Sybase, Oracle, MongoDB,
Informix, SQL Server, etc.
● Modern databases are managed by the database management system (DBMS)
16
17
Database Properties
● It is used to store data of an organization
● A database is designed and developed for a specific purpose
● It has some source from which data is derived and it is populated with that data
● It can be of any size
● It allows multiple users to share and access database at the same time
Eg: - University database which includes students, faculty, courses & class rooms
information along with activities such as enrolment and teaching courses
18
Database Management System
● A database management system (DBMS) is a collection of programs (software) for
defining, creating, manipulating and maintaining a database.
The DBMS is a general-
purpose software package that
facilitates the processes of
defining, constructing,
manipulating, and sharing
databases among various users
and applications. 19
Examples of popular DBMS
● MySql
● Oracle
● SQL Server
● IBM DB2
● Amazon SimpleDB (cloud based) etc
20
Actions of DBMS
● Defining a database involves specifying the data types, structures, and
constraints for the data to be stored in the database
● Manipulating a database
includes functions such
as querying the database
to retrieve specific data,
updating the database to
reflect changes, and
generating reports from
the data.
21
Actions of DBMS
● Constructing the database is the process of storing the data itself on some
22
Simplified database system environment
23
Database Applications
● Banking – For customer information, accounts, and loans, and banking
transactions
● Airlines – For reservation and schedule information, flight details etc
● Universities – For student and faculty information, course registrations, and
grades [registration, grades]
● Credit Card Transactions – For purchases on credit card and generation of
monthly statements
● Telecommunication – For keeping records of calls made, generating monthly
bills, maintaining balances on prepaid calling cards, and storing information
about communication networks
24
Database Applications
● Finance – For storing information about holdings, sales, and purchases of
financial instruments such as stocks and bonds
● Sales – For customer, product, and purchase information. [customers, products,
purchases]
● Manufacturing – For management of supply chain and for tracking
production of items in factories, inventories of items in warehouses/stores,
and orders for items. [production, inventory, orders, supply chain]
● Human Resources – For information about employees, salaries, payroll taxes and
benefits, and generation of paychecks. [employee records, salaries, tax
deductions]
25
File System
● Before the evolution of DBMS, File Systems are used to store and manage the
data
● In File System data will be stored in individual files
● A File is a collection of data
● Files are typically designed to meet needs of a particular department or user
group
26
File processing processing system
● In the file processing approach, each department would “own” a collection of
relevant data and software applications to manipulate that data.
27
Drawbacks of File System
1. Data Redundancy and Inconsistency
2. Difficulty in accessing data
3. Data isolation
4. Enforcing Integrity constraints
5. Atomicity problems
6. Difficulty in concurrency control
7. Security Problems
28
Data Redundancy and Inconsistency:
● Data redundancy means appearing same data in different places
● In file system same information is stored at different places it causes data-
inconsistency problems during updates
Difficulty in accessing data:
● In file system application programs are used to retrieve the data from the file
● In order to retrieve data from files we need to write special application program
every time
● This is not a convenient way because every time the requirements may change
need to write a new program to carry out each new task
29
Data isolation:
● The data is scattered in different files and with different formats in different
locations
● To retrieve the data from the files separate programs are required for each and
every format and location
● So it is difficult to write application programs to retrieve the data
30
Atomicity problems:
● Atomicity is a property of a transaction it states that either all actions to be
performed or none
● In file processing system incomplete transactions cannot be roll back
● Due to this data will be inconsistent
Difficulty in concurrency control:
● Concurrency means same file is accessed /updated by different application
programs at the same time
● In File Processing System it is not possible to control concurrency
Security Problems
● Since the information is scattered in different files and does not have centralized
access path, so it is not possible to provide security to the data so that everyone
can access the data
31
Advantages of DBMS
1. Controlling Redundancy
2. Data Consistency
3. Data Security
4. Providing Storage Structures for Efficient Query Processing
5. Providing Backup and Recovery
6. Providing concurrency control
7. Enforcing Integrity constraints
8. Report Writers
32
Different types of Database users
● Broadly, there are basically two types of Database
management systems (DBMS) users and we can also simply
say that database user
33
Actors on the Scene
34
DBA, Designers and End users - Actors of DBMS
35
Database Administrator(DBA)
● The database administrator is a person having central control over data
and programs accessing the data
● DBA coordinates all the activities of the database system
● They are the users who are most familiar with the database and are
responsible for creating, modifying, and maintaining the database
● DBA is responsible for granting permission to the users of the database
and stores the profile of each user in the database
36
Responsibilities of DBA
1. Installing and upgrading the database server and application tools
2. Allocating system storage and planning future storage
requirements for the database system
3. Modifying the database structure, as necessary, from information
given by application developers
4. Enrolling users and maintaining system security
5. Controlling and monitoring user access to the database
37
Responsibilities of DBA
6. Monitoring and optimizing the performance of the database
7. Planning for backup and recovery of database information and
restoring databases
8. Maintaining archived data
9. Contacting database vendor for technical support
10. Generating various reports by querying from database as per need
38
Database Designers
● Database designers are responsible for identifying the data to be
stored in the database and for choosing appropriate structures to
represent and store this data
● It is the responsibility of database designers to communicate with
all prospective database users in order to understand their
requirements, and to come up with a design that meets these
requirements
39
End Users
● End users are the people whose jobs require access to the database
for querying, updating, and generating reports
● There are several categories of end users:
○ Casual end users
○ Naive or parametric end users
○ Sophisticated end users
○ Stand-alone users
40
Casual end users
● Casual end users occasionally access the database, but they
may need different information each time
● Casual users uses query language to interact with the
database
● These are typically middle- or high-level managers
41
Naive or parametric end users
● These are also called unsophisticated users
● Naive users make up a sizable portion of database end users
● These users uses Application programs to interact with the
database
● Bank tellers check account balances and post withdrawals and
deposits
● Reservation clerks for airlines, hotels, and car rental companies
check availability for a given request and make reservations
42
Sophisticated end users & Stand-alone users
● Sophisticated end users include engineers, scientists, business
analysts, and others who thoroughly familiarize themselves with
the facilities of the DBMS so as to implement their applications to
meet their complex requirements
● Stand-alone users maintain personal databases by using ready-
made program packages that provide easy-to-use menu-based or
graphics-based interfaces. For example- User of a Tax package that
stores a variety of personal financial data for tax purpose
43
System Analyst and application program developers
(Software Engineers)
● System analysts determine the requirements of end-user
● Application programmers implement these specifications as programs, then they
test, debug, document, and maintain these canned transactions
● Such analysts and programmers commonly referred to as software developers or
software engineers
● A system analyst has also known as a business technology analyst
● The application programmer uses the specifications provided by the system
analyst to construct the software that is used by end users
Example: They serve as team leader, they are responsible for managing projects,
they are the supervisor who manages the lower level information staff
44
Workers behind the Scene
45
Cont...
DBMS system designers and implementers
● DBMS system designers and implementers design and
implement the DBMS modules and interfaces as a software
package
Tool developers
● Tool developers design and implement tools - the software
packages that facilitate database modeling and design,
database system design, and improved performance
46
Cont...
Operators and maintenance personnel:
● (System administration personnel) are responsible for the
actual running and maintenance of the hardware and
software environment for the database system.
Although these categories of workers behind the scene are
instrumental in making the database system available to end
users, they typically do not use the database contents for their
own purposes
47
View of Data
● A database system is a collection of interrelated data and a
set of programs that allow users to access and modify these
data. A major purpose of a database system is to provide
users with an abstract view of the data
● That is, the system hides certain details of how the data are
stored and maintained
48
Data Abstraction
● For the system to be usable, it must retrieve data efficiently.
The need for efficiency has led designers to use complex data
structures to represent data in the database
● Since many database-system users are not computer trained,
developers hide the complexity from users through several
levels of abstraction, to simplify users’ interactions with the
system:
49
Levels of Abstraction or Three-Schema architecture:
50
51
Internal level or internal schema:
● The internal schema uses a physical data model that describes
the complete details of physical data storage and access
strategies
● It tells us what data is stored in the database and how
● Physical Storage structures includes B-trees, B+ tree and hash
tables etc
● Some of the access strategies are primary index, single-level
index and multilevel index
52
Conceptual level or conceptual schema
● The conceptual level has a conceptual schema, which describes the
structure of the whole database
● The conceptual schema hides the details of physical storage
structures and concentrates on describing entities, data types,
relationships, user operations, and constraints
● Usually, a representational data model is used to describe the
conceptual schema when a database system is implemented
53
External level or External View:
● The external or view level includes a number of user views
● The external level is the view that the individual user of the
database has
● Each external schema describes the part of the database that
a particular user group is interested in and hides the rest of
the database from that user group
54
Schemas, Instances, and Database State
● Database Schema refers to the overall structure of a database
● The description of a database is called the database schema, which is specified
during database design and is not expected to change frequently
Schema Diagram:
Student
Course
Teacher
55
Instance:
● The data in the database at a particular moment in time is called instance or
database state
● The distinction between database schema and database state is very important
Database state:
● At any point in time, the database has a current state
56
Data Independence
57
Physical data independence:
● Physical data independence is the capacity to change the internal
schema without having to change the conceptual schema
● Hence, the external schemas need not be changed as well
● Changes to the internal schema may be needed because some
physical files had to be reorganized-for example, by creating
additional access structures-to improve the performance of
retrieval or update
58
Logical data independence:
● Logical data independence is the capacity to change the conceptual
schema without having to change external schema or application
programs
● We may change the conceptual schema to expand the database (by
adding a record type or data item), to change constraints, or to
reduce the database (by removing a record type or data item)
59
Data Models
60
Data Models
● Data model specifies how data is organized in database
● A data model is a collection of concepts that can be used to describe the structure
of a database
● Structure of a database mean the data types, relationships, and constraints
Types of Data Models
● Hierarchical Model
● Network Model
● Entity-Relationship Model
● Relational Model
● Object-Oriented Model
● Object Relational Model ( Features of relational + OO Models)
61
Hierarchical Model
● This database model organizes data into a tree-like-structure, with a single root, to
which all the other data is linked
● The hierarchy starts from the Root data, and expands like a tree, adding child
nodes to the parent nodes
● In this model, a child node will only have a single parent node
● This model efficiently describes many real-world relationships like index of a
book, recipes etc
● In hierarchical model, data is organized into tree-like structure with one one-to-
many relationship between two different types of data, for example, one
department can have many courses, many professors and of-course many students
62
63
Network Model
● This model is an extension of the hierarchical model
● It was the most popular model before the relational model
● This model is the same as the hierarchical model, the only difference
is that a record can have more than one parent
● It replaces the hierarchical tree with a graph
Example: In the example below, we can see that node student has two
parents i.e. CSE Department and Library. This was earlier not possible
in the hierarchical model
64
65
Entity-Relationship Model
● It is used to design database
● Entity-Relationship model is based on the notion of real
world entities and relationship among them
● It is a diagrammatic representation of database
● ER Model is based on:
○ Entities and their attributes
○ Relationships among entities
66
Entity
● An entity in ER Model is real world entity, which has some
properties called attributes
● It is a real world thing about which we want to maintain a data
● For example, in a school database, a student is considered as an
entity
● Student has various attributes like name, age and class etc
67
Relational Model
● Most commonly used model is the relational model
● In this model data is organized as two-dimensional tables
● The relational model uses a collection of tables to represent both data and the
relationships among those data
● Each table has multiple columns, and each column has a unique name
● Each table is called relation
● Each row is called tuple
68
Object-Based Data Model
● The real-world problems are more closely represented
through the object-oriented data model
● In this model, both the data and relationship are present in a
single structure known as an object
● We can store audio, video, images, etc in the database which
was not possible in the relational
● In this model, two are more objects are connected through
links
69
• In the above example, we have two objects Employee and Department
• All the data and relationships of each object are contained as a single unit
• The attributes like Name, Job_title of the employee and the methods which will
be performed by that object are stored as a single object
• The two objects are connected through a common attribute i.e the
Department_id and the communication between these two will be done with the
help of this common id 70
DBMS architecture
The Functional components of a database system can be divided in to
● Query Processor Components
● Storage Manager Components
71
Architecture
Diagram
72
Query Processor Components
The Query Processor Components include:
DDL interpreter:
● It interprets DDL statements and converts them in to a set tables which are saved
in the data dictionary
DML compiler:
● It translates DML statements into low-level instructions that are understood by
the Query Evaluation Engine
● It also optimizes the DML Queries for efficient execution by the Query
Evaluation Engine
Query evaluation engine:
● It executes low-level instructions generated by the DML compiler and produces
results 73
Storage Manager Components
● The storage manager components include:
File manager:
● It manages the allocation of disk-space for the storage of DBMS
files
Buffer manager:
● It is responsible for fetching data from disk storage into main
memory buffers for processing, and then writing the updated data
back onto the disk
74
Cont...
Authorization and integrity manager:
● It tests for the satisfaction of integrity constraints and checks the
authority of users to access data
Transaction manager:
● This component ensures that concurrent transactions proceed
without conflict and the database remains in a consistent (correct)
state despite system failures
75
Data Components
Data files:
● Which stores the database itself
Data dictionary:
● It is a metadata file, which stores the database schema. It stores metadata about
the structure of the database
Indices:
● It can provide fast access to data items. Like the index in this textbook, a database
index provides pointers to those data items that hold a particular value
Statistical data:
● It stores the statistical information about processing of previous queries
76
SQL Introduction
77
Database Languages - SQL
● SQL stands for “Structured Query Language” and can be pronounced as “SQL” or
“sequel – (Structured English Query Language)”
● It is a query language used for accessing and modifying information in the database
● IBM first developed SQL in 1970s
● Also it is an ANSI/ISO standard
● It has become a Standard Universal Language used by most of the relational
database management systems (RDBMS)
78
SQL
● Some of the RDBMS systems are: Oracle, Microsoft SQL server, Sybase etc
● Most of these have provided their own implementation thus enhancing it's feature
and making it a powerful tool
● Few of the SQL commands used in sql programming are SELECT Statement,
UPDATE Statement, INSERT INTO Statement, DELETE Statement, WHERE
Clause, ORDER BY Clause, GROUP BY Clause, ORDER Clause, Joins, Views,
GROUP Functions, Indexes etc
79
SQL
• In a simple manner, SQL is a non-procedural, English-like language that
processes data in groups of records rather than one record at a time. Few
functions of SQL are:
1. Store data
2. Modify data
3. Retrieve data
4. Delete data
5. Create tables and other database objects
6. Modify tables and other database objects
7. Describe tables and other database objects
8. Delete tables and other database objects
80
SQL Commands:
● SQL commands are instructions used to communicate with the
database to perform specific task that work with data
● SQL commands can be used not only for searching the database but
also to perform various other functions like, for example, you can
create tables, add data to tables, or modify data, drop the table, set
permissions for users. etc
81
Types of SQL Commands
82
Database Languages - SQL
SQL commands are grouped into four major categories depending on their
functionality
Data Definition Language (DDL):
○ These SQL commands are used for creating, modifying, and dropping the structure of
database objects
○ The commands are CREATE, ALTER, DROP, DESCRIBE, and TRUNCATE
83
Database Languages - SQL
Transaction Control Language (TCL)
○ These SQL commands are used for managing changes affecting the data
○ These commands are COMMIT, ROLLBACK, and SAVEPOINT
85
Data Definition Language Statements (DDL)
● Data Definition Language Statements (DDL) statements are used to
define the database structure or schema. Different types of DDL
commands are
1. Create
2. Drop
3. Alter
4. Truncate
5. Describe
86
Create:
Create command is used to create Databases, Tables, and Views etc
Syntax for Creating Databases:
CREATE DATABASE DatabaseName;
Example:
If you want to create new database, then CREATE DATABASE statement would
be as follows:
SQL> CREATE DATABASE university;
87
Create:
Syntax for Creating Table
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
);
88
Drop:
Drop command is used to drop the database or table. It is used to delete both the
structure and record stored in the table
Syntax for Dropping the Database:
DROP DATABASE DatabaseName;
Example:
If you want to delete an existing database testDB then DROP DATABASE
statement would be as follows:
SQL> DROP DATABASE testDB;
90
Truncate & Describe:
TRUNCATE: It is used to delete all the rows from the table and
free the space containing the table.
Syntax: TRUNCATE TABLE table_name;
Example: TRUNCATE TABLE EMPLOYEE;
92
Insert:
INSERT: The INSERT statement is a SQL query. It is used to insert data into the row
of a table.
Syntax:
INSERT INTO TABLE_NAME (col1, col2, col3,.... col N) VALUES (value1, value
2, value3, .... valueN);
Or
INSERT INTO TABLE_NAME VALUES (value1, value2, value3, .... valueN);
For example:
INSERT INTO javatpoint (Author, Subject) VALUES ("Sandy", "DBMS");
93
Update & Delete:
UPDATE: This command is used to update or modify the value of a column
in the table
Syntax:
UPDATE table_name SET [column_name1= value1,...column_nameN = value
N] [WHERE CONDITION]
For example: UPDATE students SET User_Name = 'Sandy' WHERE Student_Id = '3'
For example:
SELECT emp_name FROM employee WHERE age > 20;
95
Transaction Control Language Statements (TCL)
TCL commands can only be used with DML commands like INSERT, DELETE and
UPDATE only.
These operations are automatically committed in the database that's why they cannot
be used while creating tables or dropping them. The commands include:
● COMMIT
● ROLLBACK
● SAVEPOINT
a. Commit: Commit command is used to save all the transactions to the database
b. Rollback: Rollback command is used to undo transactions that have not already
been saved to the database
c. Savepoint: It is used to roll the transaction back to a certain point without rolling
back the entire transaction 96
Data Control Language Statements (DCL)
DCL commands are used to grant and take back authority from any
database user.
Here are some commands that come under DCL:
a. Grant
b. Revoke
97
Data base design and ER
diagrams
98
Entity-Relationship model
● Entity-Relationship model is a popular high, level conceptual data model
● ER Model is best used for the conceptual design of database
● The ER model describes data as entities, relationships, and attributes
● ER Model is based on: Entities and their attributes, Relationships among
entities
99
Entity:
● An entity, which is a “thing” in the real world with an independent
existence
● An entity may be an object with a physical existence
○ For example, a particular person, car, house, or employee
Entity
100
Attributes
● Attribute describes property or characteristics of an entity
● These are the properties of the entity
○ For example, an 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 attribute
Types of Attributes
1. Simple versus Composite Attribute
2. Single-valued versus Multi-valued
3. Stored versus Derived
101
Composite versus Simple (Atomic) Attributes
● Composite attributes can be divided into smaller subparts
● For example, the Address attribute of the employee entity can be subdivided into
Street Address, City, State, and Zip,3 with the values "2311 Kirby," "Houston,"
"Texas," and "77001."
● Attributes that are not divisible are called simple or atomic attributes
Ex: Zipcode
102
Single-Valued versus Multi-Valued Attributes
● Single-valued attribute is the attribute which is having only single value
○ Most attributes have a single value for a particular entity; such attributes are
called single-valued.
○ For example, Age, is a single-valued attribute of a person
● Multi-valued attribute is the attribute which is having more than one value
○ an attribute can have a set of values for the same entity-for example, a Colors attribute
for a car, or a phno attribute for a person
103
Stored versus Derived Attributes
● Derived attribute is one whose value can be calculated/derived from
the values of other attributes. The Age and BirthDate attributes of a
person
● For a particular person entity, the value of Age can be determined
from the current (today's) date and the value of that person's
BirthDate
● The Age attribute is hence called a derived attribute and is said to
be derivable from the BirthDate attribute, which is called a stored
attribute
104
Entity Types and Entity Sets
● 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
● A database usually contains groups of entities that are similar
● For 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
105
Entity Types and Entity Sets
● The collection of all entities of a particular entity type in the
database at any point in time is called an entity set.
● The entity set is usually referred to using the same name as the
entity type
● An entity type is represented in ER diagrams as a rectangular box
enclosing the entity type name
● An entity type describes the schema or intension for a set of entities
that share the same structure
106
Key Attributes of an Entity Type
● An important constraint on the entities of an entity type is the key
or uniqueness constraint on attributes
● An entity type usually has an attribute 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
● For the Employee entity type typical key attribute is Empid
107
Notations of ER Diagrams
108
109
Example Database Application: COMPANY
Example Database Application: COMPANY
● Initial Conceptual Design of COMPANY database
● The company is organized as a collection of departments
● Each department
○ has a unique name, has a unique number
○ is associated with a set of locations
○ has a particular employee who acts as its manager (and who assumed that
position on some date)
○ controls a set of projects
110
Cont ...
Each project
○ has a unique name
111
Cont ...
Each dependent
○ has first name
○ has a sex
○ has a birthdate
112
Cont ...
Each employee
○ has a name
○ has a SSN that uniquely identifies her/him
○ has an address, has a salary, has a sex, has a birthdate
○ has a direct supervisor, has a set of dependents
○ is assigned to one department
○ works some number of hours per week on each of a set of projects
(which need not all be controlled by the same department)
113
114
Relationship:
● It is Association among two or more entities
● When two or more entities are associated with each other, we have an
instance of a Relationship
● A relationship relates two or more distinct entities with a specific meaning
● It is represented by a diamond
● Relationships can have their own attributes
● Whenever an attribute of one entity type refers to an entity (of the same or
different entity type), we say that a relationship exists between the two
entity types
115
Relationship diagram:
116
Relationship Type
● Relationships of the same type are grouped or typed into a relationship
type
117
Relationship set
118
Degree of a Relationship Type
● The degree of a relationship is the number of participating entities
● It refers to number of entity sets that participate in a relationship set
● The degree of WORKS-FOR relationship is two
● A Relationship type of degree one is called unary, a Relationship type of degree
two is called binary, and a Relationship type of degree three is called ternary
● In ER diagrams, relationship types are displayed as diamond-shaped boxes, which
are connected by straight lines to the rectangular boxes representing the
participating entity types
119
Relationship Attributes
● A relationship type can have attributes describing properties
of a relationship
○ FOR EXAMPLE Sandy works for CSE Department since 2008
● Sometimes, relationships can have an attribute for itself, such
an attribute is called descriptive attribute
● WORKS-FOR relationship type have attributes like empid,
deptid and since
120
Constraints on Relationships
● Relationship types usually have certain constraints that limit
the possible combinations of entities that may participate in
the corresponding relationship set
● For example if the company has a rule that each employee
must work for exactly one department, then we would like to
describe this constraint in the schema
● Two main types of relationship constraints
1. Cardinality ratio
2. Participation 121
Cardinality Ratios for Binary Relationships
● The cardinality ratio for a binary relationship specifies the
maximum number of relationship instances that an entity
can participate in
● For example, in the WORKS_FOR binary relationship type,
DEPARTMENT: EMPLOYEE is of cardinality ratio l: N,
meaning that each department can be related to any number
of employees but an employee can be related to (work for)
only one department
122
Cardinality Ratios for Binary Relationships
For a binary relationship set the mapping cardinality must be
one of the following types:
○ One to One (1:1)
○ One to many (l:N)
○ Many to one (N:l)
○ Many to many (M:N)
● Consider binary relationship set R between entity sets A and
B
123
Cardinality ratios:
● One to One: An entity in A is associated with at most one entity in B, and an entity
in B is associated with at most one entity in A
● An example of a 1:1 binary relationship is MANAGES which relates a department
entity to the employee who manages that department. This represents the mini-
world constraints that at any point in time-an employee can manage only one
department and a department has only one manager
124
● One to Many: An entity in A is associated with many entities in B and an entity in
B is associated with at most one entity in A
● Many to One: An entity in A is associated with at most one entity in B, an entity
in B is associated with many entities in A
Ex: An employee works in a single department but a department consists of many
employees
125
● Many to Many: An entity in A is associated with many entities in B, and an entity
in B is associated with many entities in A
Ex: The relationship type WORKS_ON is of cardinality ratio M:N, because the
mini-world rule is that an employee can work on several projects and a project
can have several employees
126
127
Participation Constraints
● This constraint specifies the minimum number of
relationship instances that each entity can participate in, and
is sometimes called the minimum cardinality constraint.
● There are two types of participation constraints
1. Total participation
2. Partial participation
128
Total participation
● If a company policy states that every employee must work for a
department, then an employee entity can exist only if it
participates in at least one WORKS_FOR relationship instance\
● Thus, the participation of EMPLOYEE in WORKS_FOR is
called total participation, meaning that every entity in "the total
set" of employee entities must be related to a department entity
via WORKS_FOR. Total participation is also called existence
dependency
129
Partial participation:
● We do not expect every employee to manage a department,
so the participation of EMPLOYEE in the MANAGES
relationship type is partial, meaning that some or "part of the
set of" employee entities are related to some department
entity via MANAGES, but not necessarily all
130
Weak entity types
● Entity types that do not have key attributes of their own are called weak
entity types
● In contrast, regular entity types that do have a key attribute are also called
strong entity types
● Entities belonging to a weak entity type are identified by being related to
specific entities from another entity type in combination with one of their
attribute values
● 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
131
Company ER Diagram
● ER DIAGRAM – Relationship Types are: WORKS_FOR,
MANAGES, WORKS_ON, CONTROLS, SUPERVISION,
DEPENDENTS_OF
132
133
Example
● ER Diagram for the scenario of School Management System.
We have many entities like Parent, student, Admin, Teacher,
class and subjects
134
135