part 2 dbms models
Post on 13-Nov-2014
123 Views
Preview:
TRANSCRIPT
©Silberschatz, Korth and Sudarshan1.1Database System Concepts
PART-2 PART-2 DATABASES MODELSDATABASES MODELS
{ Relational,Heirarchical,Network,E-R Model}{ Relational,Heirarchical,Network,E-R Model}&&
RELATIONAL ALGEBRA OPERATIONSRELATIONAL ALGEBRA OPERATIONS
DBMS by Er. K.S.Dhindsa © 2006
Lecture Series By :Lecture Series By :Er. Kanwalvir Singh DhindsaEr. Kanwalvir Singh DhindsaDeptt. of CSE & ITDeptt. of CSE & IT
For downloading slides of DBMS, Visit :For downloading slides of DBMS, Visit :
WEBSITE : WEBSITE : www.dhindsa.infowww.dhindsa.info Homepage: Homepage: http://groups.google.com/group/DBMS-2006http://groups.google.com/group/DBMS-2006
©Silberschatz, Korth and Sudarshan1.2Database System Concepts
Types of Databases Types of Databases
• Relational DBMS
• Hierarchical DBMS
• Network DBMS
• Object-Oriented Databases
{ Advantages,Disadvantages & Comparisons }
©Silberschatz, Korth and Sudarshan1.3Database System Concepts
Relational Database ModelRelational Database Model
• Represents data as two-dimensional tables called relations• Relates data across tables based on common data element
Examples: DB2, Oracle, MS SQL Server
©Silberschatz, Korth and Sudarshan1.4Database System Concepts
• Select: Creates subset of rows that meet specific criteria
• Join: Combines relational tables to provide users with information
• Project: Enables users to create new tables containing only relevant information
Three Basic Operations in a Three Basic Operations in a Relational DatabaseRelational Database
©Silberschatz, Korth and Sudarshan1.5Database System Concepts
Three Basic Operations in a Relational Three Basic Operations in a Relational DatabaseDatabase
SELECT
PROJECT
JOIN
©Silberschatz, Korth and Sudarshan1.6Database System Concepts
Hierarchical Database ModelHierarchical Database Model
• It is a pointer based model
• Organizes data in a tree-like structure
• Stores data in tables and views relationships as links
• Supports one-to-many parent-child relationships
• Prevalent in large legacy systems
©Silberschatz, Korth and Sudarshan1.7Database System Concepts
Network DBMSNetwork DBMS Depicts data logically as many-to-many relationships
Organizes data in tables and views relationships as links
It is also a pointer based model
Organizes data in arbitrary graphs
©Silberschatz, Korth and Sudarshan1.8Database System Concepts
Hierarchical and Network DBMSHierarchical and Network DBMS
Some of the Disadvantages
Outdated
Complex pointer based organization
Less flexible compared to RDBMS
Lack support for ad-hoc and English language-like queries
©Silberschatz, Korth and Sudarshan1.9Database System Concepts
Object-Oriented DatabasesObject-Oriented Databases
Object-oriented DBMS: Stores data and procedures as objects
that can be retrieved and shared automatically
Object-relational DBMS: Provides capabilities of both object-
oriented and relational DBMS
©Silberschatz, Korth and Sudarshan1.10Database System Concepts
Types of Databases Types of Databases : : SummarySummary
• In a relational database the data is perceived as tables (and
nothing but tables) by the user
• The relational operators available are used to manipulate the
data in the tables
©Silberschatz, Korth and Sudarshan1.11Database System Concepts
Introduction to Data ModelingIntroduction to Data Modeling
What is Data Modeling?
A technique for analyzing requirements and for identifying the
information needs of an organization
• Why Data Modeling is important?
Cannot build a good system without knowing what data needs to be
captured and how it needs to be organized
©Silberschatz, Korth and Sudarshan1.12Database System Concepts
• An Overview :
• Conceptual representation of the data structures required by a
database
• Data structures include the data objects, the associations between data
objects, and the rules which govern operations on the objects
• Focuses on what data is required and how it should be organized
• Independent of hardware or software constraints
• Data Model And Database Design:
• Data Model is to a Database what a Building plan or a blueprint is to a
Building
• A Database Design translates a data model into a database
• A Data Model is the conceptual design of a database
Introduction to Data ModelingIntroduction to Data Modeling
©Silberschatz, Korth and Sudarshan1.13Database System Concepts
E-R ModelingE-R Modeling
Originally proposed by Peter Chen (1976)
Views the real world as entities and relationships
Key component is the E-R Diagram
Most common model used for designing relational databases
• Entity- An identifiable object or concept of significance
• Attribute- Property of an entity or relationship
• Relationship- An association between entities
• Identifier- one or more attributes identifying an instance
(occurrence) of an entity
©Silberschatz, Korth and Sudarshan1.14Database System Concepts
Entity relationship diagramEntity relationship diagram
©Silberschatz, Korth and Sudarshan1.15Database System Concepts
has works for• Dept No.
• Name
• Name• Emp Id.
Entity
Relationship Attributes
EMPLOYEEDEPARTMENT
Identifier
E-R ModelingE-R Modeling
©Silberschatz, Korth and Sudarshan1.16Database System Concepts
• Entity
• Any object or thing of significance about which data needs to be collected
and maintained
• Could be
• Concrete or tangible like a person or a building
• Abstract like a concept or activity
• Analogous to a table in a relational database
Examples: EMPLOYEES, PROJECTS, INVOICES
E-R ModelingE-R Modeling
©Silberschatz, Korth and Sudarshan1.17Database System Concepts
• Entity Rules
• Any thing or object may only be represented by one entity.
• Each entity must be uniquely identifiable. Each instance (occurrence)
of an entity must be separate and distinctly identifiable from all other
instances of that type of entity.
• Entity Classification and Types
• Classified as dependent and independent
• An independent entity is one that does not rely on another for
identification
• A dependent entity is one that relies on another for identification
• In some, methodologies, the terms used are strong and weak,
respectively
E-R Modeling
©Silberschatz, Korth and Sudarshan1.18Database System Concepts
• Entity Classification and Types • Fundamental entity - An entity that exists and is of interest in its own right.
Generally, most entities in the data model are fundamental entities.
Example :Department and Employee are both fundamental entities
• Special Entity Types
• Associative Entity - Used to associate two entities in order to reconcile
a many-many relationship
• Sub-type/super-type- Used in generalization hierarchies to represent a subset
of instances of their of parent entity
E-R Modeling
©Silberschatz, Korth and Sudarshan1.19Database System Concepts
ORDER ITEMORDER LINEappears onfor ahas
belongs to
E-R ModelingE-R Modeling
Example of Associative entity :
©Silberschatz, Korth and Sudarshan1.20Database System Concepts
• Generalization Hierarchies
• Generalization occurs when two or more entities
represent categories of the same real-world object.
Example: CAR and TRUCK represent categories of the
same entity, VEHICLE is the super-type; CAR and
TRUCK would be the subtypes
E-R Modeling
©Silberschatz, Korth and Sudarshan1.21Database System Concepts
• Generalization Hierarchies
• Form of abstraction that specifies that two or more entities that
share common attributes can be generalized into a higher level
entity type called a super-type or generic entity.
• The lower-level of entities become the sub-type, or categories,
to the super-type. Sub-types are dependent entities.
E-R Modeling
©Silberschatz, Korth and Sudarshan1.22Database System Concepts
• Generalization Hierarchies
• Example: Entity PERSON represents people at a university. It has three subtypes,
FACULTY, STAFF, and STUDENT. A STAFF member could also be registered as a
STUDENT
E-R Modeling
PERSON
FACULTYSTUDENT STAFF
©Silberschatz, Korth and Sudarshan1.23Database System Concepts
• Generalization Hierarchies - NestedGeneralization Hierarchies - Nested
E-R Modeling
PERSON
FACULTYSTUDENT
UNDERGRAD GRADUATE
©Silberschatz, Korth and Sudarshan1.24Database System Concepts
E-R Modeling
• Attribute
• Attributes describe a property or a characteristic of an entity
• A particular instance of an attribute is a value.
For example “John Doe” is one value of the attribute Name.
• Simple attribute
Contains only atomic values
• Composite attribute
Has component attributes
Student Name
FName
LName
MI
DOB
Simple Composite
©Silberschatz, Korth and Sudarshan1.25Database System Concepts
E-R Modeling
• Attribute Classification• Single-valued attribute
• Has exactly one value per instance of an entity
• Multi-valued attribute• Contains repeating values per instance of an entity
Module
Student
Math
PhysicsId
Multi-valued
Single-valued
©Silberschatz, Korth and Sudarshan1.26Database System Concepts
E-R Modeling
• Identifiers and Descriptors
• Attributes can be classified as identifiers or descriptors
• Identifiers, more commonly called keys, uniquely identify an
instance of an entity.
• A descriptor describes a non-unique characteristic of an entity
instance.
An Example :
Entity: Employee
Unique Identifier: Employee No.
Descriptor: Name, DOJ, DOB
©Silberschatz, Korth and Sudarshan1.27Database System Concepts
E-R Modeling
• Relationship • Represents an association between two or more entities
Examples
- Employees work for Departments
- Departments manage one or more projects
- Employees are assigned to projects
- Projects have sub-tasks
- Orders have line items
• Defined in terms of:
- Degree
- Connectivity
- Cardinality
- Direction
- Type
- Existence
©Silberschatz, Korth and Sudarshan1.28Database System Concepts
• Degree
• Number of entities associated with the relationship
• Binary relationships, the association between two entities is the
most common type in the real world.
Connectivity
• Mapping of associated entity instances in the relationship.
• The values of connectivity are "one" or "many”.
• Cardinality
Actual number of related occurrences for each of the two entities.
The basic types of connectivity for relations are: one-to-one, one-to-many,
and many-to-many.
E-R Modeling
©Silberschatz, Korth and Sudarshan1.29Database System Concepts
E-R Modeling
• Connectivity and Cardinality
• A one-to-one (1:1) relationship is when at most one instance of a entity A Is
associated with one instance of entity B.
FOR EXAMPLE:
Employees in the company are each assigned their own office. For each
Employee there exists a unique office and for each office there exists a
unique employee.
• A one-to-many (1:N) relationships is when for one instance of entity A,
there are zero, one, or many instances of entity B, but for one instance of
entity B, there is only one instance of entity A.
An example :
A department has many employees, each employee is assigned to one department
©Silberschatz, Korth and Sudarshan1.30Database System Concepts
E-R Modeling
• Connectivity and Cardinality
• A many-to-many relationship, is when for one instance of entity A, there
are zero, one, or many instances of entity B and for one instance of entity B
there are zero, one, or many instances of entity A.
An example is:
Employees can be assigned to no more than two projects at the
same time; Project must have assigned at least three employees
©Silberschatz, Korth and Sudarshan1.31Database System Concepts
E-R Modeling
• Entities• Represented by labeled rectangles• The label is the name of the entity• Entity names should be singular nouns.
• Relationships• Represented by a solid line connecting two
entities. • Name written above the line• Relationship names should be verbs
Employee
Department
Works for
©Silberschatz, Korth and Sudarshan1.32Database System Concepts
E-R Modeling
• Attributes• Listed inside the entity rectangle • Underlined • Names should be singular nouns
• Cardinality • Many is represented by a line ending in a
crow's foot. If omitted, cardinality is one
• Existence • Represented by placing a circle or a
perpendicular bar on the line
Employee•EmpID
•EmpName
©Silberschatz, Korth and Sudarshan1.33Database System Concepts
E-R Modeling : Assignment
How to create an E-R Model from Requirements ?
Step 1: Identify Entities• Entities are things people talk about, record information about and do work
on – by definition
• Any keyword (noun) is a candidate
• Identify generic object from reference to instances or occurrences
• Combine synonyms to represent a single entity
An Example : Purchase Order - System Requirements
A buyer creates a purchase order (PO) as and when the need arises. A PO is for a
Specific vendor. A PO has one or more line items. A buyer cannot create a PO of
Total value more than his approval limit. A PO can be sent to the vendor by mail,
fax, EDI. A PO can be canceled before it is submitted. A PO can be linked to a
sales order…
©Silberschatz, Korth and Sudarshan1.34Database System Concepts
Step 1: Identify Entities• Entities
Purchase Order (PO)Buyer?VendorLine ItemsSales OrderApproval Limit?
• Buyer characterizes a PO• Approval Limit characterizes a Buyer
What does it tell us?
• Approval Limit is not an entity• Buyer is an entity• Approval Limit is an attribute of the entity Buyer
E-R Modeling
©Silberschatz, Korth and Sudarshan1.35Database System Concepts
Step 2: Identify Relationships
Look for phrases describing a link between two things or objects
Verbs relating two nouns often suggest relationships
e.g. A buyer creates a purchase order, A purchase order has one
or more
Lines
Requirements may or may not contain information regarding
degree,
existence, cardinality of a relationship up front
Further questioning may need to be done to determine the above
E-R Modeling
©Silberschatz, Korth and Sudarshan1.36Database System Concepts
Step 2: Identify Relationships
Grid Technique
PO
PO replaced by Buyer
Buyer creates a is approver of
Vendor
Vendor supplies against a
- - Line
Line belongs to a - created for item supplied by
-
E-R Modeling
©Silberschatz, Korth and Sudarshan1.37Database System Concepts
Step 2 : Identify Relationships
• Analyzing Existing Systems (Files, Databases)
• Look for -
Pointers
Foreign Keys
Repeating Groups
Structured Codes
• All of the above imply relationships
E-R Modeling
©Silberschatz, Korth and Sudarshan1.38Database System Concepts
• Step 3 : Identify Attributes
• An attribute is any detail that server to identify, classify, quantify or
express the the state of an entity
• Ask the following question for each entity “What information do you need
to know or hold about …?”
• Potential attributes are easily found by examining paper forms
E-R Modeling
©Silberschatz, Korth and Sudarshan1.39Database System Concepts
• Step 3: Identify Attributes
E-R Modeling
Purchase Order No __________
Buyer _________ Vendor ___________
Date Created ______
No Item Quantity Value___ ___________ ______ _____________ ___________ ______ _____________ ___________ ______ __________
Shipping AddressStreet _________City __________Zip _______ Total Value
______
Example Purchase Order Form• Purchase Order No
• Vendor
• Buyer
• Date Created
• Item?
• Address
• City
• State
• Zip
• Total Value?
©Silberschatz, Korth and Sudarshan1.40Database System Concepts
E-R Model of the Purchase Order Example
PURCHASE ORDER
VENDOR
BUYERcreates
created by
supplies against
created for a
LINE
has
belongs to
ITEM
created for
exists on
E-R Modeling
©Silberschatz, Korth and Sudarshan1.41Database System Concepts
Major Modeling Techniques
Peter Chen’s original entity/relationship diagrams
Information Engineering
Richard Barker’s notation, used by Oracle corporation
IDEF1X
Object Role Modeling
Unified Modeling Language (UML)
Extensible Markup Language (XML)
E-R Modeling
©Silberschatz, Korth and Sudarshan1.42Database System Concepts
E-R Modeling
• Major Modeling Techniques
• Data Modeling has sets of two audiences:
• User community - Uses the models to verify that the analysts understand
their environment and their requirements.
• Systems designers - Use the business rules implied by the models as the
basis for their design of computer systems.
• Different techniques are better for one audience or the other.
• All techniques are fundamentally the same
• Differences are mainly in syntactic or notational
©Silberschatz, Korth and Sudarshan1.43Database System Concepts
Relational ModelRelational Model
Formally introduced by Dr. E. F. Codd in 1970
Represents data in the form of two-dimensional tables
A relational database is a collection of two-dimensional tables
Basic understanding of the model needed to design and use
relational databases
©Silberschatz, Korth and Sudarshan1.44Database System Concepts
Tables, Columns and Rows
Relationships and Keys
Data Integrity
Normalization
What is a table?
• Represents some real-world person, place, thing, or event
• Two-dimensional
• Columns
• Rows
Relational ModelRelational Model
Course No. Course_Title C_Hrs. Dept. C
CIS 120 Intro to CIS 4 Cis
MKT 333 Intro to Mkting 3 MKT
ECO 473 Labor Econ. 3 ECO
BA201 Intro to Stat. 5 ECOCIS 345 Intro to Dbase 4 CIS
©Silberschatz, Korth and Sudarshan1.45Database System Concepts
Table
• Columns represent a property of the person, place, thing or event that the table represents
• Rows represent an occurrence or instance of what the table represents
• A data value is stored in the intersection of a row and column
• Each named column has a domain, which is the set of values that may appear in that column
Relational ModelRelational Model
Empid Name Level DOJ Manager
101412 John M3 4/10/98 101667
102235 Nancy M4 1/23/01 101412
101398 Mike S1 8/15/95 101667
101667 Jeff M2 6/2/96 100351
103893 Cindy M3 7/17/95 101284
101116 Rahul S2 2/20/00 101412
102739 Scott C1 4/13/01 101667
Employee
©Silberschatz, Korth and Sudarshan1.46Database System Concepts
Relational ModelRelational Model
In this document Formal Terms Many Database Manuals
Table Relation Table
Column Attribute Field
Row Tuple Record
Table - Terminology
©Silberschatz, Korth and Sudarshan1.47Database System Concepts
Relational ModelRelational Model
• Salient features of a relational table
• Values are atomic (1NF)
• Column values are of the same kind (Domain)
• Each Row is unique (Primary Key)
• Sequence of columns is insignificant
• Sequence of rows is insignificant
• Each column must have a unique name
• Relationships and Keys• Keys - Fundamental to the concept of relational databases
• Relationship - An association between two or more tables defined by
means of keys
©Silberschatz, Korth and Sudarshan1.48Database System Concepts
Relational ModelRelational Model
• Primary Key
• Column or a set of columns that uniquely identify a row in a table
• Must be unique and must have a value
• Foreign Key
• Column or set of columns which references the primary key or a
unique key of another table
• Rows in two tables are linked by matching the values of the foreign
key in one table with the values of the primary key in another
•EMP_ID in table EMPLOYEE is the primary key
• DEPT_NO in table DEPARTMENT is the primary key
• DEPT_NO in table EMPLOYEE is a foreign key
Examples
©Silberschatz, Korth and Sudarshan1.49Database System Concepts
Relational ModelRelational Model
• Data Integrity
• Ensures correct and consistent navigation and manipulation of
relational tables
• Two types of integrity rules
• Entity integrity
• Referential integrity
• The entity integrity rule states that the value of the primary key can
never be a null value
• The referential integrity rule states that if a relational table has a foreign
key, then every value of the foreign key must either be null or match the
values in the relational table in which that foreign key is a primary key
©Silberschatz, Korth and Sudarshan1.50Database System Concepts
Relational Model OperatorsRelational Model Operators
• Data Manipulation
• Relational tables are equivalent to sets
• Operations that can be performed on sets can be performed
on relational tables
• Relational Operations such as :• Selection• Projection• Join• Union• Intersection• Difference• Product• Division
UNION
INTERSECTION
DIFFERENCE
©Silberschatz, Korth and Sudarshan1.51Database System Concepts
Relational Model OperatorsRelational Model Operators
• Selection• The select operator, sometimes called restrict to prevent confusion with the SQL SELECT command, retrieves subsets of rows from a relational table based on a value(s) in a column or columns
A B C D E
1 A 212 Y 2
2 C 45 N 84
3 B 8656 N 4
4 D 324 N 56
5 C 5656 Y 34
6 A 445 N 4
7 B 546 Y 55
©Silberschatz, Korth and Sudarshan1.52Database System Concepts
• Projection• The project operator retrieves subsets of columns from a relational table removing duplicate rows from the result
A B C D E
1 A 212 Y 2
2 C 45 N 84
3 B 8656 N 4
4 D 324 N 56
5 C 5656 Y 34
6 A 445 N 4
7 B 546 Y 55
©Silberschatz, Korth and Sudarshan1.53Database System Concepts
k x y
1 A 2
2 B 4
3 C 6
k x y
1 A 2
4 D 8
5 E 10
Table A
Table B
A TIMES B
ak ax ay bk bx by
1 A 2 1 A 2
1 A 2 4 D 8
1 A 2 5 E 10
2 B 4 1 A 2
2 B 4 4 D 8
2 B 4 5 E 10
3 C 6 1 A 2
3 C 6 4 D 8
3 C 6 5 E 10
• Product• The product of two relational tables, also called the Cartesian Product, is the concatenation of every row in one table with every row in the second. • The product of table A (having m rows) and table B (having n rows) is the table C (having m x n rows). The product is denoted as A X B or A TIMES B
©Silberschatz, Korth and Sudarshan1.54Database System Concepts
• Join• Combines the product, selection and projection operations• Combines (concatenates) data from one row of a table with rows from
another or same table• Criteria involve a relationship among the columns in the join relational table
If the join criterion is based on equality of column value, the result is called an equi join A natural join is an equi join with redundant columns removed Joins can also be done on criteria other than equality. Such joins are called non-equi joins
k a b
1 A 2
2 B 4
3 C 6k c
1 aa
3 bb
5 cc
k a b k c
1 A 2 1 aa
3 C 6 3 bb
k a b c
1 A 2 aa
3 C 6 bb
Table A
Equi-JoinTable B
Natural Join
©Silberschatz, Korth and Sudarshan1.55Database System Concepts
Relational Model OperatorsRelational Model Operators
• Union• The UNION operation of two tables is formed by appending rows from one
table to those of a second to produce a third. Duplicate rows are eliminated• Tables in an UNION operation must have the same number of columns and
corresponding columns must come from the same domain
Table A
Table B
k x y
1 A 2
2 B 4
3 C 6
k x y
1 A 2
4 D 8
5 E 10
k x y
1 A 2
2 B 4
3 C 6
4 D 8
5 E 10
A Union B
©Silberschatz, Korth and Sudarshan1.56Database System Concepts
Relational Model OperatorsRelational Model Operators
• Intersection • The intersection of two relational tables is a third table that contains common rows. Both tables must be union compatible. The notation for the intersection of A and B is A [intersection] B = C or A INTERSECT B
k x y
1 A 2
2 B 4
3 C 6
k x y
1 A 2
4 D 8
5 E 10
k x y
1 A 2
Table A
Table B
A Intersect B
©Silberschatz, Korth and Sudarshan1.57Database System Concepts
Relational Model OperatorsRelational Model Operators
• Difference
• The difference of two relational tables is a third that contains those
rows that occur in the first table but not in the second. The Difference
operation requires that the tables be union compatible.
The notation for difference is A MINUS B or A-B. As with arithmetic, the order of
subtraction matters. That is, A - B is not the same as B - A.
k x y
1 A 2
2 B 4
3 C 6
Table A
Table B
A MINUS B
k x y
1 A 2
4 D 8
5 E 10
B MINUS A
k x y
2 B 4
3 C 6
k x y
4 D 8
5 E 10
©Silberschatz, Korth and Sudarshan1.58Database System Concepts
Relational Model OperatorsRelational Model Operators
Table A Table B
A DIV B
• Division• The division operator results in columns values in one table for which there are other matching column values corresponding to every row in another table.
k x y
1 A 2
1 B 4
2 A 2
3 B 4
4 B 4
3 A 2
x y
A 2
B 4
k
1
3
©Silberschatz, Korth and Sudarshan1.59Database System Concepts
PART-2 PART-2 DATABASES MODELSDATABASES MODELS
{ Relational,Heirarchical,Network,E-R Model}{ Relational,Heirarchical,Network,E-R Model}&&
RELATIONAL ALGEBRA OPERATIONSRELATIONAL ALGEBRA OPERATIONS
DBMS by Er. K.S.Dhindsa © 2006
Lecture Series By :Lecture Series By :Er. Kanwalvir Singh DhindsaEr. Kanwalvir Singh DhindsaDeptt. of CSE & ITDeptt. of CSE & IT
For downloading slides of DBMS, Visit :For downloading slides of DBMS, Visit :
WEBSITE : WEBSITE : www.dhindsa.infowww.dhindsa.info Homepage: Homepage: http://groups.google.com/group/DBMS-2006http://groups.google.com/group/DBMS-2006
top related