Lesson08 IntroDatabases PDF
Lesson08 IntroDatabases PDF
Contents
Introduction to Databases
Abstraction, Schemas, and Views
Data Models
Database Management System (DBMS) Components
Entity Relationship Data Model
E-R Diagrams
Database Design Issues
Constraints
Converting E-R Model to Schemas
Physical level
Bad design
SQL
SQL: widely used non-procedural language
Example: Find the name of the customer with customer-id 192-83-
7465
select customer.customer_name
from customer
where customer.customer_id = 192-83-7465
Example: Find the balances of all accounts held by the customer
with customer-id 192-83-7465
select account.balance
from depositor, account
where depositor.customer_id = 192-83-7465 and
depositor.account_number = account.account_number
Application programs generally access databases through
one of
Language extensions to allow embedded SQL
Application program interface (e.g., ODBC/JDBC) which allow SQL
queries to be sent to a database
Query Processing
1. Parsing and
translation
2. Optimization
3. Evaluation
Database Users
Users are differentiated by the way they are expected 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
Naive users invoke one of the permanent application
programs that have been written previously by an
application programmer
Examples: E-shopping, Internet banking, University clerical staff
accessing student database
customer loan
AE3B33OSD Lesson 8 / Page 20 Silberschatz, Korth, Sudarshan S. 2007
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
Attribute types:
Simple and composite attributes
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
Composite Attributes
Composite
attributes
Component
attributes
customer loan
relationship set
owe
owe
AE3B33OSD Lesson 8 / Page 24 Silberschatz, Korth, Sudarshan S. 2007
Degree of a Relationship Set
Refers to number of entity sets that participate in a
relationship
Relationship sets that involve two entity sets are binary
(or degree two).
Most relationship sets in a database system are binary.
Relationship sets may involve more than two entity sets
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
Relationships between more than two entity sets are
rare. Most relationships are binary
We will mostly speak about binary relationships
Note: Some elements in A and B may not be mapped to any elements in the other set
E-R Diagrams
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
Many-To-One Relationships
In a many-to-one relationship a loan is associated
with several (including 0) customers via borrower, a
customer is associated with at most one loan via
borrower
Design Issues
Use of entity sets vs. attributes
Choice 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 to describe an
action that occurs between entities
Binary versus n-ary relationship sets
Although it is possible to replace any non-binary (n-ary, for n > 2)
relationship set by a number of distinct binary relationship sets, a
n-ary relationship set shows more clearly that several entities
participate in a single relationship.
Placement of relationship attributes
Is it reasonable to add the intended attribute to the relationship
set?
Redundancy of Schemas
Many-to-one and one-to-many relationship sets that are
total on the many-side can be represented by adding an
extra attribute to the many side, containing the primary
key of the one side
Example: Instead of creating a schema for relationship set
account_branch, add an attribute branch_name to the schema
arising from entity set account
End of Lesson 8
Questions?