dbms basic reference
TRANSCRIPT
-
7/30/2019 DBMS Basic Reference
1/445
DATA BASE
This Is About Managing and structuring the
collections of data held on computers. Adatabase consists of an organized collection
of data for one or more uses, typically in
digital form. Database involves the type of
their contents.
Eg:- bibliographic, document - text,statistical.
-
7/30/2019 DBMS Basic Reference
2/445
Project database
Centraldatabase
UserDB 1
UserDB 2
UserDB 43
userDB 4
-
7/30/2019 DBMS Basic Reference
3/445
Architecture
Database architecture consists of there
levels external, conceptual and internal.Clearly separating the three levels was a
major feature of the relational databasemodel that dominates 21st century database.
-
7/30/2019 DBMS Basic Reference
4/445
Database Management System
A database management system(DBMS)
consists of software that operates databases,providing storage, access, security, backup and
other facilities. Examples of some commonly
used DBMS are My SQL, Postgre SQL,
Microsoft access, SQL server, file maker, oracle,
RDBMS and clipper etc.
-
7/30/2019 DBMS Basic Reference
5/445
Components of DBMS
Most DBMS as of 2009 implement a relational model. Other
DBMS system , such as object DBMS, offer specific feature formore specialized requirements. Their components are similar,
but not identical.
-
7/30/2019 DBMS Basic Reference
6/445
RDBMS Components
Sublanguage
Language(DDL)
Language(DCL)
Language(DML)
Relation DBMS(RDBMS)
for defining the structureof database and data
control
for defining security/access
controls, and data
manipulation.
For querying and updating
data.
-
7/30/2019 DBMS Basic Reference
7/445
RDBMS Components
Interface drivers these drivers are code
libraries that provide methods to preparestatements, execute statement, fetch results
etc. E.g. ODBC,JDBC
SQL engine the components interpretsand execute the DDL,DCL and DML
statements, it include three majorcomponents computer, optimizer and
executer.
-
7/30/2019 DBMS Basic Reference
8/445
RDBMS Components
Transaction engine ensure that multiple SQL
statements either or fail as a group, according toapplication dictates.
Relation engine relation objects such as Table,
Index, and referential integrity constraints are
implemented in this components.
-
7/30/2019 DBMS Basic Reference
9/445
ODBMS Components
object DBMS (ODBMS) has transaction and
storage components that are analogous to thosein an RDBMS. Some ODBMS handles DDL,DCL
and update tasks. differently instead of using
sublanguages, they provide APIs for these
purposes E.g. OQL,LING
-
7/30/2019 DBMS Basic Reference
10/445
Types of Database
Operational database these database store
the detailed database about the operations of anorganization they are typically organized by
subject matter, process relatively high volumes
of update using transaction E.g. include
customers database that record cont, credit.
-
7/30/2019 DBMS Basic Reference
11/445
Types of Database
Data Warehouse data ware houses archive
modern data from operational database andoften from external sources such as market
research firms. Often operational data
undergoes transformation on its way into the
warehouse, getting summarized, anonymized,
reclassified etc. E.g. sales data might be arrangedto weekly totals and converted from internal
product codes into UPC code.
-
7/30/2019 DBMS Basic Reference
12/445
Types of Database
Analytical database it may do their work
directly against, a data warehouse , or credit aseparate analytic database for online analytical
processing. E.g. a company might extract sales
records for analyzing the effectiveness of
advertising and other sales promotions of an
aggregate level.
-
7/30/2019 DBMS Basic Reference
13/445
Types of Database
Distributed database it is local work-groups and
departments at regional offices, branch offices,manufacturing plants and other work sites.
External database it contain data collected for user
across multiple organization, either freely or via
subscription.
-
7/30/2019 DBMS Basic Reference
14/445
Types of Database
End-user database it consist of data developed
by individuals end-users. E.g. these arecollections of documents in spreadsheet, word
processing and downloaded files.
Hypermedia database - the worldwide web can
through of as a database, albeit one spread
across million s of independent computingsystem.
-
7/30/2019 DBMS Basic Reference
15/445
Models
Post-relation database models product
offering a more general data model than arerelational model are sometime classified as post-
relational alternate term include hybrid
database, object-enhanced RDBMS and
others. The data model in such products
incorporates relations but not constrained by E.F.codds information principle.
-
7/30/2019 DBMS Basic Reference
16/445
Models
Object database models In recent year, the
object-oriented paradigm has been applied inarea such as engineering and spatial database
telecommunication and in various scientific
domain. The conglomeration of object oriented
programming and database technology led to
this new kind of database.
-
7/30/2019 DBMS Basic Reference
17/445
Storage structure
Database may store relational tables/indexes in memory or onhard disk in one of many forms.
Ordered/unordered flat files
ISAM
Heaps
Hash buckets
B+ tree
The most commonly used b+ tree and ISAM.
-
7/30/2019 DBMS Basic Reference
18/445
Indexing
Indexing is a technique for improving database
performance. The simplest form of index is avalues that can be searched using a binary
search with an adjacent reference to the location
of the entry, analogous to the index in the black
of a book.
Transaction
as every s/w system, a DBMS
operates in a faulty computing environment and
prone of failures of many kinds
-
7/30/2019 DBMS Basic Reference
19/445
The ACID rules
Most DBMS provide some form of support for
transaction, which allow multiple data item to beupdated in a consistence fashion, such that are
part of transaction succeed or fail in unison.
Concurrency control and looking - it essential
for the correctness of transactions executed
concurrently in a DBMS, which is commonexecution mode for performance reason
-
7/30/2019 DBMS Basic Reference
20/445
Lock types
Locks can be shared or exclusive, and can look out
readers and/or writers locks can be createdimplicitly by the DBMS when a transaction
performance an operation or explicitly at the
transactions request.
Dead locks dead lock occur when two
transaction each requires data that the other hasalready locked exclusively.
-
7/30/2019 DBMS Basic Reference
21/445
THE
HOUSE
IS
OPEN
4QUERIES
-
7/30/2019 DBMS Basic Reference
22/445
Copyright @ www.bcanotes.com
S t r u c t u r e o f D B M S
Data Definition Language Compiler
The DDL Compiler converts the data definition
statements into a set of tables. These tables contain
the metadata concerning the database and are in a
form that can be used by other components of DBMS.
-
7/30/2019 DBMS Basic Reference
23/445
Copyright @ www.bcanotes.com
S t r u c t u r e o f D B M S
Data Manager
The data manager is the central software component of the
DBMS. It is sometimes referred to as the database control systemOne of the functions of the data manager is to convert operations
in the users queries coming directly via the query processor or
indirectly via an application program from users logical view to a
physical file system. The data manager is responsible for
interfacing with the file system. In addition, the tasks of enforcing
constraints to maintain the consistency and integrity of the data, aswell as its security, are also performed by the data manager
Synchronizing the simultaneous operations performed by
concurrent users is under the control of the data manager. It is also
entrusted with the backup and recovery operations.
-
7/30/2019 DBMS Basic Reference
24/445
Copyright @ www.bcanotes.com
S t r u c t u r e o f D B M S
ile Manager
Responsibility for the structure of the files and managing thefile space rests with the file manager. It is also responsible for
locating the block containing the required record, requesting
this block from the disk manager, and transmitting the
required record to the data manager. The file manager can be
implemented using an interface to the existing file subsystem
provided by the operating system of the host computer or it
can include a file subsystem written especially for DBMS.
-
7/30/2019 DBMS Basic Reference
25/445
Copyright @ www.bcanotes.com
S t r u c t u r e o f D B M S
Disk Manager
The disk manager is part of the operating system of the host
computer and all physical input and output operations are
performed by it. The disk manager transfers the block or page
requested by the file manager so that the latter need not be
concerned with the physical characteristics of the underlying
storage media.
-
7/30/2019 DBMS Basic Reference
26/445
Copyright @ www.bcanotes.com
S t r u c t u r e o f D B M S
Query Processor
The database user retrieves data by formulating a query in the data
manipulation language provided with the database. The query
processor is used to interpret the online users query and convert it
into an efficient series of operations in a form capable of being
sent to the data manager for execution. The query processor uses
the data dictionary to find the structure of the relevant portion of
the database and uses the information in modifying the query and
preparing an optimal plan to access the database.
-
7/30/2019 DBMS Basic Reference
27/445
Copyright @ www.bcanotes.com
S t r u c t u r e o f D B M S
atch
er
Data files and data
dictionary
Telecom System
Compiled
user interface
Compiled application
program
Nave user Casual User
Telecom system
Query Processor
DBMS and its data
manager
OS or own file
manager
OS disk
manager
Telecom system
DDL Compiler
DBA
Data files and
data dictionary
-
7/30/2019 DBMS Basic Reference
28/445
Copyright @ www.bcanotes.com
S t r u c t u r e o f D B M S
Data Files
Data files contain the data portion of the database.
Data dictionary
Information pertaining to the structure and usage of data containe
in the database, the metadata, is maintained in a data dictionary
The term system catalog also describes this meta data. The dat
dictionary, which is a database itself, documents the data. Eac
database user can consult the data dictionary to learn what eac
piece of data and various synonyms of the data fields mean.
-
7/30/2019 DBMS Basic Reference
29/445
Copyright @ www.bcanotes.com
S t r u c t u r e o f D B M S
Data dictionary
In an integrated system (i.e., in a system where the data
dictionary is a part of the DBMS) the data dictionary store
information concerning the external, conceptual, and interna
levels of the database. It contains the source of each data-field
value, the frequency of its use, and an audit trail concerning
updates, including the who and when of each update.
Currently data dictionary systems are available as add-onto the DBMS. Standards have yet to be evolved for integrating the
data dictionary facility with the DBMS so that the two databases
one for metadata and the other for data, can be manipulated using
an unified DDL/DML.
-
7/30/2019 DBMS Basic Reference
30/445
Copyright @ www.bcanotes.com
S t r u c t u r e o f D B M S
Access Facilities
To improve the performance of a DBMS, a set of
access facilities in the form of indexes are usually
provided in a database system. Commands are provided
to build and destroy additional temporary indexes.
-
7/30/2019 DBMS Basic Reference
31/445
Copyright @ www.bcanotes.com
An Architecture for a Database System
The architecture is divided into three general levels: internal
conceptual, and external
External Level
(Individual user view)
Conceptual Level
(Community user view)
Internal Level
(storage view)
-
7/30/2019 DBMS Basic Reference
32/445
Copyright @ www.bcanotes.com
An Architecture for a Database System
Broadly speaking,
The internal levelis the one closest to the physical storage.
The external levelis the one closest to the users, that is, the one
concerned with the way in which the data is viewed by
individual users.
The conceptual level is a level of indirection between the
other two.
-
7/30/2019 DBMS Basic Reference
33/445
Copyright @ www.bcanotes.com
An Architecture for a Database System
If the external levelis concerned with the individual user views,
theconceptual levelmay be thought of as defining a community
user view. In other words, there will be many externalviews,
each consisting of a more or less abstract representation of some
portion of the database, and there will be a single conceptual
view, consisting of a similarly abstract representation of the
database in its entirety.(Remember that most users will not be
interested in the total database, but only in some restricted portion
of it.) Likewise, there will be a single internal view,
representing the total database as actually stored.
-
7/30/2019 DBMS Basic Reference
34/445
Copyright @ www.bcanotes.com
An Architecture for a Database System
E x t e r n a l (PL/I)
DCL 1 EMPP,
2 EMP# CHAR(6),
3 SAL FIXED BIN(31);
E x t e r n a l (COBOL)
01 EMPC.
02 EMPNO PIC X(6).
03 DEPTNO PIC X(4).
C o n c e p t u a l
EMPLOYEE
EMPLOYEE_NUMBER CHARACTER (6)
DEPARTMENT_NUMBER CHARACTER (4)
SALARY NUMRIC (5)
I n t e r n a l
STORED_EMP LENGTH=18
PREFIX TYPE=BYTE(6), OFFSET=0
EMP# TYPE=BYTE(6), OFFSET=6, INDEX=EMPX
DEPT# TYPE=BYTE(4), OFFSET=12
PAY TYPE=FULLWORD, OFFSET=16
A
n
E
x
a
m
p
l
e
o
f
T
hr
e
e
L
e
ve
l
s
-
7/30/2019 DBMS Basic Reference
35/445
Copyright @ www.bcanotes.com
An Architecture for a Database System
Figure shows the conceptual structure of a simple personnel
database, the corresponding internal structure, and two
corresponding external structure (one for a PL/I user, the other for
COBOL user). The example is completely hypotheticalit is not
intended to resemble any actual system and many irrelevant
details have been deliberately omitted.
-
7/30/2019 DBMS Basic Reference
36/445
Copyright @ www.bcanotes.com
An Architecture for a Database System
At the conceptual level, the database contains information
concerning an entity type called EMPLOYEE. Each EMPLOYEE
has an EMPLOYEE_NUMBER (six character), a
DEPARTMENT_NUMBER (four characters), and a SALARY
(five digits).
-
7/30/2019 DBMS Basic Reference
37/445
Copyright @ www.bcanotes.com
An Architecture for a Database System
At the internal level, employees are represented by a stored
record type called STORED_EMP, eighteen bytes long
STORED_EMP contains four stored field types: a six-byte prefix
(presumably containing control information such as flags or
pointers) and three data fields corresponding to the three
properties of EMPLOYEE. In addition, STORED_EMP records
are indexed on the EMP# field by an index called EMPX.
-
7/30/2019 DBMS Basic Reference
38/445
Copyright @ www.bcanotes.com
An Architecture for a Database System
The PL/I user has an external view of the database in which
each employee is represented by a PL/I record containing two
fields (department numbers are of no interest to this user and are
omitted from the view). The record type is defined by an ordinary
Pl/I structure declaration in accordance with the normal Pl/I rules.
-
7/30/2019 DBMS Basic Reference
39/445
Copyright @ www.bcanotes.com
An Architecture for a Database System
Similarly, the COBOL user has an external view in which each
employee is represented by a COBOL record containing, again,
two fields (salaries are omitted). The record type is defined by an
ordinary COBOL record description in accordance with normal
COBOL rules.
-
7/30/2019 DBMS Basic Reference
40/445
Copyright @ www.bcanotes.com
An Architecture for a Database System
Notice that corresponding objects at the three levels can have
different names at each level. For example, the COBOL employee
number field is called EMPNO, the corresponding stored field is
called EMP#, and the corresponding conceptual object is called
EMPLOYEE_NUMBER.( The system must be aware of the
correspondences. For example, it must be told that the COBOL
field EMPNO is derived from the conceptual object
EMPLOYEE_NUMBER, which in turn is represented by the
stored field EMP#. Such correspondences, or mapping, have not
been shown in the figure).
-
7/30/2019 DBMS Basic Reference
41/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
The users are either application programmers or on-line terminal
users of any degree of sophistication. Each user has a language at
his or her disposal. For the application programmer it will be a
conventional programming language, such as COBOL or PL/I
for the terminal user it will be either a query language or a special
purpose language tailored to that users requirements and
supported by an on-line application program.
Users
-
7/30/2019 DBMS Basic Reference
42/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
An individual user will generally be interested only in some
portion of the total database; moreover, the users view of that
portion will generally be some what abstract when compared with
the way in which the data is physically stored. In ANSI terms an
individual users view is called an external view.
External View
-
7/30/2019 DBMS Basic Reference
43/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
An external view is thus the content of the database as it is seen
by some particular user, for example, a user from personnel
department, users in the purchasing department. In general, then,
an external view consists of multiple occurrences of multiple
types of external records. An external record is not necessarily the
same as a stored record. The users data sub language is defined
in terms of external records.
xternal View
-
7/30/2019 DBMS Basic Reference
44/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
Each external view is defined by means of an external schema,
which consists basically of definitions of each of the various
types of external record in the that external view. The external
schema is written using the DDL portion of the data sub
language. That DDL is therefore sometimes called an external
DDL.
xternal View
-
7/30/2019 DBMS Basic Reference
45/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
The conceptual view is a representation of the entire information
content of the database, again in a form that is somewhat abstract
in comparison with the way in which the data is physically
stored.(It may also be quite different from the way in which the
data is viewed by any particular user. Broadly speaking, it is
intended to be a view of the data as it really is, rather than as
users are forced to see it by the constraints of the particular
language or hardware they are using.
Conceptual View
-
7/30/2019 DBMS Basic Reference
46/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
A conceptual record is not necessarily the same as either an
external record, on the one hand, or a stored record, on the other.
The conceptual view is defined by means of the conceptual
schema, which includes definitions of each of the various types of
conceptual record. The conceptual schema is written using
another data definition languagethe conceptual DDL.
Conceptual View
-
7/30/2019 DBMS Basic Reference
47/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
The conceptual view, then, is a view of the total database content,
and the conceptual schema is a definition of this view. However,
it would be misleading to suggest that the conceptual schema is
nothing more than a set of definitions much like the simple record
definitions in a COBOL program today. The definitions in the
conceptual schema are intended to include a great many
additional features, such as authorization checks and validation
procedures.
Conceptual View
-
7/30/2019 DBMS Basic Reference
48/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
The internal view is a very low level representation of the entiredatabase; it consists of multiple occurrences of multiple types of
internal record. Internal record is the ANSI term for the
construct that we have been calling a stored record; the internal
view is thus still at one remove from the physical level, since it
does not deal in terms of physical records or blocks, nor with any
device-specific constraints such as cylinder or track sizes.
nternal Level
-
7/30/2019 DBMS Basic Reference
49/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
nternal Level
The internal view is described by means of the internal schema,
which not only defines the various types of stored record but also
specifies what indexes exist, how stored fields are represented,
what physical sequence the stored record are in, and so on. The
internal schema is written in using yet another data definition
language - the internal DDL.
-
7/30/2019 DBMS Basic Reference
50/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
Mapping between Conceptual & Internal
The conceptual/internal mapping defines the correspondence
between conceptual view and the stored database; it specifies how
conceptual records and fields map into their stored counterparts
If the structure of the stored database is changedi.e., if a change
is made to the storage structure definition the
conceptual/internal mapping must be changed accordingly, so thatthe conceptual schema may remain invariant. In other words, the
effects of such changes must be contained below the conceptual
level, so that data independence can be achieved.
-
7/30/2019 DBMS Basic Reference
51/445
Copyright @ www.bcanotes.com
Components of A r c h i t e c t u r e
Mapping between External & Conceptual
An external/conceptual mapping defines the correspondence
between a particular external view and the conceptual view. In
general, the same sort of differences may exist between these two
levels as may exist between the conceptual view and stored
database. For example, fields may have different data types
records may be differently sequenced and so on. Any number ofexternal views may exist at the same time; any numbers of users
may share a given external view; different external views may
overlap.
-
7/30/2019 DBMS Basic Reference
52/445
Database System Environment
The term database system refers to anorganization of components that define andregulate the collection, storage, management,and use of data within a databaseenvironment. These are:
Hardware Software People Procedures Data
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
53/445
It identifies all the systems physicaldevices. The database systems main and mosteasily identified hardware component is thecomputer, which might be a microprocessor, a
minicomputer, or a mainframe computer. Italso include peripherals like keyboard, mice,modems, printers, etc.
Hardware
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
54/445
Software refers to the collection ofprograms used by the computers within thedatabase system.
Operating system Software- managesall hardware components and makes it
possible for all other software to run on thecomputers. DOS,OS/2, and Windows used bymicro computers. UNIX and VMS used bymini computers, and MVS used by IBMmainframe computers.
Software
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
55/445
DBMS Software- manages the databasewithin the database system. MS-Access, MS-SQL Server, Oracle, DB2 etc. are some famousDBMS software.
Application Programs & Utilities
Software- are used to access and manipulatethe data in the DBMS to manage the computerenvironment in which data access andmanipulation take place.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
56/445
System Administrator: oversee thedatabase systems general operations.
Database Administrator: manage theDBMSs use and ensure that the database isfunctioning properly.
Database Designers: design the databasestructure. They are in effect the databasearchitects. If the database design is poor, eventhe best application programmers and the mostdedicated DBAs will fail to produce a usefuldatabase environment.
People
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
57/445
System Analysts and Programmers: designand implement the application programs. They
design and create the data entry screens, reports,and procedures through which end user accessand manipulate the databases data.
End Users: are the people who use the
application programs to run the organizationsdaily operations. E.g. sales clerks, supervisors,managers, and directors are all classified as endusers. High-level end users employ theinformation obtained from the database to maketactical and strategic business decisions.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
58/445
Procedures
Procedures are the instructions and rules thatgovern the design and use of the databasesystem. Procedure are a critical, althoughoccasionally forgotten, component of thesystem. Procedures play a very important role ina company, because they enforce the standards
by which business is conducted within theorganization and with customers. These also areused to ensure that there is an organized way tomonitor and audit both the data andinformation.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
59/445
Data
The word data covers the collection of factsstored in the database. Because data are theraw material from which information isgenerated, the determination of which data areto be entered into the database and how such
data are to be organized is a vital part of thedatabase designers job.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
60/445
DBMS Functions
A DBMS performs several important functions
that guarantee the integrity and consistency of
the data in the database. Most of these functions
are transparent to end users, and most can beachieved only through the use of a DBMS.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
61/445
Data dictionary management: The DBMSrequires that definitions of the data elements
and their relationships(metadata) be stored in a
data dictionary. In turn, all programs that
access the data in the database work through
the DBMS. The DBMS uses the data dictionary
to look up the required data component
structures and relationships, thus relieving us
from having to code such complex relationships
in each program.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
62/445
Data Storage Management: The DBMScreates the complex structures required for data
storage, thus relieving us from the difficult task
of defining and programming the physical data
characteristics. A modern DBMS system provides
storage not only for the data, but also for the
related data entry forms or screen definitions,
report definitions, data validation rules,
procedural code, structures to handle video and
picture formats, and so on.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
63/445
Data transformation and presentation: theDBMS transforms entered data to conform to thedata structures that are required to store data.Therefore, the DBMS relieves us of the chore ofmaking a distinction between the data logicalformat and the data physical format. By
maintaining the data independence, the DBMStranslates logical requests into commands thatphysically locate and retrieve the requested data.That is, the DBMS formats the physicallyretrieved data to make it confirm to the userslogical expectations.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
64/445
Security Management: The DBMS creates asecurity system that enforces user security anddata privacy within the database. Security rulesdetermines which user can access the database,which data items each user may access, and
which data operations the user may perform.This is especially important in multi userdatabase systems where many users can accessthe database simultaneously.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
65/445
Multi user access control: The DBMScreates the complex structures that allow multiuser access to the data. In order to provide dataintegrity and data consistency, the DBMS usessophisticated algorithms to ensure that multiple
users can access the database concurrentlywithout compromising the integrity of thedatabase.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
66/445
Backup and recovery management: TheDBMS provides backup and data recoveryprocedures to ensure data safety and integrity.Current DBMS system provide special utilitiesthat allow the DBA to perform routine andspecial backup and restore procedures. Recovery
management deals with the recovery of thedatabase after a failure, such as a bad sector inthe disk or a power failure. Such capability iscritical to the preservation of the databasesintegrity.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
67/445
Data Integrity Management: The DBMSpromotes and enforces integrity rules toeliminate data integrity problems, thusminimizing the data duplicity and maximizingdata consistency. The data relationships stored inthe data dictionary are used to enforce data
integrity. Ensuring data integrity is especiallyimportant in transaction-oriented databasesystems.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
68/445
Database access languages and applicationprogramming interface: The DBMS providesdata access via a query language. A querylanguage is a nonprocedural language that is,one that lets the user specify what must be donewithout having to specify how it is to be done. TheDBMS query language contains two components:
a DDL and DML. The DBMS also provides dataaccess to programmers via procedurallanguages.It also provides administrative utilitiesused by the DBA and the database designer tocreate, implement, monitor, and maintain thedatabase.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
69/445
Database communication interfaces:Current-generation DBMSs provide specialcommunications routines designed to allow thedatabase to accept end user requests within acomputer network environment. In fact,database communications capabilities are an
essential feature of the modern DBMS. E.g. theDBMS might provide communications functionsto access the database through the Internet,using Internet browsers such as Netscape orExplorer as the front end.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
70/445
There are many definitions of the termdatabaseand one of the most common oneis that the database is a collection ofinformation/ knowledge stored in digital
format.
The database can be in form of a flattext file or can be a relational database.
The term "database" is used to describeboth the collection of data and the softwaretool used to manage the data (i.e. DBMS).
What is a database?
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
71/445
Databases are used in most of themodern software applications. Databasesprovide the means of storing data, accessiblesimultaneously by many users.
Databases use a programming languagecalled SQL (Structured Query Language),which makes accessing and storing relationaldata very easy.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
72/445
RDBMS stands for Relational Database ManagemenSystem. RDBMS data is structured in database tablesfields and records. Each RDBMS table consists odatabase table rows. Each database table rowconsists of one or more database table fields
RDBMS store the data into collection of tables, whicmight be related by common fields (database tablcolumns). RDBMS also provide relational operators tmanipulate the data stored into the database tablesMost RDBMS use SQL as database query language
What is RDBMS?
Copyright @ www.bcanotes.com
http://localhost/var/www/apps/conversion/tmp/scratch_1/ -
7/30/2019 DBMS Basic Reference
73/445
Edgar Codd introduced the relationaldatabase model. Many modern DBMS do notconform to the Codds definition of a RDBMS,but nonetheless they are still considered to be
RDBMS.
The most popular RDBMS are MS SQLServer, DB2, Oracle and MySQL.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
74/445
SQL stands for Structured QueryLanguage. SQL language is used to create,transform and retrieve information fromRDBMS. SQL is pronounced SEQUEL. SQL wasdeveloped during the early 70s at IBM.
SQL is a declarative programminglanguage designed for creating and queryingrelational database management systems. SQLis relatively simple language, but its also verypowerful.
What is SQL?
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
75/445
SQL can insert, modify data in existingdatabase tables. SQL can delete data from SQLdatabase tables. Finally SQL can modify thedatabase structure itself create/ modify/ deletetables and other database objects.
SQL uses set of commands to manipulatethe data in relational databases. For example SQLINSERT is used to insert data in database tables.SQL SELECT command is used to retrieve datafrom one or more database tables. SQL UPDATE isused to modify existing database records.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
76/445
Most RDBMS like MS SQL Server, MSAccess, Oracle, MySQL, DB2, Sybase,PostgreSQL and Informix use SQL as adatabase querying language. Even though SQLis defined by both ISO and ANSI there aremany SQL implementation, which do not fully
comply with those definitions. Some of theseSQL implementations are proprietary. Examplesof these SQL dialects are MS SQL Serverspecific version of the SQL called T-SQL andOracle version of SQL called PL/SQL.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
77/445
E n t i t y R e l a t i o n s h i p M o d e l
Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of an E-R Database Schema Reduction of an E-R Schema to
Tables
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
78/445
E n t i t y S e t s
Adatabase can be modeled as:
a collection of entities, relationship among entities.
An entity is an object that exists and isdistinguishable from other objects. Example: specific person, company, event, plant
Entities have attributes
Example: people have names and addresses An entity setis a set of entities of the same type that
share the same properties. Example: set of all persons, companies, trees, holidays
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
79/445
E n t i t y S e t s c u s t o m e r a n d l o a n
customer-id customer- customer- customer- loan- amountname street city number
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
80/445
A t t r i b u t e s
An entity is represented by a set of attributes, that isdescriptive properties possessed by all members ofan entity set.
Domain the set of permitted values for eachattribute
Attribute types: Simple and composite attributes.
Single-valuedand multi-valuedattributes E.g. multivalued attribute:phone-numbers
Derivedattributes Can be computed from other attributes E.g. age, given date of birth
Example:
customer = (customer-id, customer-name,customer-street, customer-city)loan = (loan-number, amount)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
81/445
C o m p o s i t e A t t r i b u t e s
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
82/445
R e l a t i o n s h i p S e t s
Arelationship is an association among severalentitiesExample:
Hayes depositor A-102customer entityrelationship setaccountentity
Example:(Hayes, A-102) depositor
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
83/445
Relationship Set borrower
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
84/445
Relationship Sets (Cont.)
An attribute can also be property of a relationship set. For instance, the depositor relationship set between entity sets
customer and accountmay have the attribute access-date
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
85/445
Degree of a Relationship Set
Refers to number of entity sets that participate in arelationship set.
Relationship sets that involve two entity sets arebinary (or degree two). Generally, most relationshipsets in a database system are binary.
Relationship sets may involve more than two entitysets.
Relationships between more than two entity sets arerare. Most relationships are binary.
E.g. Suppose employees of a bank may have jobs(responsibilities) at multiple branches, with different jobs atdifferent branches. Then there is a ternary relationship setbetween entity sets employee, job and branch
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
86/445
Mapping Cardinalities
Express the number of entities to which another
entity can be associated via a relationship set. Most useful in describing binary relationship sets.
For a binary relationship set the mappingcardinality must be one of the following types: One to one
One to many
Many to one
Many to many
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
87/445
Mapping Cardinalities
One to one One to many
Note: Some elements in A and B may not be mapped to any elements in the other
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
88/445
Mapping Cardinalities ...
Many to one Many to many
Note: Some elements in A and B may not be mapped to any elements in the other
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
89/445
Mapping Cardinalities affect ER Design
Can make access-datean attribute of account, instead of arelationship attribute, if each account can have only one customer
I.e., the relationship from account to customer is many to one,or equivalently, customer to account is one to many
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
90/445
E - R D i a g r a m s
Rectangles represent entity sets.
Diamonds represent relationship sets.
Lines link attributes to entity sets and entity sets to relationship sets.
Ellipses represent attributes
Double ellipses represent multivalued attributes.
Dashed ellipses denote derived attributes.
Underline indicates primary key attributes (will study later)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
91/445
- agram t ompos te, u t va ue , an er veAttributes
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
92/445
Relationship Sets with Attributes
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
93/445
Roles
Entity sets of a relationship need not be distinct The labels manager and worker are called roles; they specify how
employee entities interact via the works-for relationship set.
Roles are indicated in E-R diagrams by labeling the lines that connectdiamonds to rectangles.
Role labels are optional, and are used to clarify semantics of therelationship
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
94/445
Cardinality Constraints
We express cardinality constraints by drawing eithera directed line (), signifying one, or anundirected line (), signifying many, between therelationship set and the entity set.
E.g.: One-to-one relationship: A customer is associated with at most one loan via the
relationship borrower A loan is associated with at most one customer via borrower
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
95/445
One-To-Many Relationship
In the one-to-many relationship a loan is associatedwith at most one customer via borrower, a customeris associated with several (including 0) loans via
borrower
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
96/445
Many-To-One Relationships
In a many-to-one relationship a loan is associated with several(including 0) customers via borrower, a customer isassociated with at most one loan via borrower
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
97/445
Many-To-Many Relationship
A customer is associated with several (possibly0) loans via borrower
A loan is associated with several (possibly 0)customers via borrower
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
98/445
Participation of an Entity Set in a Relationship Set
Totalparticipation (indicated by double line): every entity in the entityset participates in at least one relationship in the relationship set
E.g. participation of loanin borroweris total
every loan must have a customer associated to it via borrower Partial participation: some entities may not participate in any
relationship in the relationship set
E.g. participation of customerin borroweris partial
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
99/445
K e y s
Asuper key of an entity set is a set of one or moreattributes whose values uniquely determine each entity. Acandidate key of an entity set is a minimal super key
Customer-idis candidate key ofcustomer account-number is candidate key ofaccount
Although several candidate keys may exist, one of thecandidate keys is selected to be theprimary key.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
100/445
Keys for Relationship Sets
The combination of primary keys of the participatingentity sets forms a super key of a relationship set. (customer-id, account-number) is the super key ofdepositor NOTE: this means a pair of entity sets can have at most one
relationship in a particular relationship set. E.g. if we wish to track all access-dates to each account by each
customer, we cannot assume a relationship for each access. We can usea multivalued attribute though
Must consider the mapping cardinality of therelationship set when deciding the what are thecandidate keys
Need to consider semantics of relationship set inselecting the primary key in case of more than onecandidate key
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
101/445
E-RDiagram with a Ternary Relationship
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
102/445
Cardinality Constraints on Ternary Relationship
We allow at most one arrow out of a ternary (or greaterdegree) relationship to indicate a cardinality constraint
E.g. an arrow from works-on to job indicates eachemployee works on at most one job at any branch.
If there is more than one arrow, there are two ways ofdefining the meaning. E.g a ternary relationshipRbetweenA, B and Cwith arrows toB
and Ccould mean
1. eachA entity is associated with a unique entity fromB and Cor
2. each pair of entities from (A, B) is associated with a unique Centity, and each pair (A, C) is associated with a uniqueB
Each alternative has been used in different formalisms
To avoid confusion we outlaw more than one arrow
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
103/445
Design Issues
Use of entity sets vs. attributesChoice mainly depends on the structure of the enterprise
being modeled, and on the semantics associated with the
attribute in question. Use of entity sets vs. relationship sets
Possible guideline is to designate a relationship set todescribe an action that occurs between entities
Binary versus n-ary relationship setsAlthough it is possible to replace any nonbinary (n-ary, forn > 2) relationship set by a number of distinct binaryrelationship sets, a n-ary relationship set shows moreclearly that several entities participate in a singlerelationship.
Placement of relationship attributes
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
104/445
Weak Entity Sets
An entity set that does not have a primary key is referredto as a weak entity set.
The existence of a weak entity set depends on theexistence of a identifying entityset it must relate to the identifying entity set via a total, one-to-many
relationship set from the identifying to the weak entity set Identifying relationship depicted using a double diamond
The discriminator (or partial key) of a weak entity set isthe set of attributes that distinguishes among all the
entities of a weak entity set. The primary key of a weak entity set is formed by the
primary key of the strong entity set on which the weakentity set is existence dependent, plus the weak entitysets discriminator.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
105/445
Weak Entity Sets (Cont.)
We depict a weak entity set by double rectangles. We underline the discriminator of a weak entity set with a
dashed line. payment-number discriminator of thepaymententity
set Primary key forpayment (loan-number, payment-number)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
106/445
Weak Entity Sets (Cont.)
Note: the primary key of the strong entity set is not
explicitly stored with the weak entity set, since it isimplicit in the identifying relationship. Ifloan-number were explicitly stored,paymentcould be
made a strong entity, but then the relationship betweenpaymentand loan would be duplicated by an implicitrelationship defined by the attribute loan-numbercommon topaymentand loan
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
107/445
More Weak Entity Set Examples
In a university, a course is a strong entity and a
course-offering can be modeled as a weak entity The discriminator ofcourse-offering would be
semester (including year) and section-number (ifthere is more than one section)
If we model course-offering as a strong entity wewould model course-number as an attribute.Then the relationship with course would be implicit
in the course-number attribute
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
108/445
Specialization
Top-down design process; we designate subgroupingswithin an entity set that are distinctive from other entitiesin the set.
These subgroupings become lower-level entity sets thathave attributes or participate in relationships that do notapply to the higher-level entity set.
Depicted by a triangle component labeled ISA (E.g.customeris aperson).
Attribute inheritance a lower-level entity set inheritsall the attributes and relationship participation of thehigher-level entity set to which it is linked.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
109/445
Specialization Example
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
110/445
Generalization
A bottom-up design process combine a number of entity setsthat share the same features into a higher-level entity set. Specialization and generalization are simple inversions of each
other; they are represented in an E-R diagram in the sameway.
The terms specialization and generalization are usedinterchangeably.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
111/445
Specialization and Generalization
Can have multiple specializations of an entity setbased on different features.
E.g.permanent-employeevs. temporary-employee,in addition to officervs. secretaryvs. teller
Each particular employee would be a member of one ofpermanent-employee or temporary-
employee,
and also a member of one ofofficer, secretary, or teller
The ISA relationship also referred to as superclass -subclass relationship
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
112/445
Design Constraints on a Specialization/ Generalizatio
Constraint on which entities can be members of agiven lower-level entity set. condition-defined
E.g. all customers over 65 years are members ofsenior-citizen entity set; senior-citizen ISAperson.
user-defined
Constraint on whether or not entities may belongto more than one lower-level entity set within asingle generalization. Disjoint
an entity can belong to only one lower-level entity set Noted in E-R diagram by writing disjointnext to the ISA
triangle
Overlapping an entity can belong to more than one lower-level entity set
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
113/445
Des gn Constra nts on a Spec a zat on Genera zat on
Completenessconstraint -- specifies whether or notan entity in the higher-level entity set must belong to
at least one of the lower-level entity sets within ageneralization. total : an entity must belong to one of the lower-level entity
sets
partial: an entity need not belong to one of the lower-levelentity sets
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
114/445
Aggregation
Consider the ternary relationship works-on, which we saw earlier
Suppose we want to record managers for tasks performed by anemployee at a branch
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
115/445
Aggregation (Cont.)
Relationship sets works-on and manages representoverlapping information Everymanages relationship corresponds to a works-on relationship
However, some works-on relationships may not correspond to anymanages relationships
So we cant discard the works-on relationship
Eliminate this redundancy via aggregation Treat relationship as an abstract entity
Allows relationships between relationships
Abstraction of relationship into new entity
Without introducing redundancy, the following diagramrepresents: An employee works on a particular job at a particular branch
An employee, branch, job combination may have an associatedmanager
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
116/445
E-R Diagram With Aggregation
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
117/445
E-R Design Decisions
The use of an attribute or entity set to represent anobject.
Whether a real-world concept is best expressed by anentity set or a relationship set.
The use of a ternary relationship versus a pair of binaryrelationships.
The use of a strong or weak entity set. The use of specialization/generalization contributes to
modularity in the design. The use of aggregation can treat the aggregate entity
set as a single unit without concern for the details of itsinternal structure.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
118/445
E-R Diagram for a Banking Enterprise
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
119/445
Summary of Symbols Used in E-R Notation
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
120/445
Summary of Symbols (Cont.)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
121/445
Alternative E-R Notations
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
122/445
Reduction of an E-R Schema to Tables
Primary keys allow entity sets and relationship sets tobe expressed uniformly as tableswhich represent thecontents of the database.
A database which conforms to an E-R diagram can berepresented by a collection of tables. For each entity set and relationship set there is a
unique table which is assigned the name of thecorresponding entity set or relationship set.
Each table has a number of columns (generallycorresponding to attributes), which have uniquenames.
Converting an E-R diagram to a table format is thebasis for deriving a relational database design from anE-R diagram.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
123/445
Representing Entity Sets as Tables
A strong entity set reduces to a table with the sameattributes.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
124/445
Composite and Multivalued Attributes
Composite attributes are flattened out by creating aseparate attribute for each component attribute E.g. given entity set customer with composite attribute name with
component attributesfirst-name and last-name the tablecorresponding to the entity set has two attributes
name.first-name and name.last-name
A multivalued attribute M of an entity E is representedby a separate table EM Table EM has attributes corresponding to the primary key of E and
an attribute corresponding to multivalued attribute M E.g. Multivalued attribute dependent-names ofemployee is
represented by a tableemployee-dependent-names( employee-id, dname)
Each value of the multivalued attribute maps to a separate row ofthe table EM E.g., an employee entity with primary key John and
dependents Johnson and Johndotir maps to two rows:(John, Johnson) and (John, Johndotir)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
125/445
Representing Weak Entity Sets
A weak entity set becomes a table that includes a column forthe primary key of the identifying strong entity set
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
126/445
Representing Relationship Sets as Tables
A many-to-many relationship set is represented as a table withcolumns for the primary keys of the two participating entity sets,and any descriptive attributes of the relationship set.
E.g.: table for relationship set borrower
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
127/445
Redundancy of Tables
Many-to-one and one-to-many relationship sets that are totalon the many-side can be represented by adding an extraattribute to the many side, containing the primary key of theone side
E.g.: Instead of creating a table for relationship account-branch, add an attribute branchto the entity set account
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
128/445
Redundancy of Tables (Cont.)
For one-to-one relationship sets, either side can bechosen to act as the many side That is, extra attribute can be added to either of the tables
corresponding to the two entity sets
If participation ispartialon the many side,replacing a table by an extra attribute in the relationcorresponding to the many side could result in null
values The table corresponding to a relationship set linking
a weak entity set to its identifying strong entity set is
redundant. E.g. Thepaymenttable already contains the information that
would appear in the loan-paymenttable (i.e., the columnsloan-number andpayment-number).
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
129/445
Representing Specialization as Tables
Method 1:
Form a table for the higher level entity
Form a table for each lower level entity set, include primary key ofhigher level entity set and local attributes
table table attributesperson name, street, citycustomer name, credit-ratingemployee name, salary
Drawback: getting information about, e.g., employee requiresaccessing two tables
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
130/445
Representing Specialization as Tables
Method 2: Form a table for each entity set with all local and inherited attributes
table table attributes
person name, street, citycustomer name, street, city, credit-ratingemployee name, street, city, salary
If specialization is total, table for generalized entity (person) notrequired to store information
Can be defined as a view relation containing union of
specialization tables But explicit table may still be needed for foreign key constraints
Drawback: street and city may be stored redundantly for personswho are both customers and employees
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
131/445
Relations Corresponding to Aggregation
To represent aggregation, create a table containing
primary key of the aggregated relationship,
the primary key of the associated entity set
Any descriptive attributes
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
132/445
Relations Corresponding to Aggregation
E.g. to represent aggregation managesbetween relationshworks-onand entity set manager, create a tablemanages(employee-id, branch-name, title, manager-name
Table works-onis redundant provided we are willing to stonull values for attribute manager-namein table manages
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
133/445
RELATIONAL MODEL
Structure of Relational Databases
Relational Algebra
Tuple Relational Calculus Domain Relational Calculus
Extended Relational-Algebra-Operations
Modification of the Database
Views
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
134/445
EXAMPLE OF A RELATION
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
135/445
BASIC STRUCTURE
Formally, given sets D1, D2, . Dn a relation ris a subsetofD1 x D2 x x Dn
Thus a relation is a set of n-tuples (a1, a2, , an) whereeach ai Di
Example: if
customer-name = {Jones, Smith, Curry, Lindsay}customer-street = {Main, North, Park}customer-city = {Harrison, Rye, Pittsfield}
Thenr= { (Jones, Main, Harrison),
(Smith, North, Rye),(Curry, North, Rye),(Lindsay, Park, Pittsfield)}
is a relation overcustomer-name x customer-street xcustomer-city
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
136/445
ATTRIBUTE TYPES
Each attribute of a relation has a name
The set of allowed values for each attribute is called thedomain of the attribute
Attribute values are (normally) required to be atomic,that is, indivisible E.g. multivalued attribute values are not atomic
E.g. composite attribute values are not atomic
The special value null is a member of every domain
The null value causes complications in the definition ofmany operations we shall ignore the effect of null values in our main
presentation and consider their effect later
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
137/445
RELATION SCHEMA
A1,A2, ,Anare attributes
R = (A1,A2, ,An ) is arelation schema
E.g. Customer-schema =(customer-name, customer-street,
customer-city)
r(R) is arelation on therelation schema R
E.g. customer (Customer-schema)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
138/445
RELATION INSTANCE
The current values (relation instance) of arelation are specified by a table
An element t ofris a tuple, represented by arow in a table
JonesSmithCurry
Lindsay
customer-name
MainNorthNorthPark
customer-street
HarrisonRyeRye
Pittsfield
customer-city
customer
attributes(or columns)
tuples
(or rows)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
139/445
RELATIONS ARE UNORDERED
Order of tuples is irrelevant (tuples may be stored in an arbitrary order
E.g. accountrelation with unordered tuples
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
140/445
DATABASE
A database consists of multiple relations Information about an enterprise is broken up into parts, with
each relation storing one part of the information
E.g.: account : stores information about accountsdepositor: stores information about which
customerowns which account
customer: stores information about customers Storing all information as a single relation such as
bank(account-number, balance, customer-name, ..)results in repetition of information (e.g. two customers own an account) the need for null values (e.g. represent a customer without an
account)
Normalization theory deals with how to design relationalschemas
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
141/445
THE CUSTOMER RELATION
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
142/445
THE DEPOSITOR RELATION
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
143/445
E-R DIAGRAM FOR THE BANKINGENTERPRISE
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
144/445
SCHEMA DIAGRAM FOR THE BANKINGENTERPRISE
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
145/445
QUERY LANGUAGES
Language in which user requests information from
the database.
Categories of languages
procedural
non-procedural
Pure languages:
Relational Algebra
Tuple Relational Calculus
Domain Relational Calculus
Pure languages form underlying basis of querylanguages that people use.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
146/445
RELATIONAL ALGEBRA
Procedural language
Six basic operators
select
project
union
set difference
Cartesian product
rename
The operators take one or more relations as inputsand give a new relation as a result.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
147/445
SELECT OPERATION EXAMPLE
Relation r A B C D
1
5
12
23
7
7
3
10
A=B ^ D > 5(r)A B C D
1
23
7
10
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
148/445
SELECT OPERATION
Notation: p(r)
p is called the selection predicate
Defined as:
p(r) = {t | trand p(t)}
Where p is a formula in propositionalcalculus consisting of terms connected by : (and), (or), (not)Each term is one of:
op or
where op is one of: =, , >, .
-
7/30/2019 DBMS Basic Reference
149/445
PROJECT OPERATION EXAMPLE
Relation r: A B C
10
20
30
40
1
1
1
2
A C
1
1
1
2
=
A C
1
1
2
A,C (r)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
150/445
PROJECT OPERATION
Notation:
A1, A2, , Ak (r)
whereA1, A2 are attribute names andris a relationname.
The result is defined as the relation of k columnsobtained by erasing the columns that are not listed
Duplicate rows removed from result, since relationsare sets
E.g. To eliminate the branch-name attribute ofaccount
account-number, balance (account)Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
151/445
UNION OPERATION EXAMPLE
Relationsr, s:
r s:
A B
12
1
A B
23
r
s
A B
1
2
1
3
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
152/445
UNION OPERATION
Notation: rs
Defined as:
r s = {t | trorts}
Forrs to be valid.
1. r,s must have thesame arity (same number of
attributes)2. The attribute domains must be compatible (e.g.,2nd column
ofrdeals with the same type of values as doesthe 2nd
column ofs) Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
153/445
SET DIFFERENCE OPERATION EXAMPLE
Relationsr, s:
r s:
A B
12
1
A B
23
r
s
A B
1
1
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
154/445
SET DIFFERENCE OPERATION
Notationrs
Defined as:
rs = {t | trand t s}
Set differences must be taken between compatiblerelations.
rands must have thesame arity
attribute domains ofrands must be compatible
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
155/445
CARTESIAN-PRODUCTOPERATION-EXAMPLE
Relations r, s:
rx s:
A B
1
2
A B
1
1112222
C D
10
10201010102010
E
a
abbaabb
C D
10
102010
E
a
abbr
s
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
156/445
CARTESIAN-PRODUCT OPERATION
Notation rx s
Defined as:
rxs = {t q | t rand q s}
Assume that attributes of r(R) and s(S) are disjoint.(That is,R S = ).
If attributes ofr(R) ands(S) are not disjoint, thenrenaming must be used.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
157/445
COMPOSITION OF OPERATIONS
Can build expressions using multiple operations
Example: A=C(r x s)
r x s
A=C(r x s)
A B
1111222
2
C D
10102010101020
10
E
aabbaab
b
A B C D E
122
102020
aab
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
158/445
RENAME OPERATION
Allows us to name, and therefore to refer to, the
results of relational-algebra expressions.
Allows us to refer to a relation by more than onename.
Example:
x (E)
returns the expression E under the nameXIf a relational-algebra expression E has arity n, then
x(A1, A2, , An) (E)
returns the result of expression E under the nameX,and with the
attributes renamed toA1, A2, ., An.Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
159/445
BANKING EXAMPLE
branch (branch-name, branch-city, assets)
customer (customer-name, customer-street,customer-only)
account (account-number, branch-name,balance)
loan (loan-number, branch-name, amount)
depositor (customer-name, account-number)
borrower (customer-name, loan-number)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
160/445
EXAMPLE QUERIES
Find all loans of over $1200
Find the loan number for each loan of an amount greater than
$1200
amount> 1200 (loan)
loan-number
(amount
> 1200 (loan))
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
161/445
EXAMPLE QUERIES
Find the names of all customers who have a loan,
an account, or both, from the bank
Find the names of all customers who have a loan and an
account at bank.
customer-name (borrower) customer-name (depositor)
customer-name
(borrower) customer-name
(depositor)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
162/445
EXAMPLE QUERIES
Find the names of all customers who have a loan atthe Perryridge branch.
Find the names of all customers who have a loan at thePerryridge branch but do not have an account at any branch ofthe bank.
customer-name(branch-name = Perryridge(borrower.loan-number = loan.loan-number(borrower x loan))) customer-name(depositor)
customer-name(branch-name=Perryridge(borrower.loan-number = loan.loan-number(borrower x loan)))
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
163/445
EXAMPLE QUERIES
Find the names of all customers who have a loan at thPerryridge branch.
Query 2
customer-name(loan.loan-number = borrower.loan-number((branch-name = Perryridge(loan)) x borrower))
Query 1
customer-name(branch-name = Perryridge(borrower.loan-number = loan.loan-number(borrower x loan)))
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
164/445
EXAMPLE QUERIES
Find the largest account balance
Rename account relation as d
The query is:balance(account) - account.balance
(account.balance < d.balance(account xd(account)))
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
165/445
FORMAL DEFINITION
A basic expression in the relational algebra consists
of either one of the following: A relation in the database
A constant relation
Let E1 and E2 be relational-algebra expressions; thefollowing are all relational-algebra expressions:
E1E2
E1 - E2
E1 x E2
p (E1), P is a predicate on attributes in E1
s(E1), S is a list consisting of some of the attributes in E1 x(E1), x is the new name for the result of E1
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
166/445
ADDITIONAL OPERATIONS
We define additional operations that do not addany power to the
relational algebra, but that simplify commonqueries.
Set intersection
Natural join
Division
Assignment
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
167/445
SET-INTERSECTION OPERATION
Notation:rs
Defined as:
rs ={ t | trandts }
Assume:
r,s have thesame arity
attributes of r and s are compatible
Note:rs =r- (r-s)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
168/445
SET-INTERSECTION OPERATION -EXAMPLE
Relation r, s:
r s
A B
121
A B
2
3
r s
A B
2
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
169/445
Notation: r s
NATURAL-JOIN OPERATION
Letrands be relations on schemas R and Srespectively.
Then, r s is a relation on schema R S obtainedas follows: Consider each pair of tuples trfromrand ts froms.
If trand ts have the same value on each of the attributes inRS, add a tuple t to the result, where
t has the same value as tronr
t has the same value as ts ons
Example:
R = (A, B, C, D)
S = (E, B, D)
Result schema = (A, B, C, D, E)
r s is defined as: Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
170/445
NATURAL JOIN OPERATION EXAMPLE
Relations r, s:
A B
12412
C D
aabab
B
13123
D
aaabb
E
r
A B
11112
C D
aaaab
E
s
r s
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
171/445
DIVISION OPERATION
Suited to queries that include the phrasefor all.
Letrands be relations on schemas R and Srespectively where R = (A1, ,Am, B1, , Bn)
S = (B1, , Bn)
The result of r s is a relation on schema
RS = (A1, ,Am)
rs = { t | t R-S(r) u s ( tu r) }
rs
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
172/445
DIVISION OPERATION EXAMPLE
Relations r, s:
rs: A
B
1
2
A B
1
23111346
12
r
s
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
173/445
ANOTHER DIVISION EXAMPLE
A B
aaaaaaaa
C D
aabababb
E
11113111
Relations r, s:
rs:
D
ab
E
11
A B
aa
C
r
s
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
174/445
DIVISION OPERATION (CONT.)
Property Let qr s
Then q is the largest relation satisfying q xsr
Definition in terms of the basic algebraoperationLetr(R) ands(S) be relations, and let S R
rs = R-S (r)R-S ( (R-S(r) xs)R-S,S(r))
To see why R-S,S(r) simply reorders attributes ofr
R-S(R-S(r) xs)R-S,S(r)) gives those tuples t in
R-S(r) such that for some tuple u s, tu r.Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
175/445
ASSIGNMENT OPERATION
The assignment operation () provides a convenient wayto express complex queries. Write query as a sequential program consisting of
a series of assignments
followed by an expression whose value is displayed as a resultof the query.
Assignment must always be made to a temporary relationvariable.
Example: Writers as
temp1R-S (r)
temp2 R-S ((temp1 xs)R-S,S(r))
result = temp1temp2
The result to the right of the is assigned to the relation variable
on the left of the .
May use variable in subsequent expressions.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
176/445
EXAMPLE QUERIES
Find all customers who have an account from atleast the Downtown and the Uptownbranches.
where CNdenotes customer-name and BNdenotes
branch-name.
Query 1
CN(BN=Downtown(depositor account))
CN(BN=Uptown(depositor account))
Query 2
customer-name, branch-name(depositor account)
temp(branch-name) ({(Downtown), (Uptown)})
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
177/445
EXAMPLE QUERIES
Find all customers who have an account at all
branches located in Brooklyn city.
customer-name, branch-name(depositor account)
branch-name(branch-city= Brooklyn (branch))
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
178/445
VIEWS
In some cases, it is not desirable for all users tosee the entire logical model (i.e., all the actualrelations stored in the database.)
Consider a person who needs to know acustomers loan number but has no need to seethe loan amount. This person should see arelation described, in the relational algebra, by
customer-name, loan-number(borrower loan)
Any relation that is not of the conceptual modelbut is made visible to a user as a virtual relationis called a view.
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
179/445
VIEW DEFINITION
A view is defined using the create view statement
which has the form
create view v as
-
7/30/2019 DBMS Basic Reference
180/445
VIEW EXAMPLES
Consider the view (named all-customer)consisting of branches and their customers.
We can find all customers of the Perryridge branch by writing:
create viewall-customer
as
branch-name, customer-name(depositor account)
branch-name, customer-name(borrower loan)
customer-name(branch-name= Perryridge(all-customer))
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
181/445
UPDATES THROUGH VIEW
Database modifications expressed as views must be
translated to modifications of the actual relations inthe database.
Consider the person who needs to see all loan datain the loan relation except amount. The view givento the person, branch-loan, is defined as:
create view branch-loan as
branch-name, loan-number(loan)
Since we allow a view name to appear wherever arelation name is allowed, the person may write:
branch-loan branch-loan {(Perryridge, L-Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
182/445
TUPLE RELATIONAL CALCULUS
A nonprocedural query language, where eachquery is of the form
{t | P (t) } It is the set of all tuples t such that predicate P is
true fort
t is a tuple variable, t[A] denotes the value of tuplet on attributeA
trdenotes that tuple t is in relationr
P is a formula similar to that of the predicatecalculus
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
183/445
PREDICATE CALCULUS FORMULA
1. Set of attributes and constants
2. Set of comparison operators: (e.g., , , , , ,)
3. Set of connectives: and (), or (v) not ()
4. Implication (): x y, if x if true, then y is true
xyx v y
5. Set of quantifiers: t r (Q(t)) there exists a tuple in t in relationr
such that predicate Q(t) is true
t r(Q(t)) Qis true for all tuples t in relationr
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
184/445
BANKING EXAMPLE
branch (branch-name, branch-city, assets)
customer (customer-name, customer-street,customer-city)
account (account-number, branch-name,balance)
loan (loan-number, branch-name, amount)
depositor (customer-name, account-number) borrower (customer-name, loan-number)
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
185/445
EXAMPLE QUERIES
Find the loan-number, branch-name, andamount for loans of over $1200
Find the loan number for each loan of an amount greater than $1200
Notice that a relation on schema [loan-number] is implicitly definedby the query
{t |sloan (t[loan-number] = s[loan-number] s[amount] 1200)}
{t| tloant[amount] 1200}
Copyright @ www.bcanotes.com
-
7/30/2019 DBMS Basic Reference
186/445
Evolutionof DistributedDatabase Management System
During the 1970s, corporations implementedcentralized database management systems tomeet their structured information needs.
Structured information is usually presented asregularly issued formal reports in a standard
format.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
187/445
The use of centralized database required that corporatedata be stored in a single central site, usually a mainframecomputer.
Data access was provided through serially connecteddumb terminals.
The centralized approach worked well to fill thestructured information needs of corporations, but it felshort when quickly moving events required faster reponsetimes and equally quick access to information.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
188/445
The 1980s gave birth to a series of crucial social andtechnological changes that affected database developmentand design, such as:
Business operations became more decentralizedgeographically.
Competition increased at the global level.
Customer demands and market needs favored adecentralized management style.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
189/445
Rapid technological change low costmainframe.
The large number of applications based on DBMSand the need to protect investments in centralizedDBMS software made the notion of data sharing
attractive.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
190/445
During 1990s the factors we have just described becameeven more firmly pressured. However, how these factorswere addressed was strongly influenced by:
The growing acceptance of internet and, particularly, theWWW, as the platform for data access and distribution. TheWWW is, in effect, the repository for distributed data.
The increased focus on data analysis that led to data miningand warehousing. Although a data warehouse is not usually adistributed database, it does rely on techniques-such as datareplication and distributed queries-that facilitate its dataextraction and integration.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
191/445
The decentralized database is especially desirable becausecentralized database management is subject to problemssuch as:
Performance degradation due to a growing number oremote locations over greater distance.
High Cost associated with maintaining and operatinglarge central (mainframe) database systems.
Reliability problems created by dependence on centrasite.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
192/445
Advantages of DDBMS
Data are located near thegreatestdemandsite:
The data in a distributed database system ar
dispersed to match business requirements.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
193/445
Faster Data Processing:A distributed database system makes it possible tprocess data at several sites, thereby spreading outhe systems workload.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
194/445
Faster Data Access:
End users often work with only a subset of thcompanys data. If such data subsets are locally storeand accessed, the database system will deliver fast
data access than is possible with remotely locatecentralized data.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
195/445
Growth Facilitation:New sites can be added to the network withouaffecting the operations of other sites. Such flexibilitenables the company to expand relatively easily and
rapidly.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
196/445
Improved Communications:Because local sites are smaller and located closer tocustomers, local sites foster better communicationsamong departments and between customers and
company staff. Quicker and better communicationoften help to improve information systems.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
197/445
Reduced operating costs:It is much more cost-effective to add workstations ta network than to update a mainframe system. Thcost of dedicated data communication lines and
mainframe software is reduced proportionallyDevelopment work is done more cheaply and morquickly on low-cost PCs than on mainframe.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
198/445
User Friendly Interface:PCs and workstations are usually endowed with aeasy-to-use GUI. The GUI simplifies use and trainin
for end users.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
199/445
Less danger of a single-pointfailure: In a centralized system, thmainframes failure brings down all the systemoperations. In contrast, a distributed system is able
to shift operations when one of the computefails.The system workload picked up by otheworkstations, because one of the distributed systemfeatures is that data exist at multiple sites.
Copyright @ www.bcanotes.
-
7/30/2019 DBMS Basic Reference
200/445
Proce