Académique Documents
Professionnel Documents
Culture Documents
Unit II
Database System Concepts and Architecture
UNIT II:
2.1 Data Models
2.2 DBMS architecture and Data
independence
2.3 Database user languages
2.4 Database users and Database
administrators
2.5 E-R Model: Entities, Attributes,
Relationships, Keys, Cardinalities,
Participation constraints, E-R Diagram
2.6 Data Dictionary
Data Models
Type:
E-R Model
Relational Model
Object-Oriented Data Model
Object-Relational Data Model
Network Data Model
Hierarchical Data Model
Data Models
Type:
E-R Model
Relational Model
Object-Oriented Data Model
Object-Relational Data Model
Network Data Model
Hierarchical Data Model
Entity-Relationship Model
E-R data model is based on a perception of
real world that consists of a collection of
basic objects, called entities, and of
relationships among these objects.
E-R models separate the information required by
business from the activities performed within a
business. Although business can change their
activities, the type of information tends to remains
constant. Therefore, the data structures also tend
to be constant.
Graphical representation:
Rectangles - entity sets
Ellipses attributes
Diamonds relationships among entity sets
Lines - link
Employee
Department
Read this relationship first from left to right, and then from right to left
Employee
Department
Employee
Department
INSTRUCTOR
Code
Name
Fee
Duration
Name
Phone number
STUDENT
Name
Phone number
INSTRUCTOR
Taught by
Taken by
Enrolled in
STUDENT
Name
Phone number
The teacher of
Name
Phone
Participation Constraints
o The participation of an entity set E in a
relationship set R is said to be Total if every
entity in E participates in at least one
relationship in R.
o If only some entities in E participate in
relationships in R, the participation of entity
set E in relationship R is said to be Partial.
Database
Development
Process
ER
entity type
Relational
relation/table
entity
attribute
relationship
key attribute
inheritance
tuple/row
attribute/column
foreign key
primary key
foreign key
Entity Types
Entity types are similar to classes,
they describe potential objects (entities)
that will appear in the database.
Weak entity types describe dependent
entities,
entities that depend on other entities for
identity.
EMPLOYEE
DEPENDENT
Entity
Weak Entity
SSN
Date
Attribute
Key Attribute
Partial Key
Attribute
SSN
Date
Attribute
Key Attribute
Partial Key
Attribute
EMPLOYEE
Phone
EID
Name
DEPENDENT
Age
Relationships
Relationships diamonds
Identifying relationship double diamond
WorksOn
DependentOf
Relationship
Identifying
Relationship
Relationships
Relationships indicate a meaningful connection
between two entity types
Relationships may have attributes,
but they cannot have key attributes.
Identifying relationships connect a weak entity
type
to some other entity type
indicates where the weak entity gets a key
to complete its own partial key
WorksOn
DependentOf
Relationship
Identifying
Relationship
Example Schema
DEPENDENT
DependentOf
Name
Age
EID
Name
EMPLOYEE
Phone
Name
WorksOn
PROJECT
StartDate
Budget
Participation Constraints
Total participation double or thick line
indicates required participation
WorksFor
DEPARTMENT
Total Participation
EMPLOYEE
WorksOn
Partial Participation
PROJECT
Participation Constraints
Arrowheads can be used to indicate
an upper bound of 1 for participation
Cardinality Ratios
Cardinality ratios specify
the maximum number of relationship instances
that an entity may participate in
EMPLOYEE
Manages
DEPARTMENT
1:1 ratio
EMPLOYEE
WorksFor
DEPARTMENT
n:1 ratio
EMPLOYEE
WorksOn
n:m ratio
PROJECT
Structural Constraints
Structural constraints specify the minimum and
maximum number of relationship instances
that an entity may participate in
EMPLOYEE
(1,1)
WorksFor
(4,n)
DEPARTMENT
(0,1)
Manages
(1,1)
DEPARTMENT
Relational Roles
It is sometimes convenient
to name an entitys role in a relationship.
particularly useful in recursive relationships
removes ambiguity in direction of relationship
Supervision
supervisor
supervisee
(0,N)
(0,1)
EMPLOYEE
Recursive Relationship
Supervision
supervisor
supervisee
(0,N)
(0,1)
EMPLOYEE
1 = supervisor
2 = supervisee
Notation Summary
Keys:
o No two entities in an entity set are allowed to
have exactly the same value for all attributes.
o A keys allows us to identify a set of attributes
that suffice to distinguish entities from each
other.
Data Models
Type:
E-R Model
Relational Model
Object-Oriented Data Model
Object-Relational Data Model
Network Data Model
Hierarchical Data Model
Edgar F. Codd
schema
defined by the DB designer
generally fixed once defined *
database state
changes over time due to user updates
RDM Schemas
External View
relation
specifications
mapping from
relations to
storage layout (files)
External View
Conceptual Schema
Internal Schema
External View
query processor
security manager
concurrency manager
index manager
database designer
enters the
definition of
relation schemas
SQL DDL = relation
definition language
(CREATE TABLE)
users of
the data
data
definition
processor
relation
schemas
relations
Relation Schemas
A relation is defined by
a name and
a set of attributes
set of
attributes
StockItem
Attribute
ItemID
Description
Price
Taxable
attribute
names
Domain
string(4)
string(50)
currency/dollars
boolean
attribute
domains
Definition: Relation
A relation is denoted by r(R)
R is the name of the relation schema for the
relation
Definition: Relation
Each tuple is an ordered list of n values
t = < v1, v2, , vn >
n is the degree of R
t[Ai]
or
vi
t.Ai
Alternate notations:
ith value of tuple t is also referred to as
Example Relation
r(STOCKITEM) =
{ < I119, "Monopoly", $29.95, true >,
< I007, "Risk", $25.45, true >,
< I801, "Bazooka Gum", $0.25, false > }
t2 = < I007, "Risk", $25.45, true >
t2[Price] = t2.Price = $25.45
t2[Price] dom(Price) = currency/dollars
Characteristics of Relations
A relation is a set
tuples are unordered
no duplicate tuples
Characteristics of Relations
atomic = non-structured
(similar to primitive types in C++)
implication:
no nested relations or other complex data
structures
Example Schema
Example
State
CONSTRAINTS
Constraints
Constraints are restrictions on legal relation states
they add further semantics to the schema
Domain constraints
vi
dom(Ai)
Non-null constraints
the domain of some attributes may not include null,
implying that a value for that attribute
is required for all tuples
Key Constraints
By definition, all tuples in a relation are unique
Often, we want to restrict tuples further such
that some subset of the attributes
is unique for all tuples
Example: in the StockItem relation,
no ItemID should appear in more than one
tuple
ItemID is called a key attribute
key
key
candidate key
Example Keys
STOCKITEM( ItemId, Description, Price, Taxable )
superkeys:
(ItemId), (Description), (ItemId, Description)
keys:
(ItemId), (Description)
candidate keys:
(ItemId), (Description)
primary key:
(ItemId)
(assumes that
Description is
unique for all items)
Inserting Tuples
r1(STORESTOCK) =
r2(STORESTOCK) =
Deleting Tuples
r2(STORESTOCK) =
r3(STORESTOCK) =
Updating Tuples
r3(STORESTOCK) =
r3(STORESTOCK) =
Enforcing Constraints
constraint enforcement:
ensuring that no invalid database states can
exist
invalid state: a state in which a constraint is
violated
Possible ways to enforce constraints:
reject any operation that causes a violation, or
allow the violating operation and then attempt
to correct the database
Schema for
Airline
Database
EMPLOYEE(Ssn, Name, )
FK
AJB(x, y, p, q, r)
or
AJB(x, y, p, q, r)
BANK_BRANCH(Bank_code, Branch_No,
Addr)
BANK_BRANCH(Bank_code, Branch_No,
Addr)
ACCOUNT(Acct_no, Type,
Balance, Bank, Branch)
Data Models
Type:
E-R Model
Relational Model
Object-Oriented Data Model
Object-Relational Data Model
Network Data Model
Hierarchical Data Model
EER
Class
Entity type
Object
Entity instance
Association
Relationship
Inheritance of
attributes
Inheritance of
attributes
Inheritance of
behavior
No representation of
behavior
Data Models
Type:
E-R Model
Relational Model
Object-Oriented Data Model
Object-Relational Data Model
Network Data Model
Hierarchical Data Model
Data Models
Type:
E-R Model
Relational Model
Object-Oriented Data Model
Object-Relational Data Model
Network Data Model
Hierarchical Data Model
Data Models
Type:
E-R Model
Relational Model
Object-Oriented Data Model
Object-Relational Data Model
Network Data Model
Hierarchical Data Model
Schema Diagram:
An illustrative display of (most aspects of) a
database schema.
Schema Construct:
A component of the schema or an object
within the schema, e.g., STUDENT, COURSE.
Database Schema
vs. Database State
Database State:
Refers to the content of a database at a
moment in time.
Valid State:
A state that satisfies the structure and
constraints of the database.
Database Schema
vs. Database State (continued)
Distinction
The database schema changes very
infrequently.
The database state changes every time the
database is updated.
Three-Schema Architecture
Proposed to support DBMS
characteristics of:
Program-data independence.
Support of multiple views of the data.
Three-Schema Architecture
Defines DBMS schemas at three levels:
Internal schema at the internal level to describe
physical storage structures and access paths (e.g
indexes).
Typically uses a physical data model.
Conceptual schema at the conceptual level to describe
the structure and constraints for the whole database
for a community of users.
Uses a conceptual or an implementation data
model.
External schemas at the external level to describe the
various user views.
Usually uses the same data model as the conceptual
schema.
Three-Schema Architecture
Mappings among schema levels are
needed to transform requests and data.
Programs refer to an external schema, and
are mapped by the DBMS to the internal
schema for execution.
Data extracted from the internal DBMS
level is reformatted to match the users
external view (e.g. formatting the results of
an SQL query for display in a Web page)
Data Independence
Logical Data Independence:
The capacity to change the conceptual schema
without having to change the external schemas
and their associated application programs.
DBMS Languages
Data Definition Language (DDL)
Data Manipulation Language (DML)
High-Level or Non-procedural Languages:
These include the relational language SQL
May be used in a standalone way or may be
embedded in a programming language
DBMS Languages
Data Definition Language (DDL):
Used by the DBA and database designers to
specify the conceptual schema of a database.
In many DBMSs, the DDL is also used to define
internal and external schemas (views).
In some DBMSs, separate storage definition
language (SDL) and view definition
language (VDL) are used to define internal
and external schemas.
SDL is typically realized via DBMS commands
provided to the DBA and database designers
DBMS Languages
Data Manipulation Language (DML):
Used to specify database retrievals and updates
DML commands (data sublanguage) can be
embedded in a general-purpose programming
language (host language), such as COBOL, C,
C++, or Java.
A library of functions can also be provided to access
the DBMS from a programming language
Types of DML
High Level or Non-procedural
Language:
For example, the SQL relational language
Are set-oriented and specify what data to
retrieve rather than how to retrieve it.
Also called declarative languages.
DBMS Interfaces
Stand-alone query language interfaces
Example: Entering SQL queries at the DBMS
interactive SQL interface (e.g. SQL*Plus in
ORACLE)
Other Tools
Data dictionary / repository:
Used to store schema descriptions and
other information such as design decisions,
application program descriptions, user
information, usage standards, etc.
Active data dictionary is accessed by DBMS
software and users/DBA.
Passive data dictionary is accessed by
users/DBA only.
Other Tools
Application Development Environments
and CASE (computer-aided software
engineering) tools:
Examples:
PowerBuilder (Sybase)
JBuilder (Borland)
JDeveloper 10G (Oracle)
DROP
RENAME
Data dictionary
Data definition
Data organization
Data updating
Data processing
Data retrieval
Data reporting
Data base
language
EXAMPLE OF AN SQL
QUERY
SAMPLE DATA
DICTIONARY REPORT
AN ACCESS QUERY