Module 1
Module 1
MODULE 1
Chapter 1:
Databases and Database Users
Databases and database systems have become an essential component of everyday life in modern
society. In the course of a day, most of us encounter several activities that involve some interaction
with a database. For example, if we go to the bank to deposit or withdraw funds; if we make a hotel or
airline reservation; if we access a computerized library catalog to search for a bibliographic item; or if
we order a magazine subscription from a publisher, chances are that our activities will involve
someone accessing a database. Even purchasing items from a supermarket nowadays in many cases
involves an automatic update of the database that keeps the inventory of supermarket items.
.IN
The above interactions are examples of what we may call traditional database applications, where
most of the information that is stored and accessed is either textual or numeric. In the past few years,
advances in technology have been leading to exciting new applications of database systems.
C
Multimedia databases can now store pictures, video clips, and sound messages. Geographic
information systems (GIS) can store and analyze maps, weather data, and satellite images. Data
N
warehouses and on-line analytical processing (OLAP) systems are used in many companies to extract
and analyze useful information from very large databases for decision making. Real-time and active
SY
database technology is used in controlling industrial and manufacturing processes. And database
search techniques are being applied to the World Wide Web to improve the search for information
that is needed by users browsing through the Internet.
U
1.1 Introduction
VT
Importance: Database systems have become an essential component of life in modern society, in that
many frequently occurring events trigger the accessing of at least one database: bibliographic library
searches, bank transactions, hotel/airline reservations, grocery store purchases, online (Web) purchases,
etc., etc.
Sahana M Page 1
.IN
some degree of interaction with events in the represented miniworld (at least insofar as the data
is updated when the state of the miniworld changes), and an audience that is interested in using
it.
C
An Aside: data vs. information vs. knowledge: Data is the representation of "facts" or "observations"
whereas information refers to the meaning thereof (according to some interpretation). Knowledge, on
N
the other hand, refers to the ability to use information to achieve intended ends.
SY
Computerized vs. manual: Not surprisingly (this being a CS course), our concern will be with
computerized database systems, as opposed to manual ones, such as the card catalog-based systems that
were used in libraries in ancient times (i.e., before the year 2000). (Some authors wouldn't even
U
Size/Complexity: Databases run the range from being small/simple (e.g., one person's recipe database)
to being huge/complex (e.g., Amazon's database that keeps track of all its products, customers, and
suppliers).
Sahana M Page 2
.IN
A database can be of any size and of varying complexity. For example, the list of names and
addresses referred to earlier may consist of only a few hundred records, each with a simple structure.
On the other hand, the card catalog of a large library may contain half a million cards stored under
C
different categories. A database may be generated and maintained manually or it may be
computerized.
N
A database management system (DBMS) is a collection of programs that enables users to create and
SY
maintain a database. The DBMS is hence a general-purpose software system that facilitates the
processes of defining, constructing, and manipulating databases for various applications. Defining a
database involves specifying the data types, structures, and constraints for the data to be stored in the
database. Constructing the database is the process of storing the data itself on some storage medium
U
that is controlled by the DBMS. Manipulating a database includes such functions as querying the
database to retrieve specific data, updating the database to reflect changes in the mini world, and
VT
In traditional file processing, data definition is typically part of the application programs
themselves. Hence, these programs are constrained to work with only one specific database, whose
structure is declared in the application programs. For example, a PASCAL program may have record
structures declared in it; a C++ program may have "struct" or "class" declarations; and a COBOL
program has Data Division statements to define its files. Whereas file-processing software can
access only specific databases, DBMS software can access diverse databases by extracting the
database definitions from the catalog and then using these definitions.
Sahana M Page 3
.IN
C
N
1.2 Example
SY
Let us consider an example that most readers may be familiar with: a UNIVERSITY
database for maintaining information concerning students, courses, and grades in a university
environment. Figure 01.02 shows the database structure and a few sample data for such a
U
database. The database is organized as five files, each of which stores data records of the same
type (Note 2). The STUDENT file stores data on each student; the COURSE file stores data on
VT
each course; the SECTION file stores data on each section of a course; the GRADE_REPORT
file stores the grades that students receive in the various sections they have completed; and the
PREREQUISITE file stores the prerequisites of each course.
Sahana M Page 4
.IN
C
N
SY
U
VT
Sahana M Page 5
.IN
For example, one user, the grade reporting office, may keep a file on students and their grades.
Programs to print a student’s transcript and to enter new grades into the file are implemented. A
second user, the accounting office, may keep track of students’ fees and their payments.
C
Although both users are interested in data about students, each user maintains separate files—and
programs to manipulate these files—because each requires some data not available from the
N
other user’s files. This redundancy in defining and storing data results in wasted storage space
and in redundant efforts to maintain common data up-to- date.
SY
The main characteristics of the database approach versus the file-processing approach are the following.
A fundamental characteristic of the database approach is that the database system contains not
VT
only the database itself but also a complete definition or description of the database structure and
constraints. This definition is stored in the system catalog, which contains information such as
the structure of each file, the type and storage format of each data item, and various constraints
on the data. The information stored in the catalog is called meta-data, and it describes the
structure of the primary database.
.IN
view of the database. A view may be a subset of the database or it may contain virtual data that
is derived from the database files but is not explicitly stored. Some users may not need to be
aware of whether the data they refer to is stored or derived.
C
Sharing of Data and Multiuser Transaction Processing
A multiuser DBMS, as its name implies, must allow multiple users to access the database
N
at the same time. This is essential if data for multiple applications is to be integrated and
maintained in a single database. The DBMS must include concurrency control software to
SY
ensure that several users trying to update the same data do so in a controlled manner so that the
result of the updates is correct. For example, when several reservation clerks try to assign a seat
on an airline flight, the DBMS should ensure that each seat can be accessed by only one clerk at
U
a time for assignment to a passenger. These types of applications are generally called on-line
transaction processing (OLTP) applications. A fundamental role of multiuser DBMS software
VT
Sahana M Page 7
Database Administrators
Database Designers
End Users
Database Administrators
.IN
In any organization where many persons use the same resources, there is a need for a
chief administrator to oversee and manage these resources. In a database environment, the
primary resource is the database itself and the secondary resource is the DBMS and related
C
software. Administering these resources is the responsibility of the database administrator
(DBA). The DBA is responsible for authorizing access to the database, for coordinating and
N
monitoring its use, and for acquiring software and hardware resources as needed.
SY
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
U
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.
VT
End Users
End users are the people whose jobs require access to the database for querying, updating,
and generating reports; the database primarily exists for their use. There are several categories of
end users:
• Casual end users occasionally access the database, but they may need different information
each time. They use a sophisticated database query language to specify their requests and
are typically middle- or high-level managers or other occasional browsers.
• Naive or parametric end users make up a sizable portion of database end users. Their
main job function revolves around constantly querying and updating the database, using
standard types of queries and updates—called canned transactions—that have been
carefully programmed and tested.
Bank tellers check account balances and post withdrawals and deposits.
Sahana M Page 8
• 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- or graphics-based interfaces. An example is the user of a
tax package that stores a variety of personal financial data for tax purposes.
System Analysts and Application Programmers (Software Engineers)
System analysts determine the requirements of end users, especially naive and
parametric end users, and develop specifications for canned transactions that meet these
requirements. Application programmers implement these specifications as programs; then
.IN
they test, debug, document, and maintain these canned transactions. Such analysts and
programmers (nowadays called software engineers) should be familiar with the full range
of capabilities provided by the DBMS to accomplish their tasks.
1.5 Workers behind the Scene C
N
In addition to those who design, use, and administer a database, others are associated with
the design, development, and operation of the DBMS software and system environment.
SY
These persons are typically not interested in the database itself. We call them the
"workers behind the scene," and they include the following categories.
DBMS system designers and implementers are persons who design and implement
the DBMS modules and interfaces as a software package. A DBMS is a complex
U
software system that consists of many components or modules, including modules for
VT
Sahana M Page 9
Controlling Redundancy
.IN
Providing Backup and Recovery
Controlling Redundancy
VT
In traditional software development utilizing file processing, every user group maintains
its own files for handling its data-processing applications. For example, consider the
UNIVERSITY database example two groups of users might be the course registration personnel
and the accounting office. In the traditional approach, each group independently keeps files on
students. The accounting office also keeps data on registration and related billing information,
whereas the registration office keeps track of student courses and grades. Much of the data is
stored twice: once in the files of each user group. Additional user groups may further duplicate
some or all of the same data in their own files.
This redundancy in storing the same data multiple times leads to several problems. First,
there is the need to perform a single logical update—such as entering data on a new student—
multiple times: once for each file where student data is recorded. This leads to duplication of
effort. Second, storage space is wasted when the same data is stored repeatedly, and this problem
may be serious for large databases. Third, files that represent the same data may become
inconsistent. This may happen because an update is applied to some of the files but not to others.
Sahana M Page 10
In the database approach, the views of different user groups are integrated during
database design. For consistency, we should have a database design that stores each logical data
item—such as a student’s name or birth date—in only one place in the database. This does not
permit inconsistency, and it saves storage space.
.IN
Typically, users or user groups are given account numbers protected by passwords, which they
can use to gain access to the database.
C
Providing Persistent Storage for Program Objects and Data Structures
Databases can be used to provide persistent storage for program objects and data
N
structures. This is one of the main reasons for the emergence of the object-oriented database
SY
systems. Programming languages typically have complex data structures, such as record types in
PASCAL or class definitions in C++. The values of program variables are discarded once a
program terminates.
U
The persistent storage of program objects and data structures is an important function of
database systems. Traditional database systems often suffered from the so-called impedance
VT
mismatch problem, since the data structures provided by the DBMS were incompatible with the
programming language’s data structures. Object- oriented database systems typically offer data
structure compatibility with one or more object-oriented programming languages.
.IN
For example we may specify that the value of the Class data item within each student
record must be an integer between 1 and 5 and that the value of Name must be a string of no
more than 30 alphabetic characters.
computer system fails in the middle of a complex update program, the recovery subsystem is
responsible for making sure that the database is restored to the state it was in before the program
started executing.
U
Sahana M Page 12
.IN
It was developed in the late 1970’s and the commercial RDBMS was introduced
in the early 1980’s.
Advantages
C
Introduction of high level query language made it easier to write new queries
and recognize database as required.
N
They did not use physical storage pointers and record placement to access
related data records.
SY
Performance greatly improved with the development of new storage and indexing.
Query processing became better.
U
3. Object-Oriented databases
In the 1980’s with the emergence of object oriented programming languages, it
was necessary to store and share complex structured objects. This led to the
development of object oriented databases. They are used in specialized
applications such as engineering design, multimedia publishing and
manufacturing systems.
Advantages
• It provided more general data structures.
•In incorporated many of the useful object oriented paradigms, such as
ADT(Abstract Data Types), encapsulation, inheritance etc..
4. Web based database applications
The World Wide Web is a large interconnection of a number of computer networks. User
can create web documents (using HTML ( Hyper Text Markup Language)) called web
pages and store them on web servers from where other web clients can access.
Sahana M Page 13
Large number of records of similar structure were stored and maintained in large
organization.
Drawback
There was intermixing a conceptual relationship with the physical storage
and placement of records on disk. Although for original queries and transaction data
access was efficient, it did not provide enough flexibility to access records
efficiently when new queries and transactions were identified.
.IN
When changes were made to the requirements of the application, it was
difficult to reorganize the database.
These systems only provide programming language interfaces.
C
Implementing new queries and transactions was time-consuming and expensive.
N
SY
U
VT
Sahana M Page 14
Chapter 2
OVERVIEW OF DATABASE LANGUAGES AND ARCHITECTURES
2.1 Data Models, Schemas, and Instances
One fundamental characteristic of the database approach is that it provides some level of data
abstraction.
Data abstraction generally refers to the suppression of details of data organization and storage, and
the highlighting of the essential features for an improved understanding of data.
.IN
One of the main characteristics of the database approach is to support data abstraction so that different
users can perceive data at their preferred level of detail.
A data model—a collection of concepts that can be used to describe the structure of a database—
C
provides the necessary means to achieve this abstraction
N
By structure of a database means the data types, relationships, and constraints that apply to the data.
Most data models also include a set of basic operations for specifying retrievals and updates on the
SY
database.
-provide concepts that are close to the way many users perceive data
VT
- provide concepts that describe the details of how data is stored on the computer storage media,
typically magnetic disks.
- Concepts provided by low-level data models are generally meant for computer specialists, not for
end users
Sahana M Page 15
- provide concepts that may be easily understood by end users but that are not too far removed from the
way data is organized in computer storage
-in between high level and low level
- hide many details of data storage on disk but can be implemented on a computer system directly
Schemas
The description of a database is called the database schema, which is specified during database design
and is not expected to change frequently.
A displayed schema is called a schema diagram
Object in the schema—such as STUDENT or COURSE—a schema construct
.IN
A schema diagram displays only some aspects of a schema, such as the names of record types and data
items, and some types of constraints.
The actual data in a database may change quite frequently. Changes every time we add a new student or
enter a new grade.
C
The data in the database at a particular moment in time is called a database state or SNAPSHOT. It is
also called the current set of occurrences or instances in the database.. In a given database state, each
N
schema construct has its own current set of instances; for example, the STUDENT construct will
SY
Sahana M Page 16
When we define a new database, we specify its database schema only to the DBMS. At this point, the
corresponding database state is the empty state with no data.
We get the initial state of the database when the database is first populated or loaded with the initial
data. From then on, every time an update operation is applied to the database, we get another database
state.
At any point in time, the database has a current state.
The DBMS is partly responsible for ensuring that every state of the database is a valid state—that is, a
state that satisfies the structure and constraints specified in the schema.
The DBMS stores the descriptions of the schema constructs and constraints—also called the meta-
data—in the DBMS catalog.
The schema is sometimes called the INTENSION, and a database state is called an EXTENSIONof the
.IN
schema.
Application requirements change occasionally, which is one of the reasons why software maintenance
is important. On such occasions, a change to a database's schema may be called for. An example would
C
be to add a Date_of_Birth field/attribute to the STUDENT table. Making changes to a database schema
is known as SCHEMA EVOLUTION. Most modern DBMS's support schema evolution operations that
N
can be applied while a database is operational.
SY
database.
VT
Sahana M Page 17
.IN
implemented
This implementation conceptual schema is often based on a conceptual schema design in a high-
level data model.
C
3. The external or view level includes a number of external schemas or user views,
Describes the part of the database that a particular user group is interested in and hides the rest
N
of the database from that user group.
As in the previous level, each external schema is typically implemented using a representational
SY
data model, possibly based on an external schema design in a high-level data model.
The DBMS must transform a request specified on an external schema into a request against the
conceptual schema, and then into a request on the internal schema for processing over the stored
U
database. If the request is database retrieval, the data extracted from the stored database must be
reformatted to match the user’s external view. The processes of transforming requests and results
VT
between levels are called mappings. These mappings may be time-consuming, so some DBMSs—
especially those that are meant to support small databases—do not support external views.
Even in such systems, however, a certain amount of mapping is necessary to transform requests
between the conceptual and internal levels.
Data Independence
Data independence, which can be defined as the capacity to change the schema at one level of a
database system without having to change the schema at the next higher level.
We can define two types of data independence:
1. Logical data independence
capacity to change the conceptual schema without having to change external schemas or
application programs
change the conceptual schema to expand the database, to change constraints, or to reduce the
database
Sahana M Page 18
DBMS packages provide an integrated feature of above languages into a single language called
Structured Query Language.
.IN
Data definition language (DDL), is used by the DBA and by database designers to define both
schemas.
Storage definition language (SDL), is used to specify the internal schema.
C
View definition language (VDL), to specify user views and their mappings to the conceptual schema.
Data manipulation language (DML) provides set of operations like retrieval, insertion, deletion, and
N
modification of the data.
SY
high-level DML statements either to be entered interactively from a display monitor or terminal or to be
embedded in a general-purpose programming language.
VT
can specify and retrieve many records in a single DML statement; therefore, they are called set-at-a-time
or set- oriented DMLs
Whenever DML commands, whether high level or low level, are embedded in a general-purpose
programming language, that language is called the host language and the DML is called the data
sublanguage. A high-level DML used in a standalone interactive manner is called a query language.
Sahana M Page 19
.IN
or result. The speech input is detected using a library of predefined words and used to set up the
parameters that are supplied to the queries.
Interfaces for Parametric Users such as bank tellers, often have a small set of operations that they
must perform repeatedly.
C
Interfaces for the DBA. DBA use privileged commands. These include commands for creating
N
accounts, setting system parameters, granting account authorization, changing a schema, and
reorganizing the storage structures of a database.
SY
The top part of the figure refers to the various users of the database environment and their [Link]
lower part shows the internals of the DBMS responsible for storage of data and processing of
VT
[Link] database and the DBMS catalog are usually stored on disk. Access to the disk is
controlled primarily by the operating system (OS), which schedules disk read/write.
Many DBMSs have their own buffer management module to schedule disk read/[Link] data
manager controls access to DBMS information that is stored on disk, whether it is part of the database or
the catalog.
Top half figure:
it shows interfaces for the DBA staff, casual users who work with interactive interfaces to
formulate queries
application programmers who create programs using some host programming languages
parametric users who do data entry work by supplying parameters to predefined transactions.
the DBA staff works on defining the database and tuning it by making changes to its definition
using the DDL and other privileged commands
Sahana M Page 20
.IN
C
N
SY
DBA staff:
U
The DDL compiler processes schema definitions, specified in the DDL, and stores descriptions
of the schemas (meta-data) in the DBMS catalog
VT
The catalog includes information such as the names and sizes of files, names and data types of
data items, storage details of each file, mapping information among schemas, and constraints
Casual users:
interact using some form of interface, which we call the interactive query interface
queries are parsed and validated for correctness of the query syntax, the names of files anddata
elements, and so on by a query compiler that compiles them into an internal form
This internal query is subjected to query optimization
query optimizer is concerned with the rearrangement and possible reordering of operations,
elimination of redundancies, and use of correct algorithms and indexes during execution.
It consults the system catalog for statistical and other physical information about the stored
data and generates executable code that performs the necessary operations for the query and
makes calls on the runtime processor
Application programmers
write programs in host languages such as Java, C, or C++ that are submitted to a precompiler
pre compiler extracts DML commands from an application program
Sahana M Page 21
.IN
It also works with the stored data manager, which in turn uses basic operating system services
for carrying out low-level input/output (read/write) operations between the disk and main
memory
The runtime database processor handles other aspects of data transfer, such as management of
C
buffers concurrency control and backup and recovery systems, integrated into the working of the
N
runtime database processor for purposes of transaction management.
SY
1. Loading
used to load existing data files—such as text files or sequential files—into the database
VT
Sahana M Page 22
.IN
system site to access the database through computer terminals, workstations, or personal computers
6. These are connected to the database site through data communications hardware such as Internet
routers, phone lines, long-haul networks, local networks, or satellite communication devices
7. The integrated DBMS and data communications system is called a DB/DC system
C
N
2.5 Centralized and Client/Server Architectures for DBMSs
SY
Sahana M Page 23
.IN
C
N
SY
The client/server architecture was developed to deal with computing environments in which a large
number of PCs, workstations, file servers, printers, database servers, Web servers, e-mail servers, and
other software and equipment are connected via a network.
The idea is to define specialized servers with specific functionalities
U
it is possible to connect a number of PCs or small workstations as clients to a file server that
maintains the files of the client machines
VT
Another machine can be designated as a printer server by being connected to various printers; all
print requests by the clients are forwarded to this machine
Web servers or e-mail servers also fall into the specialized server category. The resources
provided by specialized servers can be accessed by many client machines
The client machines provide the user with the appropriate interfaces to utilize these servers, as
well as with local processing power to run local applications.
This concept can be carried over to other software packages, with specialized programs—such as a CAD
(computer-aided design) package
Some machines would be client sites only, other machines would be dedicated servers, and
others would have both client and server functionality
The concept of client/server architecture assumes an underlying framework that consists of many
PCs and workstations as well as a smaller number of mainframe machines, connected via LANs
and other types of computer networks
Sahana M Page 24
.IN
SQL provided a standard language for RDBMSs, this created a logical dividing point between
client and server
hence, the query and transaction functionality related to SQL processing remained on the server
side
C
in such an architecture, the server is often called a query server or transaction server
N
SY
U
VT
Sahana M Page 25
.IN
The advantages of this architecture:
simplicity and seamless compatibility with existing systems
C
5. Three-Tier and n-Tier Architectures for Web Applications
N
SY
U
VT
Many Web applications use an architecture called the three-tier architecture, which adds an
intermediate layer between the client and the database server
This intermediate layer or middle tier is called the application server or the Web server, depending
on the application
This server plays an intermediary role by running application programs and storing business
rules (procedures or constraints) that are used to access data from the database server. It can also
improve database security by checking a client’s credentials before forwarding a request to the
database server
Clients contain GUI interfaces and some additional application-specific business rules
Sahana M Page 26
.IN
2.6 Classification of Database Management Systems
1. Data Model
Used in commercial DBMS [eg: relational data model, object data model]
C
Many legacy applications still run on database systems based on the hierarchical and
network data models
N
2. Number of users
Single-user systems support only one user at a time and are mostly used with PCs
SY
Multiuser systems, which include the majority of DBMSs, support concurrent multiple
users
3. Number of sites
Centralized DBMS : the data is stored at a single computer site
U
Sahana M Page 27
.IN
C
N
SY
U
VT
Sahana M Page 28
.IN
3.2 An example Database Application
The COMPANY database keeps track of a company’s employees, departments, and projects.
C
The company is organized into departments. Each department has a unique name, a unique number,
N
and a particular employee who manages the department. We keep track of the start date when that
employee began managing the department. A department may have several locations.
SY
A department controls a number of projects, each of which has a unique name, a unique number,
and a single location.
The database will store each employee’s name, Social Security number,address, salary, sex
U
(gender), and birth date. An employee is assigned to one department, but may work on several projects,
which are not necessarily controlled by the same department. It is required to keep track of the current
VT
number of hours per week that an employee works on each project, as well as the direct supervisor of
each employee (who is another employee).
The database will keep track of the dependents of each employee for insurance purposes, including
each dependent’s first name, sex, birth date, and relationship to the employee.
Sahana M Page 29
.IN
C
N
SY
U
VT
Entity, which is a thing or object in the real world with an independent existence.
An entity may be an
1. object with a physical existence (for example, a particular person, car, house, or employee) or
2. object with a conceptual existence (for instance, a company, a job, or a university course)
Each entity has attributes—the particular properties that describe it. For example, an EMPLOYEE
entity may be described by the employee’s name, age, address, salary, and job
Sahana M Page 30
.IN
The EMPLOYEE entity e1 has four attributes: Name, Address, Age, and Home_phone; their
values are ‘John Smith,’ ‘2311 Kirby, Houston, Texas 77001’, ‘55’, and ‘713-749-2630’,
respectively.
C
The COMPANY entity c1 has three attributes: Name, Headquarters, and President; their values
are ‘Sunco Oil’, ‘Houston’, and ‘John Smith’, respectively.
N
Types of attributes occur in the ER model
SY
Attributes that are not divisible are called simple or atomic attributes.
For eg: attribute Age cannot be divided
Sahana M Page 31
single-valued
Most attributes have a single value for a particular entity
For eg:Age is a single-valued attribute of a person
Multivalued
An entity having multiple values for that attribute For eg: color of a color color={black,red}
Person’s degree degree={BE, MTech, PhD}
.IN
The Age attribute is hence called a derived attribute
Birth_date attribute is called a stored attribute
NULL Values
C
In some cases, a particular entity may not have an applicable value for an attribute.
N
foreg, the Apartment_number attribute of an address applies only to addresses that are in
apartment buildings and not to other types of residences, such as single-family homes
SY
Complex Attributes
composite and multivalued attributes can be nested arbitrarily
U
Sahana M Page 32
.IN
C
N
SY
Fig: two entity types: EMPLOYEE and COMPANY, and a list of some of the attributes for each
The collection of all entities of a particular entity type in the database at any point in time is called
U
an entity set or entity collection entity set is usually referred to using the same name as the entity
type.
VT
Important constraint on the entities of an entity type is the key or uniqueness constraint on
attributes
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.
Sahana M Page 33
.IN
C
N
SY
U
VT
Sahana M Page 34
.IN
C
N
SY
U
VT
Whenever an attribute of one entity type refers to another entity type, some relationship exists for
example, the attribute Manager of DEPARTMENT refers to an employee who manages the
department, the attribute Controlling_department of PROJECT refers to the department that
controls the project in the ER model, these references should not be represented as attributes but as
relationships
Sahana M Page 35
A relationship type R among n entity types E1, E2, . . . , En defines a set of associations—or a
relationship set—among entities from these entity types
entity types and entity sets, a relationship type and its corresponding relationship set are
customarily referred to by the same name, R
Mathematically, the relationship set R is a set of relationship instances ri, where each ri associates
n individual entities (e1, e2, . . . , en), and each entity ej in ri is a member of entity set Ej , 1 ≤ j ≤ n
a relationship set is a mathematical relation on E1, E2, . . . , En; alternatively, it can be defined as a
subset of the Cartesian product of the entity sets E1 × E2 × . . . × En
each of the entity types E1, E2, . . . , En is said to participate in the relationship type R
each of the individual entities e1, e2, . . , en is said to participate in the relationship instanceri = (e1,
.IN
e2, . . , en)
consider a relationship type WORKS_FOR between the two entity types EMPLOYEE and
DEPARTMENT, which associates each employee with the department for which the employee
EMPLOYEE entity and one DEPARTMENT entity. C
works. Each relationship instance in the relationship set WORKS_FOR associates one
N
the employees e1, e3, and e6 work for department d1
the employees e2 and e4 work for department d2; and the employees e5 and e7 work for
SY
department d3
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. The relationship
name is displayed in the diamond-shaped box
U
VT
Sahana M Page 36
.IN
C
N
SY
U
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
same entity type participates more than once in a relationship type in different roles, such
relationship types are called recursive relationships
Sahana M Page 37
.IN
C
N
SY
U
In 1:1 an employee can manage at most one department and a department can have at most one
manager
VT
In M:Nan employee can work on several projects and a project can have several employees
Cardinality ratios for binary relationships are represented on ER diagrams by displaying 1, M, and N
Sahana M Page 38
The participation constraint specifies whether the existence of an entity depends on its being
related to another entity via the relationship type
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—total and partial
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
.IN
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.
we do not expect every employee to manage a department, so the participation of EMPLOYEE in
C
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
N
In ER diagrams, total participation (or existence dependency) is displayed as a double line
connecting the participating entity type to the relationship, whereas partial participation is
SY
Relationship types can also have attributes, similar to those of entity types.
For example, to record the number of hours per week that a particular employee works on a
VT
particular project, we can include an attribute Hours for the WORKS_ON relationship type
to include the date on which a manager started managing a department via an attribute Start_date
for the MANAGES relationship type
Sahana M Page 39
choose names that convey the meanings attached to the different constructs in the schema
use singular names for entity types, rather than plural ones
use the convention that entity type and relationship type names are in uppercase letters, attribute
names have their initial letter capitalized, and role names are in lowercase letters
.IN
nouns appearing in the narrative tend to give rise to entity type names, and the verbs tend to
indicate names of relationship types
choosing binary relationship names to make the ER diagram of the schema readable from left to
right and from top to bottom
C
N
3.7.2 Design Choices for ER Conceptual Design
SY
Schema design process should be considered an iterative refinement process, where an initial design is
created and then iteratively refined until the most suitable design is reached. Some of the refinements that
are often used include the following:
U
A concept may be first modeled as an attribute and then refined into a relationship because it is
determined that the attribute is a reference to another entity type
VT
Similarly, an attribute that exists in several entity types may be elevated or promoted to an
independent entity type. For example, suppose that each of several entity types in a UNIVERSITY
database, such as STUDENT, INSTRUCTOR, and COURSE, has an attribute Department in the
initial design; the designer may then choose to create an entity type DEPARTMENT with a single
attribute Dept_name and relate it to the three entity types (STUDENT, INSTRUCTOR, and
COURSE) via appropriate relationships
An inverse refinement to the previous case may be applied—for example, if an entity type
DEPARTMENT exists in the initial design with a single attribute Dept_name and is related to only
one other entity type, STUDENT. In this case, DEPARTMENT may be reduced or demoted to an
attribute of STUDENT
Sahana M Page 40
.IN
C
N
SY
U
VT
Sahana M Page 41
3.7.4 ER diagrams for the company schema, with structural constraints specified using (min, max)
notation and role names
.IN
C
N
SY
U
VT
Sahana M Page 42
.IN
C
N
SY
U
VT
Sahana M Page 43
.IN
C
N
SY
U
VT
Sahana M Page 44
The ER diagram notation for a ternary relationship type is shown in Figure (a), which displays the
schema for the SUPPLY relationship type that was displayed at the entity set/relationship set or
instance level
Recall that the relationship set of SUPPLY is a set of relationship instances (s, j, p), where s is a
SUPPLIER who is currently supplying a PART p to a PROJECT j
In general, a relationship type R of degree n will have n edges in an ER diagram, one connecting R
to each participating entity type.
Figure (b) shows an ER diagram for three binary relationship types CAN_SUPPLY, USES, and
SUPPLIES
In general, a ternary relationship type represents different information than do three binary
.IN
relationship types
Consider the three binary relationship types CAN_SUPPLY, USES, and SUPPLIES. Suppose that
CAN_SUPPLY, between SUPPLIER and PART, includes an instance (s, p) whenever supplier s
can supply part p (to any project); USES, between PROJECT and PART, includes an instance (j, p)
C
whenever project j uses part p; and SUPPLIES, between SUPPLIER and PROJECT, includes an
instance (s, j) whenever supplier s supplies some part to project j. The existence of three
N
relationship instances (s, p), (j, p), and (s, j) in CAN_SUPPLY, USES, and SUPPLIES,
respectively, does not necessarily imply that an instance (s, j, p) exists in the ternary relationship
SY
The designer must base this decision on the semantics or meaning of the particular situation being
represented
VT
Sahana M Page 45
ER diagram UNIVERSITY DB
.IN
C
N
SY
U
VT
Sahana M Page 46
.IN
C
N
SY
U
VT
Sahana M Page 47
.IN
C
N
SY
Sahana M Page 48
.IN
C
N
SY
U
Specializations the process of defining a set of subclasses of an entity type; this entity type is called
the super class of the specialization.
The set of subclasses that forms a specialization is defined on the basis of some distinguishing
characteristic of the entities in the supe rclass.
For example, the set of subclasses {SECRETARY, ENGINEER, TECHNICIAN} is a
specialization of the super class EMPLOYEE that distinguishes among employee entities based on
the job type of each employee.
Sahana M Page 49
.IN
Generalization
C
One can think of a reverse process of abstraction in which suppress the differences among several
N
entity types, identify their common features, and generalize them into a single superclass of which
the original entity types are special subclasses.
SY
For example, consider the entity types CAR and TRUCK shown in below figure . Because they
have several common attributes, they can be generalized into the entity type VEHICLE, as shown
in Figure.
Both CAR and TRUCK are now subclasses of the generalized superclass VEHICLE. We use the
U
term generalization to refer to the process of defining a generalized entity type from the given
entity types.
VT
Sahana M Page 50