rdbms concepts

38
© Tata Consultancy Services ltd. June 6, 2022 1 RDBMS Concepts

Upload: chacko-mathew

Post on 15-Nov-2014

46 views

Category:

Documents


4 download

DESCRIPTION

Course Objectives:To provide an overview of the basic RDBMS Concepts.To provide an insight into the architecture and components of a Database System.

TRANSCRIPT

Page 1: RDBMS Concepts

© Tata Consultancy Services ltd. April 8, 2023 1

RDBMS Concepts

Page 2: RDBMS Concepts

2

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Course Prerequisites

A basic understanding of SQL in Oracle Understanding of a procedural language

Page 3: RDBMS Concepts

3

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

To provide an overview of the basic RDBMS Concepts

To provide an insight into the architecture and components of a Database System.

Course Objectives

Page 4: RDBMS Concepts

4

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Session Outline

RDBMS : Description Evolution of the Database Model Entity Relationship Model Integrity Rules Normalization Integrity Rules ER Diagrams ER Model Relational Algebra Operators Relational Database

Page 5: RDBMS Concepts

5

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

RDBMS Concepts Evolution of the database model Approaches to Data Management

File Based Systems DBMS

The Entity Relationship Model Normalization Relational Algebra Codd ’s Rules ORDBMS

!

Page 6: RDBMS Concepts

6

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Needs of Computerized Systems

Management of

Data that needs to be stored

Business functions that need to be performed

!

Page 7: RDBMS Concepts

7

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Evolution of the Database ModelFiles based system

1970 1985 1990 19951975 1980 2000

Hierarchical DBMS

Network DBMS

Relational DBMS

Distributed DBMS

Object Oriented

DBMS

Object Relational DBMS

!

Page 8: RDBMS Concepts

8

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

File-Based SystemsDrawbacks:

Data redundancy and inconsistency

Poor handling of unanticipated queries

Concurrent access anomalies

Security problems

Integrity problems

Application dependent on

Storage structure of data

Access strategy of data

!@

Page 9: RDBMS Concepts

9

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

File-Based Systems

Checking A/c

Application

Checking A/c

Data file(s)

Loan InstallmentApplication

LoanInstallmentData file(s)

Savings A/c

Application

Savings A/c

Data file(s)

!

Page 10: RDBMS Concepts

10

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

CheckingA/c

Application

(All Data)Data Base

SavingsA/c

Application

LoanInstallmentApplication

DatabaseManagement

System(DBMS)

Any NewApplication

- Integrated- Shared

Database Management SystemsA database is a collection of stored operational data used by application systems of a particular enterprise

!@

Page 11: RDBMS Concepts

11

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Database Management SystemsFunctions:

Data Definition Data Manipulation

Planned Unplanned

Data Security & Integrity Data Recovery & Concurrency Data Dictionary Maintenance Performance

!

Page 12: RDBMS Concepts

12

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Database Management Systems

Physical/ InternalHow the data is stored

[ DATA FILES ]

Conceptual/ LogicalWhat data and How it is organized logically

[ TABLE SPACE, SEGMENTS ]

User/ ExternalWhat the user sees

[ TABLES, VIEWS … ]

3-Level DBMS Architecture

!

Page 13: RDBMS Concepts

13

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Database Management SystemsAdvantages:

Minimal Data Redundancy

Data Consistency

Data Integration

Data Sharing

Enforcement of Standards

Application Development Ease

Better Controls

Data Independence

!

Page 14: RDBMS Concepts

14

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

The Entity Relationship Model

The Entity-Relationship data model is based on a perception of the real world which consists of basic objects called entities and relationships among these objects.

!@

Page 15: RDBMS Concepts

15

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

The Entity Relationship Model

Entity

Attribute

Domain

Relation

Cardinality

Key

Constraint

!

Page 16: RDBMS Concepts

16

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

ER Model: EntityEntity: Is an object that exists, and is distinguishable from other objects, and about

which data needs to be stored in the system Maybe concrete (person, book) or abstract (holiday, concept)

Hint: Identified by nouns Entity Set is a set of entities of the same type

eg: A set of all persons who are allowed to issue books at the library can be defined as entity set Member.

!

Page 17: RDBMS Concepts

17

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

ER Model: Attribute and DomainAttribute: (Characteristics) Is a feature which qualifies an entity, and about which data needs to be

stored Maybe concrete (name, identity number) or abstract (status)

eg: A Member has a Member ID, Name, Address

A Book has a Book ID, Name, Author

Domain: (Data Type + Format + Validation) Each attribute has a set of permitted values, called the domain of that

attribute

eg: Status can have any one of these values at a time:

Issued, Available, Lost

!

Page 18: RDBMS Concepts

18

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

ER Model: RelationshipRelationship: Is an association among several entities, and about which data needs to

be storedeg: A Member requests books from the library

Hint: Identified by Verbs

A relationship set is a set of relationships of the same type

May have descriptive attributes

!

Page 19: RDBMS Concepts

19

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

ER Model: RelationshipCardinality: Expresses the number of instances of the entity to which another entity can be

associated via a relation. Types:

One to One A copy of a Book can be issued by only one Member at a time

One to Many A Member can issue many Books

Many to Many An author can write many books, and a book can be written by many

authors

!

Page 20: RDBMS Concepts

20

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

ER Model: KeyKey:

A key is an attribute or set of attributes of an entity which can be used to identify it.

Super Key is a set of one or more attributes which, taken collectively, allows an

entity to be uniquely identified in an entity set Candidate Key

is a super key for which no proper subset is a super key (i.e., a minimal super key)

Primary Key is a candidate key chosen by the database designer as the principle

means of identifying entities within an entity set

!

Page 21: RDBMS Concepts

21

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

ER Model: KeyKey:

Alternate Key is a candidate key that is not a primary key

Foreign Key is an attribute or set of attributes that exist in one entity and

reference similar attribute(s) in another entity wherein they serve as a primary key

!

Page 22: RDBMS Concepts

22

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

ER Model: ConstraintsConstraints:

Key Constraints:These are constraints implied by the existence of candidate keys. The table definition includes a specification implying uniqueness of the attributes constituting the primary key or alternate keys. A primary key constraint also implies a no-nulls constraint.

Referential Constraints:Constraints implied by the existence of foreign keys in the table definition.

Other Constraints:Constraints enforcing checks of business logic of the application in the table definition.

!

Page 23: RDBMS Concepts

23

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

ER Model: Example

Cheques

# Chq No* Cust No.* Amount* Date* Amount* To name0 Comments

# primary key

* mandatory

0 optional

OptionalMandatory

Only oneMany

Cust Account

# Customer No.# Account Type# Account No.* Date opened* Balance0 Last Activity

Has/ Issued from

Legend:

ER Diagram for:Cheques are issued from Customer Account

!@

Page 24: RDBMS Concepts

24

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

ER Model: Example Entity - Cust Account

Attribute - Account No, Date Opened ...

Domain - Date Opened should be valid date

Relation - Cheques are “issued from” Cust account.

Cardinality - Many cheques can be written from the same account

Key - Cheque No. is a Primary Key

Constraint - Amount should be not NULL

!

Page 25: RDBMS Concepts

25

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Reducing ER diagrams to Tables

The database should conform to the E-R diagram Each entity should have a table Each table will have as many columns as the number of attributes of the

entity (which are unique in the table) Attributes should conform to their domain characteristics Constraints on attributes can be represented as check constraints, not null

or unique constraints Relationships between entities on should be represented as referential key

constraints or tables

!@

Page 26: RDBMS Concepts

26

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Reducing ER diagrams to Tables

Tuple:

A row in a table is referred to as a tuple (rhymes with ‘couple’)Example: An instance of a Book - (1, ‘Backup and Recovery’, ‘Rama

Velpuri’)

Properties of Relationships: No duplicate tuples Tuples are unordered Attributes are unordered Attribute values are atomic (cannot be decomposed)

!

Page 27: RDBMS Concepts

27

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Integrity Rules

Integrity Rules:

No component of the Primary Key can be null The database must not contain any unmatched foreign key values Issues to consider at design time:

Can the foreign key accept nulls What to do in case of deletes/updates of parent

restrict cascade nullify

!@

Page 28: RDBMS Concepts

28

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Normalization

Normalization: A relation is said to be in normal form if it satisfies a set of constraints

Universe of relations (normalized and unnormalized)

1NF relations (normalized relations)

2NF relations3NF relations

BCNF (Boyce Codd) relations4NF relations

PJ/ NF (5NF Projection Join) relations

!@

Page 29: RDBMS Concepts

29

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Normalization

FIRST Normal form (1NF) if it contains atomic values only

SECOND Normal form (2NF) if it is in 1NF and every non-key attribute is dependent on the primary

key

THIRD Normal form (3NF) if it is in 2NF and every non-key attribute is non-transitively

dependent on the primary key

!@

Page 30: RDBMS Concepts

30

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Normalization

Functional Dependency Unique value of one attribute can always be determined if we know the

value of another.Independent variable (X), dependent variable (Y)invoice number (X) --> Order date (Y)

Total Dependency When both the variables are dependent on each other

Employee number (X) <--> Driving license number (Y)

!

Page 31: RDBMS Concepts

31

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Normalization

Full Dependency When one attribute is always dependent on at least two other

attributes Invoice Number (X) Part number (Y) Order Quantity (Z)

Transitive Dependency If Y depends on X and X depends on Y

Invoice (X) --> Customer Number (Y) --> Customer Name (Z)

Course (X) --> Department (Y) --> College (Z)

!

Page 32: RDBMS Concepts

32

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

NormalizationInvoice Number: 4001Date: 22/5/98

Customer ID: C0051Name: Mr. Babu DaveAddress: B-10, Sada society, Borivali (W), Mumbai - 400 092.

Sr. Part Name Qty Unit QtyNo. No. Price Price------------------------------------------------------------------------1. U90 U-pin box 3 10 302. E12 Big eraser box 2 30 60------------------------------------------------------------------------TOTAL: 90

Terms and conditions: TC035Sales person: S04

ABC Company INVOICE

(NOTE: See the appendix #@)

!

Page 33: RDBMS Concepts

33

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Relational Algebra Operators

SELECT

PROJECT

PRODUCT

DIVIDE

JOIN

UNION

INTERSECT

DIFFERENCE

!

Page 34: RDBMS Concepts

34

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Relational Algebra OperatorsSELECT employees with department number 10

PROJECT name and salary from employee

dept#=10(DEPT)

name, salary(EMP)

!

Page 35: RDBMS Concepts

35

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Relational Algebra OperatorsPRODUCT of employee with departmenta

bxyz

aaabbb

X =xyzxyz

EMP X DEPT

DIVIDE Orders containing item numbers X and Z

xz

aaabb

xyzxy

a=

ord#, Item#(ORD_ITEMS)

Item#(item#=‘X’ or ‘Z’(ITEMS))

!

Page 36: RDBMS Concepts

36

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Relational Algebra Operators

a1a2

b1b2

c1c2

b1b2

a1a2

b1b2

c1c2

JOIN of employee with department

EMP DEPT

=

!

Page 37: RDBMS Concepts

37

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Relational Algebra Operators

cust# (ORD_JUL) cust#(ORD_AUG)

INTERSECT

cust# (ORD_JUL) - cust#(ORD_AUG)

DIFFERENCE

UNION

ORD_JUL ORD_AUG

!

Page 38: RDBMS Concepts

38

Text in blue and black can be changedPositions in Blue text cannot be alteredText in black can be altered in position and sizes if need beText in yellow ochre is meant for legal matters and updates

Relational Database A database system may be defined as fully relational

if it supports

relational databases (including concepts of domain and key and the two integrity rules)

a language that is at least as powerful as relational algebra

!