Sunteți pe pagina 1din 133

Poonam Railkar DBMS Unit 1

UNIT I
Introduction to Databases

Prepared By:
Poonam Railkar
S.K.N.C.O.E., Pune
Poonam Railkar DBMS Unit 1
UNIT I
INTRODUCTION
Purpose of Database Systems
Database Languages

Poonam Railkar DBMS Unit 1


Relational Databases

Database Design

Data Models

Database Users and Administrators


Poonam Railkar DBMS Unit 1
What is data? (Data,Information,Knowledge)
Data is information that has been translated into a
form that is more convenient to move or process

DBMS contains information about a particular

Poonam Railkar DBMS Unit 1


enterprise
Collection of interrelated data
Set of programs to access the data
An environment that is both convenient and efficient
to use
Simply, DBMS is computer software that allows users
and other software to store and retrieve data in a
structured way.
IN OTHER WORD:
A DBMS is a complex set of software programs
that controls the organization, storage,
management, and retrieval of data in a database.

Poonam Railkar DBMS Unit 1


DATABASE SYSTEM APPLICATIONS:

Banking: all transactions


Airlines: reservations, schedules.
Universities: student information, course registration,

Poonam Railkar DBMS Unit 1


grades
Credit card transactions: purchase on credit cards &
generation of monthly statements
Sales: customers, products, purchases
Telecommunication
Online retailers: order tracking, customized
recommendations
Manufacturing: production, inventory, orders, supply
chain
Human resources: employee records, salaries, tax
deductions
Databases touch all aspects of our lives
Poonam Railkar DBMS Unit 1
PURPOSE OF DATABASE SYSTEMS

In the early days, database applications were


built directly on top of file systems
Typical file processing system is supported by
a conventional operating system.
Permanent record

Require different application programs.

Poonam Railkar DBMS Unit 1


9
Drawbacks of using file systems to store
data: (Advantages of DBMS)
Data redundancy and inconsistency:
o Different programmers create file and
application programs.
Data redundancy : Same data stored multiple times,
duplication of information in different files

Poonam Railkar DBMS Unit 1


For example: Saving-account & checking-account records
oLeads to higher storage and access cost.
Data inconsistency : Several copies of same data may
not agree with each other over a time period.

Difficulty in accessing data


Need to write a new program to carry out each new task
For example: To find name of customers who live within a particular-
code area have to write new application program.
The point here is that conventional file-processing environment do
not allow needed data to be retrieved in convenient and efficient
manner.

Data isolation Data are scattered in various file and


formats.
Writing of new application program is difficult.
Integrity problems
Integrity constraints (e.g. account balance > 500)
Data values must satisfy certain types of consistency

constraints.
Hard to add new constraints or change existing ones

Problem is compounded when constraints involve several

Poonam Railkar DBMS Unit 1


data items from different files.
Atomicity of updates
Failures may leave database in an inconsistent state with
partial updates carried out
In may applications it is crucial that if a failure occurs,

the data to be restored to the consistent state that existed


prior to the failure.
Example: Transfer of funds from one account to another

should either complete or not happen at all i.e. fund


transfer must be atomic.
Concurrent access by multiple users
Concurrent accessed needed for performance
Uncontrolled concurrent accesses can lead to
inconsistencies
Example: Two people reading a balance and
updating it at the same time

Poonam Railkar DBMS Unit 1


Security problems
Hard to provide user access to some, but not all,
data
For example, in a banking system, payroll personnel
need to see only that part of the database that has
information about the various bank employees. They
do not need access to information about customer
accounts.
But since application program are added to the file
processing system in an ad hoc manner, enforcing
such security constraints is difficult.

Database systems offer solutions to all the above problems


DISADVANTAGES
Cost of Hardware and Software
Cost of Staff Training

Poonam Railkar DBMS Unit 1


Appointing Technical Staff

Database Damage
DATA ABSTRACTION
A major purpose of database system is to provide users with an
abstract view of the data.
System hides certain details of how the data are stored and
maintained.
Levels of Abstraction:

Poonam Railkar DBMS Unit 1


Many database-system users are not computer trained,
developers hide the complexity from users through several
levels of abstraction, to simplify users interactions with the
system.
Physical level: describes how data are actually stored.
Logical level: describes what data stored in database, and
the relationships among the data.
type customer = record
customer_id : string;
customer_name : string;
customer_street : string;
customer_city : integer;
end;
Poonam Railkar DBMS
VIEW OF DATA
An architecture for a database system

Unit 1
View of required
information
Type definition

Storage blocks

15
View level:
Highest level abstraction describes only part of the
entire database.
application programs hide details of data types.

Poonam Railkar DBMS Unit 1


Views can also hide information (such as an
employees salary) for security purposes
The view level of abstraction exists to simplify their
interaction with the system.
The system may provide many views for the same
database.
many user require some part of the database.
AN EXAMPLE OF THREE LEVELS

Poonam Railkar DBMS Unit 1


INSTANCES AND SCHEMAS
Similar to types and variables in programming
languages
Schema the logical structure of the database
Example: The database consists of information about a set
of customers and accounts and the relationship between
them)
Analogous to type information of a variable in a program
Physical schema: database design at the physical level.
Logical schema: database design at the logical level.
View schema: subschema, different views of database
Instance the actual content of the database at a
particular point in time
Analogous to the value of a variable

Poonam Railkar DBMS Unit 1


18
DATABASE LANGUAGES
DML : Data Manipulation language
Language for accessing and manipulating the data
organized by the appropriate data model
DDL : Data Definition language
Specification notation for defining the database
schema
DCL: Data control lanquage
TCL: transaction control language

Poonam Railkar DBMS Unit 1


19
DATA DEFINITION LANGUAGE (DDL)
Providesfacilities to specify consistency
constraints.
Example: create table account (
account-number char(10),
balance integer)
DDL compiler generates a set of tables stored in a
data dictionary which contains metadata.
The set of indices to be maintained for each
relations.
A database system consults the data dictionary
before reading or modifying actual data.

Poonam Railkar DBMS Unit 1


20
DATA MANIPULATION LANGUAGE
(DML)
Language for accessing and manipulating the data
organized by the appropriate data model.
Types of access are: Retrival, Insertion, Deletion,
Modification
DML also known as query language
Two classes of languages
Procedural user specifies what data is required and
how to get those data
Declarative (nonprocedural) user specifies what
data is required without specifying how to get those data
SQL is the most widely used query language
The portion of DML that involves information
retrieval is called query language.
Poonam Railkar DBMS Unit 1
21
DATA MODELS :STRUCTURE OF DATABASE
A collection of coceptual tools for describing
Data
Data relationships
Data semantics
Data constraints
Provides way to describe the design of a database at the physical,l ogical,
and view level.
Record Based model
Relational
Network
Hierarchical
Entity-Relationship data model (mainly for database design)
Based on a understanding of real world that consists of collection of basic objects
called entities, and relationships among these objects.
Object-based data models (Object-oriented and Object-relational): extending E-
R model with notation of encapsulation,methods, and object identity.
Semi structured data model (XML):
Permits the specification of data where individual data items of the same type may
have a different sets of attributes.
XML is widely used to represent.

Poonam Railkar DBMS Unit 1


23
Poonam Railkar DBMS Unit 1
Poonam Railkar DBMS Unit 1
RELATIONAL MODEL

Example of tabular data in the relational model

Attributes

Poonam Railkar DBMS Unit 1


26
EXAMPLE

Attribute

Poonam Railkar DBMS Unit 1


Cardinality = 2
tuple/relational
instance SID Name Major GPA
1234 John CS 2.8
5678 Mary EE 3.6

4 Degree

A Schema / Relation
Poonam Railkar DBMS Unit 1
Network model: graph
data is represented as collections of records, and relationships
are represented by sets.
Compared with the relational model, relationships are
explicitly modeled by the sets, which become pointers in the
implementation.
The records are organized as generalized graph structures with

Poonam Railkar DBMS Unit 1


records appearing as nodes (also called segments) and sets as
edges in the graph.
The most popular network DBMS is Computer Associates IDMS/ R.
Poonam Railkar DBMS Unit 1
Hierarchical Model-
Parent-child relationship:
one-to-one
one-to-many

Poonam Railkar DBMS Unit 1


It is a restricted type of network model.
Again, data is represented as collections of records and
relationships are represented by sets.
However, the hierarchical model allows a node to have only one
parent.

Poonam Railkar DBMS Unit 1


A hierarchical model can be represented as a tree graph, with records
appearing as nodes (also called segments) and sets as edges.
Record-based (logical) data models are used to specify the overall
structure of the database and a higher-level description of the
implementation.
Their main drawback lies in the fact that they do not provide
adequate facilities for explicitly specifying constraints on the data
whereas the object-based data models lack the means of logical
structure specification but provide more semantic substance by
allowing the user to specify constraints on the data.
Poonam Railkar DBMS Unit 1
A sample instance of a hierarchical schema.
SEMI STRUCTURED DATA MODEL (XML:
EXTENSIBLE MARKUP LANGUAGE)

Defined by the WWW Consortium (W3C)


Originally intended as a document markup language
not a database language
The ability to specify new tags, and to create nested
tag structures made XML a great way to exchange
data, not just documents
XML has become the basis for all new generation data
interchange formats.
The schema can easily be changed. The data transfer
format may be portable.
A wide variety of tools is available for parsing,
browsing and querying XML documents/data
Poonam Railkar DBMS Unit 1
35
Poonam Railkar DBMS Unit 1
THE ENTITY-RELATIONSHIP MODEL
The entity-relationship (E-R) data model perceives
the real world as consisting of basic objects, called
entities, and relationships among these objects. It was
developed to facilitate database design by allowing
specification of an enterprise schema, which represents
the overall logical structure of a database.
An entity is a thing or object in the real world
that is distinguishable from all other objects.
For example, each person in an enterprise is an entity. An
entity has a set of properties, and the values for some set of
properties may uniquely identify an entity. For instance, a
person may have a person-id property whose value uniquely
identifies that person.
An entity set is a set of entities of the same type
that share the same properties, or attributes.
For example,The set of all persons who are customers at a
given bank.
Poonam Railkar DBMS Unit 1
37
THE ENTITY-RELATIONSHIP MODEL

Attributes-An entity is represented by a set


of attributes, that is descriptive properties
possessed by all members of an entity set.
Example:
customer = (customer_id, customer_name,
customer_street, customer_city )
loan = (loan_number, amount )

Domain the set of permitted values for


each attribute e.g.
Domain of customer name is all character strings.
domain of loan number is set of alphanumeric
strings starting from L
Poonam Railkar DBMS Unit 1
38
ATTRIBUTES (CONTD ..)
An entity can be represented as <Attribute,
Value>
Customer can be shown as
(<name, XYZ>,<id, c-002>, <Address, Wallstreet
>)

Poonam Railkar DBMS Unit 1


39
ATTRIBUTES (CONTD ..)
Attribute types:
Simple and composite attributes.
Attribute not divided into subpart is single attribute.
Example : customer id ..

Composite attributes can be divided into subpart

Example : Name divided into <first name, middle name, last

name>

Poonam Railkar DBMS Unit 1


40
ATTRIBUTES (CONTD ..)
Single-valued and multi-valued attributes
Example: multivalued attribute:
phone_numbers
Derived attributes
Can be computed from other
attributes
Example: age, given date_of_birth

Poonam Railkar DBMS Unit 1


41
MODELING

Anentity set is a set of entities of the same


type that share the same properties.
Example: set of all persons, companies, trees
Adatabase is a collection of entity sets, each of
which contains entities of same type

Poonam Railkar DBMS Unit 1


42
ENTITY SETS CUSTOMER AND LOAN

Poonam Railkar DBMS


customer_id customer_ customer_ customer_ loan_ amount
name street city number

Unit 1
43
RELATIONSHIP SETS

A relationship is an association among several


entities
Example:
Hayes depositor A-102
customer entity relationship set account entity
(Hayes, A-102) depositor

Poonam Railkar DBMS Unit 1


44
Poonam Railkar DBMS
RELATIONSHIP SET BORROWER

Unit 1
45
RELATIONSHIP SETS (CONT.)
The function that an entity plays in a
relationship is called that entitys role
roles are implicit and are not usually specified.
However, they are useful when the meaning of a
relationship needs clarification.

When a same entity set participate in a relation


with different roles then such a relation is called
recursive relation, explicit role names are
necessary to specify how an entity participates in
relationship instance.
For Example: Employees of the bank. Relation
set works_for characterized by (worker, manager)
pairs
Poonam Railkar DBMS Unit 1
47
RELATIONSHIP SETS (CONT.)
An attribute can also
be property of a

Poonam Railkar DBMS Unit 1


relationship set.
(descriptive
attributes): For
instance, the depositor
relationship set
between entity sets
customer and account
may have the attribute
access-date

48
DEGREE OF A RELATIONSHIP SET
Refers to number of entity sets that participate in a
relationship set.
Relationship sets that involve two entity sets are
binary (or degree two). Generally, most
relationship sets in a database system are binary.
Relationship sets may involve more than two entity
sets.
Relationships between more than two entity sets
are rare. Most relationships are binary.
Example: Suppose employees of a bank may have jobs (responsibilities) at multiple branches, with
different jobs at different branches. Then there is a ternary relationship set between entity sets
employee, job, and branch

Poonam Railkar DBMS Unit 1


49
CONSTRAINTS
E-R schema may define certain constraints to which
the contents of the database must confirm.
The different constraints are
Mapping Cardinalities
Keys
Participation Constraints

Poonam Railkar DBMS Unit 1


50
MAPPING CARDINALITY CONSTRAINTS
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 mapping cardinality must


be one of the following types:
One to one
One to many
Many to one
Many to many

Poonam Railkar DBMS Unit 1


51
MAPPING CARDINALITY CONSTRAINTS
One to one
An entity in A is associated with at most one entity in B
and an entity in B is associated with at most one entity in
A.
Example: College governed by - principal
One to many
An entity in A is associated with any number of entities in
B. An entity in B however can be associated with at most
one entity in A.
Example: College employees Staff

Poonam Railkar DBMS Unit 1


52
Poonam Railkar DBMS
MAPPING CARDINALITIES

Unit 1
One to one One to many
Note: Some elements in A and B may not be mapped to any
elements in the other set

53
MAPPING CARDINALITIES
Many-to-one
An entity in A is associated with at most one entity
in B. An entity in B however can be associated with
any number of entities in A.
Example : Students mentored by TG
Many-to-many
An entity in A is associated with any no. of entities
in B, an entity in B is associated with any no of
entities in A
Example : Students learn course

Poonam Railkar DBMS Unit 1


54
Poonam Railkar DBMS
MAPPING CARDINALITIES

Unit 1
Many to one Many to many
Note: Some elements in A and B may not be mapped to any
elements in the other set
55
KEYS
There must be a way to uniquely identify the
entities.
A Key allows to identify a set of attributes that
suffice to distinguish entities from each other.
Keys are also helpful to uniquely identify the
relationship set.

Poonam Railkar DBMS Unit 1


56
KEYS FOR ENTITY SETS
A super key of an entity set is a set of one or more
attributes whose values uniquely determine each entity.
Consider the relation
customer = (customer_id, customer_name,
customer_street, customer_city )
Super key(Customer) = {customer_id, customer_name }

Poonam Railkar DBMS Unit 1


57
KEYS FOR ENTITY SETS
The primary is chosen by Database designer as
primary means of identifying entities within an entity
set.
The primary key should be chosen such that its
attributes are never or rarely changed.

Poonam Railkar DBMS Unit 1


58
KEYS FOR RELATIONSHIP SETS
The combination of primary keys of the participating entity
sets forms a super key of a relationship set.
(customer_id, account_number) is the super key of depositor

Poonam Railkar DBMS Unit 1


59
KEYS FOR RELATIONSHIP SETS
The combination of primary keys of the participating entity
sets forms a super key of a relationship set.
(customer_id, account_number) is the super key of depositor
NOTE: this means a pair of entity sets can have at most one
relationship in a particular relationship set.

Poonam Railkar DBMS Unit 1


60
KEYS FOR RELATIONSHIP SETS
If there are no attributes associated with the
relationship R then
Primary key(E1)U Primary Key(E2) U ..
U Primary key(En)
Describes individual relationship in a set
If the relationship has attributes a1,a2,a3.an
associated with it then
Primary key(E1)U Primary Key(E2) U ..
U Primary key(En) U {a1, a2, a3, an}
Describes individual relationship in a set

Poonam Railkar DBMS Unit 1


61
PARTICIPATION CONSTRAINT TYPE

Total participation : 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 relation ship in R
(existence dependency)
Partial : some entities

Poonam Railkar DBMS Unit 1


63
TOTAL PARTICIPATION
E1

E2 R1
D1
E3
R2 D2
E4
D3
E5 R3
D4
E6
R4
E7

Entity D
Entity E
Poonam RailkarRelationship
DBMS Unit 1
64
PARTIAL PARTICIPATION
E1

E2 R1
D1
E3
R2 D2
E4
D3
E5 R3
D4
E6
R4
E7

Entity E Entity D
Poonam Relationship
Railkar DBMS Unit 1
65
SUMMARY OF SYMBOLS USED IN E-R NOTATION

Poonam Railkar DBMS Unit 1


THE ENTITY-RELATIONSHIP MODEL
Models an enterprise as a collection of entities
and relationships
Entity: a thing or object in the enterprise that is
distinguishable from other objects

Poonam Railkar DBMS Unit 1


Described by a set of attributes
Relationship: an association among several entities
Represented diagrammatically by an entity-
relationship diagram:

67
E-R DIAGRAMS

Poonam Railkar DBMS


Unit 1
Rectangles represent entity sets.
Diamonds represent relationship sets.
Lines link attributes to entity sets and entity sets to relationship sets.

68
E-R DIAGRAM WITH COMPOSITE,
MULTIVALUED, AND DERIVED

Poonam Railkar DBMS


Primary key?
ATTRIBUTES Composite?
Multivalued?
Derived?

Unit 1
Composite
Primary Attribute
Key

Multi-
valued
attribute
Derived
Attribute 69
RELATIONSHIP SETS WITH ATTRIBUTES

Poonam Railkar DBMS Unit 1


70
ROLES

Poonam Railkar DBMS Unit 1


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 connect diamonds to rectangles.
Role labels are optional, and are used to clarify semantics
of the relationship 71
CARDINALITY CONSTRAINTS
We express cardinality constraints by
drawing either a directed line (),
signifying one, or an undirected line (),
signifying many, between the
relationship set and the entity set.
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

Poonam Railkar DBMS Unit 1


72
ONE-TO-MANY RELATIONSHIP
Inthe one-to-many relationship a loan is
associated with at most one customer via
borrower, a customer is associated with several
(loans via borrower

Poonam Railkar DBMS Unit 1


73
MANY-TO-ONE RELATIONSHIPS
Ina many-to-one relationship a loan is
associated with several) customers via
borrower, a customer is associated with at most
one loan via borrower

Poonam Railkar DBMS Unit 1


74
MANY-TO-MANY RELATIONSHIP

A customer is associated with several


(possibly 0) loans via borrower
A loan is associated with customers via
borrower

Poonam Railkar DBMS Unit 1


75
PARTICIPATION OF AN ENTITY SET IN A

Poonam Railkar DBMS


RELATIONSHIP SET
Total participation (indicated by double line): every entity in the entity set participates in at least one

Unit 1
relationship in the relationship set
E.g. participation of loan in borrower is 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
Example: participation of customer in borrower is partial

76
Poonam Railkar DBMS
ALTERNATIVE NOTATION FOR CARDINALITY
LIMITS

Unit 1
Cardinality limits can also express participation constraints

77
Poonam Railkar DBMS
E-R DIAGRAM WITH A TERNARY

Unit 1
RELATIONSHIP

78
CARDINALITY CONSTRAINTS ON TERNARY
RELATIONSHIP
E.g.
an arrow from works_on to job indicates each
employee works on at most one job at any branch.

Poonam Railkar DBMS Unit 1


79
WEAK ENTITY SETS

An entity set that does not have a primary key is


referred to as a weak entity set.

Poonam Railkar DBMS Unit 1


The existence of a weak entity set depends on the
existence of a identifying entity set
The discriminator (or partial key) of a weak entity
set is the set of attributes that distinguishes among
all the entities of a weak entity set.
The relationship associating the weak entity set
with the identifying entity set is called the
identifying relationship
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 Payment numbers are typically sequential

Poonam Railkar DBMS Unit 1


numbers, starting from 1, generated separately for each loan. So
it is discriminator of the payment entity set
Primary key for payment (loan_number, payment_number)
Construct an E-R diagram for a hospital with a set of patients and
a set of medical doctors. Associate with each patient a log of the
various tests and examinations conducted.

Poonam Railkar DBMS Unit 1


EXTENDED E-R FEATURES:
SPECIALIZATION
Top-down design process; we choose sub groupings
within an entity set that are distinctive from other

Poonam Railkar DBMS Unit 1


entities in the set.
These subgroupings become lower-level entity sets
that have attributes or participate in relationships
that do not apply to the higher-level entity set.
Depicted by a triangle component labeled ISA (E.g.
customer is a person).
Attribute inheritance a lower-level entity set
inherits all the attributes of the higher-level entity
set to which it is linked.
Poonam Railkar DBMS Unit 1
SPECIALIZATION EXAMPLE
EXTENDED ER FEATURES:
GENERALIZATION

A bottom-up design process combine a number of entity


sets that share the same features into a higher-level entity set.

Poonam Railkar DBMS Unit 1


Specialization and generalization are simple inversions of each
other; they are represented in an E-R diagram in the same way.
The terms specialization and generalization are used
interchangeably.
SPECIALIZATION AND GENERALIZATION (CONT.)

Can have multiple specializations of an entity set based on


different features.
E.g. permanent_employee vs. temporary_employee, in addition
to officer vs. secretary vs. teller

Poonam Railkar DBMS Unit 1


Each particular employee would be
a member of one of permanent_employee or
temporary_employee,
and also a member of one of officer, secretary, or teller
The ISA relationship also referred to as superclass -
subclass relationship
LATTICE STRUCTURE OF
SPECIALIZATION/ GENERALIZATION

Poonam Railkar DBMS Unit 1


If an entity set is a lower-level entity set in more than one ISA
relationship,then the entity set has multiple inheritance, and the
resulting structure is said to be a lattice.
DESIGN CONSTRAINTS ON A
SPECIALIZATION/GENERALIZATION
Constraint on which entities can be members of a given lower-level
entity set.
condition-defined
Example: all customers over 65 years are members of senior-
citizen entity set; senior-citizen ISA person.
All lower level entities are evaluated on the basis of the same

Poonam Railkar DBMS Unit 1


attribute so this type of generalizaton is said to be attibute-
defined.
E.g. Account type (Saving or checking)

user-defined: user-defined lower-level entity sets are not constrained


by membership condition; rather the database users assigns entities
to given entity set.
Constraint on whether or not entities may belong to more than one
lower-level entity set within a single generalization.
Disjoint
an entity can belong to only one lower-level entity set

For e.g. Account entity for account_type attribute.


Overlapping
an entity can belong to more than one lower-level entity set
For e.g. Employee work team- Manager

The generalization is overlapping if an employee can also be a


customer
DESIGN CONSTRAINTS ON A
SPECIALIZATION/GENERALIZATION (CONT.)

Completeness constraint -- specifies whether or not


an entity in the higher-level entity set must belong to
at least one of the lower-level entity sets within a
generalization.

Poonam Railkar DBMS Unit 1


total : an entity must belong to one of the lower-
level entity sets
partial: an entity need not belong to one of the
lower-level entity sets

specify total generalization in an E-R diagram by


using a double line to connect the box representing the
higher-level entity set to the triangle symbol
AGGREGATION

Consider the ternary relationship works_on, which we saw earlier

Suppose we want to record managers for tasks performed by an


employee at a branch

Poonam Railkar DBMS Unit 1


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 diagram represents:
An employee works on a particular job at a particular branch
An employee, branch, job combination may have an associated
manager
E-R DIAGRAM WITH AGGREGATION

Poonam Railkar DBMS Unit 1


So how do we convert an ER
diagram into a table?? Simple!!
Basic Ideas:

Poonam Railkar DBMS Unit 1


Build a table for each entity set

Build a table for each relationship set if


necessary
Make a column in the table for each attribute in
the entity set
Primary Key
EXAMPLE STRONG ENTITY SET AND ITS
RELATIONAL MODEL

SID Name SSN Name

Student Advisor Professor

Poonam Railkar DBMS Unit 1


Major Dept
GPA

SID SSN
1234 9999
5678 8888

SID Name Major GPA SSN Name Dept


1234 John CS 2.8 9999 Smith Math
5678 Mary EE 3.6 8888 Lee CS
REPRESENTATION OF WEAK ENTITY
SET
Weak Entity Set Cannot exists alone
To build a table/schema for weak entity set
Construct a table with one column for each attribute
in the weak entity set
Remember to include discriminator
Augment one extra column on the right side of the
table, put in there the primary key of the Strong
Entity Set (the entity set that the weak entity set is
depending on)
Primary Key of the weak entity set = Discriminator
+ foreign key
Poonam Railkar DBMS Unit 1
EXAMPLE WEAK ENTITY SET
Age
SID Name Name

Parent owns Children

Poonam Railkar DBMS Unit 1


Age Name Parent_SID
10 Bart 1234
8 Lisa 5678

* Primary key of Children is Parent_SID + Name


Poonam Railkar DBMS Unit 1
The primary key of the loan entity set, on which payment depends, is loan-
number. Thus, we represent payment by a table with four columns labeled loan-
number, paymentnumber, payment-date, and payment-amount
REPRESENTING RELATIONSHIP SET
UNARY/BINARY RELATIONSHIP
For one-to-one relationship w/out total participation
Build a table with two columns, one column for
each participating entity sets primary key. Add

Poonam Railkar DBMS Unit 1


successive columns, one for each descriptive
attributes of the relationship set (if any).
For one-to-one relationship with one entity set having
total participation
Augment one extra column on the right side of the
table of the entity set with total participation, put
in there the primary key of the entity set without
complete participation as per to the relationship.
EXAMPLE ONE-TO-ONE RELATIONSHIP SET
Degree
SID Name ID Code

Student study Major

Poonam Railkar DBMS Unit 1


Major GPA

SID Maj_ID Co S_Degree


9999 07 1234
8888 05 5678

* Primary key can be either SID or Maj_ID_Co


EXAMPLE ONE-TO-ONE RELATIONSHIP
SET Condition
SID Name 1:1 Relationship S/N #

Student Have Laptop

Poonam Railkar DBMS Unit 1


Major GPA Brand

SID Name Major GPA LP_S/N Hav_Cond


9999 Bart Economy -4.0 123-456 Own
8888 Lisa Physics 4.0 567-890 Loan

* Primary key can be either SID or LP_S/N


REPRESENTING RELATIONSHIP SET
UNARY/BINARY RELATIONSHIP
Forone-to-many relationship w/out total
participation

Poonam Railkar DBMS Unit 1


Same thing as one-to-one
Forone-to-many/many-to-one relationship
with one entity set having total
participation on many side
Augment one extra column on the right side of the
table of the entity set on the many side, put in there
the primary key of the entity set on the one side as
per to the relationship.
EXAMPLE MANY-TO-ONE RELATIONSHIP
SET Semester
SID Name N:1 SSN
Relationship

Student Advisor Professor

Poonam Railkar DBMS Unit 1


Major GPA Dept Name

SID Name Major GPA Pro_SSN Semester


9999 Bart Economy -4.0 123-456 Fall 2006
8888 Lisa Physics 4.0 567-890 Fall 2005

* Primary key of this table is SID


REPRESENTING RELATIONSHIP SET
UNARY/BINARY RELATIONSHIP
For many-to-many relationship
Same thing as one-to-one relationship without total

Poonam Railkar DBMS Unit 1


participation.
Primary key of this new schema is the union of the
foreign keys of both entity sets.
No augmentation approach possible
REPRESENTING RELATIONSHIP SET
N-ARY RELATIONSHIP
Intuitively Simple
Build a new table with as many columns as

Poonam Railkar DBMS Unit 1


there are attributes for the union of the
primary keys of all participating entity sets.
Augment additional columns for descriptive
attributes of the relationship set (if necessary)
The primary key of this table is the union of all
primary keys of entity sets that are on many
side
That is it, we are done.
EXAMPLE N-ARY RELATIONSHIP SET
P-Key1
D-Attribute A-Key
E-Set 1

P-Key2 A relationship Another Set

Poonam Railkar DBMS Unit 1


E-Set 2

P-Key3

E-Set 3

P-Key1 P-Key2 P-Key3 A-Key D-Attribute


9999 8888 7777 6666 Yes
1234 5678 9012 3456 No

* Primary key of this table is P-Key1 + P-Key2 + P-Key3


REPRESENTING COMPOSITE
ATTRIBUTE
Relational
Model Indivisibility Rule Applies
One column for each component attribute

Poonam Railkar DBMS Unit 1


NO column for the composite attribute itself

SSN Name

SSN Name Street City


Professor 9999 Dr. Smith 50 1st St. Fake City
8888 Dr. Lee 1 B St. San Jose
Address

Street City
REPRESENTING MULTIVALUE
ATTRIBUTE
For each multivalue attribute in an entity
set/relationship set

Poonam Railkar DBMS Unit 1


Build a new relation schema with two columns
One column for the primary keys of the entity
set/relationship set that has the multivalue
attribute
Another column for the multivalue attributes.
Each cell of this column holds only one value.
So each value is represented as an unique
tuple
Primary key for this schema is the union of all
attributes
EXAMPLE MULTIVALUE ATTRIBUTE
SID Name The primary key for
this table is
Student_SID +
Children Children, the union of
Student
all attributes

Poonam Railkar DBMS Unit 1


Major GPA

Stud_SID Children
1234 Johnson
1234 Mary
SID Name Major GPA
5678 Bart
1234 John CS 2.8
5678 Lisa
5678 Homer EE 3.6
5678 Maggie
REPRESENTING CLASS HIERARCHY
Two general approaches depending on
disjointness and completeness

Poonam Railkar DBMS Unit 1


For non-disjoint and/or non-complete class
hierarchy:
create a table for each super class entity set according to
normal entity set translation method.
Create a table for each subclass entity set with a column for
each of the attributes of that entity set plus one for each
attributes of the primary key of the super class entity set
This primary key from super class entity set is also used as

the primary key for this new table


SSN Name
EXAMPLE
Person

SID Status
Gender

Poonam Railkar DBMS Unit 1


ISA
Student

Major GPA

SSN Name Gender


1234 Homer Male
5678 Marge Female

SSN SID Status Major GPA


1234 9999 Full CS 2.8
5678 8888 Part EE 3.6
REPRESENTING CLASS HIERARCHY
Two general approaches depending on
disjointness and completeness

Poonam Railkar DBMS Unit 1


For disjoint AND complete mapping class
hierarchy:
DO NOT create a table for the super class
entity set
Create a table for each subclass entity set
include all attributes of that subclass entity
set and attributes of the superclass entity set

Simple and Intuitive enough, need example?


SSN Name
EXAMPLE No table created for
superclass entity set

SJSU people

Poonam Railkar DBMS Unit 1


ISA
SID
Student Faculty
Disjoint and
Complete mapping
Major GPA Dept

SSN Name SID Major GPA SSN Name Dept


1234 John 9999 CS 2.8 1234 Homer C.S.
5678 Mary 8888 EE 3.6 5678 Marge Math
REPRESENTING AGGREGATION

Name SSN Name

Student Advisor Professor

Dept
SID

Name
member
Primary Key of Advisor
Dept

SID Code Code


1234 04 Primary key of Dept
Poonam Railkar DBMS Unit 1
5678 08
ALTERNATIVE TERMINOLOGY

Formal Terms Alternative 1 Alternative 2

Relation Table File

Tuple Row Record

Attribute Column Field

Poonam Railkar DBMS Unit 1


114
PROPERTIES OF RELATION
The relation has a name that is distinct from
other relation names in relation schema.
Each cell of the relation contains exactly one

Poonam Railkar DBMS Unit 1


atomic value.
Each attribute has a distinct name
The values of an attribute are all from same
domain
Each tuple is distinct, i.e. no duplication
The order of attributes has no significance.
The order of tuples has no significance.

115
SCHEMA DIAGRAM

A database schema, along with primary key and


foreign key dependencies can be depicted as schema diagram.

Poonam Railkar DBMS Unit 1


Primary keys are highlighted with greys.
Arrows represent foreign key.
VIEWS
A view is a virtual or derived relation that does
not necessarily exist in its own right, but may be
dynamically derived from one or more base
relations.

Poonam Railkar DBMS Unit 1


Base Relation : A named relation corresponding
to an entity in the conceptual schema whose
tuples are physically stored in the database.
Views can be produced on request by a particular
user.
Views are dynamic: The changes to the base
relation that affect views are immediately
reflected in views
PURPOSE OF VIEWS
It provides a powerful and flexible security
mechanism by hiding parts of the database
from certain user. Users are not aware about

Poonam Railkar DBMS Unit 1


the attributes and tuples that are not part of
views
It permits user to access data in a way that is
customized to their needs, so that the same
data can be seen by different users in different
ways at the same time.
It can simplify the complex operations on the
base relations.
FUNCTIONS OF DBMS

Data Storage, Retrieval, and Update.


A User-Accessible Catalog.
Transaction Support.
Concurrency Control Services.
Recovery Services.
Authorization Services.
Support for Data Communication.
Integrity Services.
Services to Promote Data Independence.
Utility Services.
Poonam Railkar DBMS Unit 1
123
COMPONENTS OF DBMS
A database system is partitioned into
modules
Storage manager

Query processor

Transaction management

Data mining and analysis

Poonam Railkar DBMS Unit 1


124
Poonam Railkar DBMS Unit 1
125
Components of DBMS
STORAGE MANAGEMENT
Storage manager
Important
Data are moved between disk storage and main memory
is a program module that provides the interface between the low-
level data stored in the database and the application programs
and queries submitted to the system.
The storage manager is responsible to the following tasks:
Interaction with the file manager
DML statements into low- level file system commands.
Efficient storing, retrieving and updating of data
Issues:
Storage access
File organization
Indexing and hashing

Poonam Railkar DBMS Unit 1


126
STORAGE MANAGEMENT (CONTD.)
The storage manager includes
Authorization and integrity Manager
Checks integrity and authority constraints
File manager
Manages allocation of storage and data structures used to represent
data
Buffer manager
Fetch the data to main memory
Transaction manager
Ensure database remain in consistent state

Data structures of storage manager


Data file: store database itself
Data dictionary : metadata
Indices: provide fast access to data items

Poonam Railkar DBMS Unit 1


127
QUERY PROCESSING
Components:
DDL interpreter
DML Compiler: Also performs query
optimization
Query evaluation engine

Basic Steps
1.Parsing and translation
2.Optimization
3.Evaluation

Poonam Railkar DBMS Unit 1


128
Poonam Railkar DBMS Unit 1
BASIC STEPS IN QUERY PROCESSING (CONT.)
Parsing and translation
translate the query into its internal form. Costructs
parse tree representation of the query. This is then
translated into relational algebra.

Poonam Railkar DBMS Unit 1


Parser checks syntax, verifies relations
Evaluation
The query-execution engine takes a query-evaluation
plan, executes that plan, and returns the answers to the
query.
BASIC STEPS: OPTIMIZATION (CONT.)
Query Optimization: Amongst all equivalent
evaluation plans choose the one with lowest cost.

Poonam Railkar DBMS Unit 1


Cost is estimated using statistical information from
the database catalog
e.g. number of tuples in each relation, size of tuples, etc.
DATABASE USERS
Users are differentiated by the way they expect to
interact with the system
Application programmers
interact with system through DML calls
Sophisticated users
form requests in a database query language
Specialized users
write specialized database applications that do not fit into the
traditional data processing framework
Nave users
invoke one of the permanent application programs that have
been written previously
Examples, people accessing database over the web, bank
tellers, clerical staff
Poonam Railkar DBMS Unit 1
133
DATABASE ADMINISTRATOR
Coordinates all the activities of the database
system; the database administrator has a
good understanding of the enterprises
information resources and needs.
Database administrator's duties include:
Schema definition
Storage structure and access method definition
Schema and physical organization modification
Granting user authority to access the database
Specifying integrity constraints
Monitoring performance and responding to
changes in requirements
Poonam Railkar DBMS Unit 1
134
UNIT I OVER
QUESTION BANK FOR UNIT I
OCT 2012

APRIL 2011
Poonam Railkar DBMS Unit 1
APRIL 2012
Poonam Railkar DBMS Unit 1
APRIL 2010 (2003 COURSE)
Poonam Railkar DBMS Unit 1
OCT 2011
OTHER QUESTIONS
1. Differentiate between a DBMS and a file Processing System
2. Explain in brief different levels of data abstraction

Poonam Railkar DBMS Unit 1


3. Differentiate between physical and logical data independence? Which is easier
to achieve and why?
4. Explain various components of DBMS
5. Write a short note on Database system Architecture.
6. Define metadata and data model.
7. Compare different data models.
8. Discuss Extended ER features.
9. Compare relational, object oriented , ?Hierarchical and network data model.
10. Explain specialization in ER model.
11. Explain strong and weak entity set.
12.What are five main functions of a database administrator?
13.List six major steps that you would take in setting up a database
for a particular enterprise.
14. Consider a two-dimensional integer array of size n ?m that is to be
used in your favorite programming language. Using the array as an
example, illustrate the difference
(a) between the three levels of data abstraction, and (b) between a
schema and instances.

Poonam Railkar DBMS Unit 1


15. Explain the distinctions among the terms primary key, candidate
key, and superkey.
16. Construct an E-R diagram for a car-insurance company whose
customers own one or more cars each. Each car has associated with it
zero to any number of recorded accidents.
17. Construct an E-R diagram for a hospital with a set of patients and
a set of medical doctors. Associate with each patient a log of the
various tests and examinations conducted.
18.A university registrars office maintains data about the following
entities: (a) courses, including number, title, credits, syllabus, and
prerequisites; (b) course offerings, including course number, year,
semester, section number, instructor(s), timings, and classroom; (c)
students, including student-id, name, and program; and (d)
instructors, including identification number, name, department, and
title. Further, the enrollment of students in courses and grades
awarded to students in each course they are enrolled for must be
appropriately modeled.
19. Construct an E-R diagram for the registrars office. Document all assumptions that you
make about the mapping constraints.
20. Explain the difference between a weak and a strong entity set.
21 Define the concept of aggregation. Give two examples of where this concept is useful.
22. Consider an E-R diagram in which the same entity set appears several times. Why is
allowing this redundancy a bad practice that one should avoid whenever possible?
23. Consider a university database for the scheduling of classrooms for final exams. This
database could be modeled as the single entity set exam, with attributes course-name,
section-number, room-number, and time. Alternatively, one or more additional entity sets
could be defined, along with relationship sets to replace some of the attributes of the exam

Poonam Railkar DBMS Unit 1


entity set, as
course with attributes name, department, and c-number
section with attributes s-number and enrollment, and dependent as a weak
entity set on course
room with attributes r-number, capacity, and building
a. Show an E-R diagram illustrating the use of all three additional entity sets
listed.
b. Explain what application characteristics would influence a decision to include
or not to include each of the additional entity sets.

24.When designing an E-R diagram for a particular enterprise, you have several
alternatives from which to choose. What criteria should you consider in making the
appropriate choice?

S-ar putea să vă placă și