Chapter 2: Oracle PLSQL

25
Database Management System, Oracle SQL and PL/SQL Pranab Kumar Das Gupta PHI Learning Private Limited Book Page Number 22 - 50 DATABASE MANAGEMENT SYSTEM ORACLE SQL AND PL/SQL CHAPTER 2 Relational Algebra Normal Forms Teaching Aid

description

It describes details about DBMS using ORacle PLSQL

Transcript of Chapter 2: Oracle PLSQL

Page 1: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Book Page Number 22 - 50

DATABASE MANAGEMENT SYSTEM ORACLE SQL AND PL/SQL

CHAPTER 2

Relational Algebra Normal Forms

Teaching Aid

Page 2: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 22 - 28

CHAPTER 2Relational Database

1 of 4

A relational database is based on the concept that the related data is organized and stored in a series of two dimensional tables known as relations

A row is called a tuple

A column is called as attribute

A primary key is an attribute that determines all the other attributes within that row

Each data item in a row is functionally dependent on the primary key

Teaching Aid

Page 3: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 22 - 28

CHAPTER 2Relational Database

2 of 4

PRIMARY KEY A primary key is a minimal combination of field(s) that uniquely identifies the corresponding values of other field in a table. The field(s) of a primary key is known as prime attribute(s). The values of prime attributes can never be NULL

FOREIGN KEYA foreign key is an attribute or set of attributes that appears in one table but is the primary key in other table. It is used to link two tables

Teaching Aid

Page 4: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 22 - 28

CHAPTER 2Relational Database

3 of 4

SUPER KEYA super key is combination of prime attribute(s) and one or more nonprime key attribute(s). It also uniquely identifies a record in a table. Primary key can be defined as super key with minimal attributes

CANDIDATE KEY & ALTERNATE KEYCandidate key may be two or more keys that uniquely identifies record in a table. Any one in the candidate key can be chosen as a primary key. The remaining keys are called alternate key

Teaching Aid

Page 5: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 22 - 28

CHAPTER 2Relational Database

4 of 4

SETS AND DOMAINSA domain is finite or infinite set from which values can be chosen

CARTESIAN PRODUCTFor two domains D1 and D2, the Cartesian product, denoted by D1 x D2 is defined as the set of all ordered pairs such that the first element is a member of D1 and second element is a member of D2

RELATIONSA Relation is defined as any subset of the

Cartesian product of the domains

Teaching Aid

Page 6: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 28 - 32

CHAPTER 2Relational Algebra

1 of 5

Two relation P and Q are said to be Union, Intersection and Difference compatible if both P and Q are of same degree nand the domain of the corresponding n attributes are identical

UNIONSelects the all tuples from the two relations without repetition

INTERSECTIONSelects the common tuples from the two relations

DIFFERENCERemoves common tuples from the first relation

Teaching Aid

Page 7: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 28 - 32

CHAPTER 2Relational Algebra

2 of 5

Teaching Aid

Page 8: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 28 - 32

CHAPTER 2Relational Algebra

3 of 5

PROJECTIONThe projection operation yields a vertical subset of a relation

Teaching Aid

Page 9: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 28 - 32

CHAPTER 2Relational Algebra

4 of 5

SELECTION The selection operation yields a horizontal subset of a relation

Teaching Aid

Page 10: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 28 - 32

CHAPTER 2Relational Algebra

5 of 5

Teaching Aid

Page 11: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 33 - 45

CHAPTER 2Normal Forms

1 of 9

Normalization is the process of refining the data model built by the Entity-Relationship diagram.

The decomposition of more complex data structures into flat files (relation) is known as normalization.

A relation is said to be normalized if every value in the relation is atomic.

Teaching Aid

Page 12: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 33 - 45

CHAPTER 2Normal Forms

2 of 9

All relations in a relational database are required to be normalized to permit the simple retrieval and maintenance of data through updates, insertions and deletions.

It also allows representing any pertinent relationship between entities.

Normalization ensures minimum redundancies of data and removes anomalies for database activities.

Teaching Aid

Page 13: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 33 - 45

CHAPTER 2Normal Forms

3 of 9

UN-NORMALIZED FORM

Teaching Aid

Page 14: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 33 - 45

CHAPTER 2Normal Forms

4 of 9

FIRST NORMAL FORM: All attributes are atomic

Anomalies associated with First Normal Form

Teaching Aid

Page 15: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 33 - 45

CHAPTER 2Normal Forms

5 of 9

SECOND NORMAL FORM1 NF and every non-key attribute is functionally dependent on the primary key

Teaching Aid

Page 16: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 33 - 45

CHAPTER 2Normal Forms

6 of 9

SECOND NORMAL FORMElimination of anomalies encountered in First Normal Form

Anomalies associated with Second Normal Form

Teaching Aid

Page 17: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 33 - 45

CHAPTER 2Normal Forms

7 of 9

THIRD NORMAL FORMSecond Normal Form and no transitive dependency

Teaching Aid

Page 18: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 33 - 45

CHAPTER 2Normal Forms

8 of 9

THIRD NORMAL FORM

Elimination of anomalies encountered in Second Normal Form

Teaching Aid

Page 19: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 33 - 45

CHAPTER 2Normal Forms

9 of 9

BOYCE - CODD NORMAL FORMIf and only if every determinant is a candidate key

FOURTH NORMAL FORMBCNF and has no nontrivial multi-values Dependencies

FIFTH NORMAL FORMFourth normal form and every join dependency in the table is a consequence of the candidate key of the table

Teaching Aid

Page 20: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 46 - 48

CHAPTER 2Short/ Objective Type Questions

1 of 5

Q1. What are the disadvantages of flat file database?

Q2. How ‘Cartesian product’ and ‘relations’ are associated with each other?

Q3. What is the difference between primary key and unique key?

Q4. Define candidate key.

Q5. Define division operation.

Q6. Describe fully functional dependency with the help of an example.

Q7. Define BCNF and Fourth normal form.

Q8. Mention common type of anomalies during normalization process.

Teaching Aid

Page 21: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 46 - 48

CHAPTER 2Short/ Objective Type Questions

2 of 5

Q9. Which normal form is considered adequate for RDBMS design?a. 3 NFb. 2 NFc. BCNFd. 4 NF

Q10. If every non-key attribute is functionally dependent on the primary key, the relation will be ina. 1 NFb. 2 NFc. 3 NFd. 4 NF

Q11. The column of a table is referred to as thea. Tupleb. Entityc. Degree d. Attribute

Teaching Aid

Page 22: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 46 - 48

CHAPTER 2Short/ Objective Type Questions

3 of 5

Q12.Relation produced from an ER model will always be ina. 1 NFb. 2 NFc. 3 NFd. 4 NF

Q13. Select True/ False statementa. An alternate key is a primary key that is not a candidate key b. An alternate key is a candidate key that is not a primary key c. An alternate key is a candidate key that is also a primary key

Q14. An attribute of one table matching the primary key of another table, is called asa. Primary keyb. Unique keyc. Composite key d. Foreign key

Teaching Aid

Page 23: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 46 - 48

CHAPTER 2Short/ Objective Type Questions

4 of 5

Q15. Oracle database server supportsa. Client/ Server architectureb. Three-tier architecturec. None of the above

Q16. Join correctly the followinga. Projection a. Yields a horizontal subset of a relationb. Selection b. Selects a vertical subset of a relationc. Join c. Allows combining two relations

Q17. A domain is/area. Finite set from which values can be chosenb. Infinite set from which values can be chosenc. None of the above

Teaching Aid

Page 24: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 46 - 48

CHAPTER 2Short/ Objective Type Questions

5 of 5

Q18. Primary key can also be defined asa. Super key with minimal attributesb. Any one candidate keyc. Combination of prime attributesd. Alternate key

Q19. Disadvantage of normalization is/area. Elimination of anomaliesb. Increase in execution time because of joinc. Overall reduction of spaced. Minimal redundancy

Q20. Transitive dependency is related to a. 1NFb. 2NFc. 3NFd. 4NF

Teaching Aid

Page 25: Chapter 2: Oracle PLSQL

Dat

abas

e M

anag

emen

t Sy

stem

, O

racl

e SQ

L an

d P

L/SQ

LPr

anab

Kum

ar D

as G

upta

PH

I Lea

rnin

g Pr

ivat

e Li

mit

ed Page 48 - 50

CHAPTER 2Home Assignment

WORKOUT SECTION [Page 48 – 50]

Teaching Aid