Database Concepts and Definition of Terms

66
Database Concepts and Definition of Terms SPECIAL TRAINING EDITION

description

Oracle Database Modelling --Database Concepts and Definition of Terms

Transcript of Database Concepts and Definition of Terms

Page 1: Database Concepts and Definition of Terms

Database Concepts andDefinition of Terms

Database Concepts andDefinition of Terms

SPECIAL TRAINING EDITIONSPECIAL TRAINING EDITION

Page 2: Database Concepts and Definition of Terms

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

SESSION OBJECTIVESESSION OBJECTIVEThis session will introduce you to the basic concepts and terminologies used in Relational Analysis and Design.

This session will introduce you to the basic concepts and terminologies used in Relational Analysis and Design.

Page 3: Database Concepts and Definition of Terms

What is a Database ?What is a Database ?A shared collection of logically related data (and a description of this data) designed to meet the information needs of an organization.

A shared collection of logically related data (and a description of this data) designed to meet the information needs of an organization.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

DatabaseDatabase

Page 4: Database Concepts and Definition of Terms

What is a DBMS ?What is a DBMS ?

A database management system (DBMS) is a software system that enables users to define, create and maintain the database and which provides controlled access to this database.

A database management system (DBMS) is a software system that enables users to define, create and maintain the database and which provides controlled access to this database.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 5: Database Concepts and Definition of Terms

What is a Table ?What is a Table ?

A table is a 2-dimensional representation of data consisting of one or more columns, and zero or more rows.

A table is a 2-dimensional representation of data consisting of one or more columns, and zero or more rows.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 6: Database Concepts and Definition of Terms

ExampleExample COURSECOURSE

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSABSCBSC

COMPUTER SCIENCECOMPUTER SCIENCEINFORMATION TECHNOLOGYINFORMATION TECHNOLOGYACCOUNTANCYACCOUNTANCYCOMMERCECOMMERCE

The name of the table is COURSE. It has two columns and four rows. The column names are Course Code and Course Description.

The name of the table is COURSE. It has two columns and four rows. The column names are Course Code and Course Description.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 7: Database Concepts and Definition of Terms

Table Naming ConventionsTable Naming Conventions Table names must be unique.

To avoid ambiguity in specifying a table, no two tables can have the same name within a data model (database).

Column names must be unique within a table

Each column within a table must have a unique name. However, columns from different tables can have the same name and in fact, desirable to clearly establish relations between tables.

Rows must be uniqueRows, considered in their entirety, must be distinct from one another.

Table names must be unique.To avoid ambiguity in specifying a table, no two tables can have the same name within a data model (database).

Column names must be unique within a table

Each column within a table must have a unique name. However, columns from different tables can have the same name and in fact, desirable to clearly establish relations between tables.

Rows must be uniqueRows, considered in their entirety, must be distinct from one another.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 8: Database Concepts and Definition of Terms

ExampleExample COURSECOURSE

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSABSCBSC

COMPUTER SCIENCECOMPUTER SCIENCEINFORMATION TECHNOLOGYINFORMATION TECHNOLOGYACCOUNTANCYACCOUNTANCYCOMMERCECOMMERCE

STUDENTSTUDENT

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

0101020203030404

HERBERTHERBERT

NICOLAINICOLAIGENEGENE

CARMELCARMEL

COURSECOURSE

BSCSBSCSBSCSBSCSBSABSABSITBSIT

YEARYEAR

11224444

TUITIONTUITION

7,000.007,000.006,500.006,500.005,000.005,000.008,000.008,000.00

CODECODE

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 9: Database Concepts and Definition of Terms

Table Naming Conventions (cont.)Table Naming Conventions (cont.) Column and row order must be arbitrary.

Although the following tables may look different, they are actually the same. The order of the columns and rows has no significance.

Column and row order must be arbitrary.Although the following tables may look different, they are actually the same. The order of the columns and rows has no significance.

STUDENTSTUDENT

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

0101020203030404

HERBERTHERBERT

NICOLAINICOLAIGENEGENE

CARMELCARMEL

COURSECOURSE

BSCSBSCSBSCSBSCSBSABSABSITBSIT

YEARYEAR

11224444

CODECODE

STUDENTSTUDENT

COURSECOURSECODECODE

STUDENTSTUDENTNUMBERNUMBER

BSABSABSITBSITBSCSBSCSBSCSBSCS

02020101

44

YEARYEAR

03030404 44

2211

NICOLAINICOLAI

HERBERTHERBERT

GENEGENECARMELCARMEL

NAMENAMESTUDENTSTUDENT

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 10: Database Concepts and Definition of Terms

Table Naming Conventions (cont.)Table Naming Conventions (cont.) Each cell of the table contains exactly one

atomic (single) value. Since each cell should contain only one value, it is illegal to store two year levels for a single student in a single cell (year).

Each cell of the table contains exactly one atomic (single) value. Since each cell should contain only one value, it is illegal to store two year levels for a single student in a single cell (year).

STUDENTSTUDENT

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

0101020203030404

HERBERTHERBERT

NICOLAINICOLAIGENEGENE

CARMELCARMEL

COURSECOURSE

BSCSBSCSBSCSBSCSBSABSABSITBSIT

YEARYEAR

1 / 21 / 22 / 32 / 3

4 4 44

CODECODE

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 11: Database Concepts and Definition of Terms

Null ValuesNull Values Def. A missing or unknown value of a column of a table.Def. A missing or unknown value of a column of a table.

Null Values Naming ConventionsNull Values Naming Conventions

Nulls are not the same as blanks. A value of a null is unknown.

Nulls are not the same as zeros. You cannot perform arithmetic operations on nulls.

NN means no nulls allowed. Why should some columns not allow nulls? (Tuition Fees, Student Number, Subject Code, Course Code)

Nulls are not the same as blanks. A value of a null is unknown.

Nulls are not the same as zeros. You cannot perform arithmetic operations on nulls.

NN means no nulls allowed. Why should some columns not allow nulls? (Tuition Fees, Student Number, Subject Code, Course Code)

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 12: Database Concepts and Definition of Terms

Exampleon NullsExampleon Nulls

COURSECOURSE

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFORMATION TECHNOLOGYINFORMATION TECHNOLOGYACCOUNTANCYACCOUNTANCY

STUDENTSTUDENT

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

010102020303

HERBERTHERBERT

NICOLAINICOLAICARMELCARMEL

COURSECOURSE

BSCSBSCSBSCSBSCS

YEARYEAR

112244

TUITIONTUITION

7,000.007,000.00

5,000.005,000.00

CODECODE

NNNN NNNN

NNNN NNNN

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 13: Database Concepts and Definition of Terms

Duplicate ValuesDuplicate ValuesWhen a value in a column matches exactly another value in the same column, it is called a duplicate value.

When a value in a column matches exactly another value in the same column, it is called a duplicate value.

ND means no duplicates allowed. Duplicate rows are not allowed. However, duplicate values in particular columns of a table are not at all uncommon.

By placing ND below a column heading, it will prohibit duplicate values in that column. To prevent duplicate values in groups of columns, suffix ND with a number, e.g. ND1, ND2, ND3, etc.

ND means no duplicates allowed. Duplicate rows are not allowed. However, duplicate values in particular columns of a table are not at all uncommon.

By placing ND below a column heading, it will prohibit duplicate values in that column. To prevent duplicate values in groups of columns, suffix ND with a number, e.g. ND1, ND2, ND3, etc.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 14: Database Concepts and Definition of Terms

Exampleon DuplicateValues

Exampleon DuplicateValues

COURSECOURSE

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFORMATION TECHNOLOGYINFORMATION TECHNOLOGYACCOUNTANCYACCOUNTANCY

STUDENTSTUDENT

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

010102020303

HERBERTHERBERT

NICOLAINICOLAICARMELCARMEL

COURSECOURSE

BSCSBSCSBSCSBSCS

YEARYEAR

112244

TUITIONTUITION

7,000.007,000.00

5,000.005,000.00

CODECODE

NN, NDNN, ND NN, NDNN, ND

NN, NDNN, ND NN, ND1NN, ND1 ND1ND1

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 15: Database Concepts and Definition of Terms

Changeable ValuesChangeable Values

A value in a table that may vary over time is called a changeable value.A value in a table that may vary over time is called a changeable value.

NC means no changes allowed.

Can student numbers in a table be changed?

Place NC below the column heading to prevent changes on the values in that column.

NC means no changes allowed.

Can student numbers in a table be changed?

Place NC below the column heading to prevent changes on the values in that column.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 16: Database Concepts and Definition of Terms

Exampleon ChangeableValues

Exampleon ChangeableValues

COURSECOURSE

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFORMATION TECHNOLOGYINFORMATION TECHNOLOGYACCOUNTANCYACCOUNTANCY

STUDENTSTUDENT

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

010102020303

HERBERTHERBERT

NICOLAINICOLAICARMELCARMEL

COURSECOURSE

BSCSBSCSBSCSBSCS

YEARYEAR

112244

TUITIONTUITION

7,000.007,000.00

5,000.005,000.00

CODECODE

NN,ND,NCNN,ND,NC NN, NDNN, ND

NN, ND1NN, ND1 ND1ND1NN,ND,NCNN,ND,NC

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 17: Database Concepts and Definition of Terms

Primary KeysPrimary KeysThe column or group of columns whose values uniquely identify each row of that table is called the primary key.

The column or group of columns whose values uniquely identify each row of that table is called the primary key.

Primary Key Values Naming ConventionsPrimary Key Values Naming Conventions Every table must have a primary key. Every table must have only one primary key. PK means primary key.

Place PK below the heading of one or more columns which will serve as the primary key.

Every table must have a primary key. Every table must have only one primary key. PK means primary key.

Place PK below the heading of one or more columns which will serve as the primary key.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 18: Database Concepts and Definition of Terms

Constraints on Primary KeysConstraints on Primary Keys Primary key values must never be null.

PK implies NN (Entity Integrity)

Primary key values must never be duplicated. PK implies ND

Primary key values must never be changed.PK implies NC

Primary keys do not influence column order. Primary keys do not influence row order. Primary keys do not influence row access.

Primary key values must never be null.PK implies NN (Entity Integrity)

Primary key values must never be duplicated. PK implies ND

Primary key values must never be changed.PK implies NC

Primary keys do not influence column order. Primary keys do not influence row order. Primary keys do not influence row access.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 19: Database Concepts and Definition of Terms

Other Primary Keys NotationsOther Primary Keys Notations SA means system-assigned

Mark a column with SA, in addition to PK if the values are automatically generated by the system.

UA means user-assignedMark a column with UA, in addition to PK, if the values of the primary key are assigned by the user.

SA means system-assignedMark a column with SA, in addition to PK if the values are automatically generated by the system.

UA means user-assignedMark a column with UA, in addition to PK, if the values of the primary key are assigned by the user.

COURSECOURSE

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFORMATION TECHNOLOGYINFORMATION TECHNOLOGYACCOUNTANCYACCOUNTANCY

PK, UAPK, UA NN, NDNN, ND

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 20: Database Concepts and Definition of Terms

Foreign KeysForeign KeysA column or group of columns that is a primary key elsewhere is called a foreign key.A column or group of columns that is a primary key elsewhere is called a foreign key.

Foreign Key Rules and ConstraintsForeign Key Rules and Constraints FK mean foreign key Multi-column foreign keys can be numbered, e.g. FK1, FK2, etc. Foreign key values might be null. Foreign key columns can contain duplicate

values.

FK mean foreign key Multi-column foreign keys can be numbered, e.g. FK1, FK2, etc. Foreign key values might be null. Foreign key columns can contain duplicate

values.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 21: Database Concepts and Definition of Terms

Foreign Key Rules and Constraints (cont.)Foreign Key Rules and Constraints (cont.) FK values must refer to existing PK values

(Referential Integrity)

FK values must refer to existing PK values (Referential Integrity)

COURSECOURSE

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFO. TECHNOLOGYINFO. TECHNOLOGYACCOUNTANCYACCOUNTANCY

STUDENTSTUDENT

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

010102020303

HERBERTHERBERT

NICOLAINICOLAICARMELCARMEL

COURSECOURSE

BSCSBSCS

YEARYEAR

112244

TUITIONTUITION

7,000.007,000.00

5,000.005,000.00

CODECODE

PK,UAPK,UA NN, NDNN, ND NN, ND1NN, ND1 FK,ND1FK,ND1PK,SAPK,SA

BSABSA0404 LOUIELOUIE ABAB 33

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 22: Database Concepts and Definition of Terms

Derivative DataDerivative Data

Data that is calculated from data defined elsewhere in a model is called derivative data.

Data that is calculated from data defined elsewhere in a model is called derivative data.

DD means derivative data. DD is redundant data.

Derivative data should only be included in a model when severe performance problems dictate its necessity.

DD means derivative data. DD is redundant data.

Derivative data should only be included in a model when severe performance problems dictate its necessity.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 23: Database Concepts and Definition of Terms

Derivative Data ExampleDerivative Data ExampleCOURSECOURSE

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFO. TECHNOLOGYINFO. TECHNOLOGYACCOUNTANCYACCOUNTANCY

PK,UAPK,UA NN, NDNN, ND

STUDENTSTUDENTCOUNTCOUNT

DDDD

11212100

The Student Count column of the Course table is a derived data; the values in this column are calculated from the information resident in the Student table.

The Student Count column of the Course table is a derived data; the values in this column are calculated from the information resident in the Student table.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 24: Database Concepts and Definition of Terms

Basic Relational Analysis

Basic Relational Analysis

SPECIAL TRAINING EDITIONSPECIAL TRAINING EDITION

Page 25: Database Concepts and Definition of Terms

Basic Relational AnalysisBasic Relational Analysis

SESSION OBJECTIVESESSION OBJECTIVEThis session will introduce you to the steps, procedures and rules used in basic relational analysis and design.

This session will introduce you to the steps, procedures and rules used in basic relational analysis and design.

Page 26: Database Concepts and Definition of Terms

What is an Entity ?What is an Entity ?

An entity is a distinct object (a person, place or thing, concept or event) in the organization that is to be represented in the database.

An entity is a distinct object (a person, place or thing, concept or event) in the organization that is to be represented in the database.

Basic Relational AnalysisBasic Relational Analysis

Page 27: Database Concepts and Definition of Terms

Steps in Modeling EntitiesSteps in Modeling Entities DISCOVER AN ENTITY

Ask: What person, place or thing do you want to keep track of?

Concentrate on nounsMore often, entities are obvious physical objects. Sometimes, they are nothing more than a concept or idea.

Beware of attributes in disguiseEntities stand on their own; attributes have meaning only in the context of the entities which they describe. Entities have attributes; attributes have no characteristics they can call their own.

DISCOVER AN ENTITY Ask:

What person, place or thing do you want to keep track of?

Concentrate on nounsMore often, entities are obvious physical objects. Sometimes, they are nothing more than a concept or idea.

Beware of attributes in disguiseEntities stand on their own; attributes have meaning only in the context of the entities which they describe. Entities have attributes; attributes have no characteristics they can call their own.

Basic Relational AnalysisBasic Relational Analysis

Page 28: Database Concepts and Definition of Terms

DEFINE THE SCOPE OF THE ENTITY Verify user interest

Users often mention entities that are not really within the scope of a model. They may be interested in a particular entity, but not enough to warrant keeping track of it. In which case, exclude it from

the model. Concentrate on types not occurrences

Student instead of Carmel or Herbert.

Establish the appropriate level of detailWhen a user says Part, he may refer to the kinds of part (e.g. hard disk, video card, etc.) rather than a specific part identified by Serial No. 1234. In this case, you may want to use Part Kind instead of Part as the entity name.

DEFINE THE SCOPE OF THE ENTITY Verify user interest

Users often mention entities that are not really within the scope of a model. They may be interested in a particular entity, but not enough to warrant keeping track of it. In which case, exclude it from

the model. Concentrate on types not occurrences

Student instead of Carmel or Herbert.

Establish the appropriate level of detailWhen a user says Part, he may refer to the kinds of part (e.g. hard disk, video card, etc.) rather than a specific part identified by Serial No. 1234. In this case, you may want to use Part Kind instead of Part as the entity name.

Basic Relational AnalysisBasic Relational Analysis

Page 29: Database Concepts and Definition of Terms

DETERMINE THE PRIMARY KEY Ask:

What uniquely identifies the entity from another? Check for nulls

Make sure that the potential primary key is never null.

Check for duplicatesMake sure that the proposed primary key is always unique.

Check for changesThe proposed primary key values must never be changed.

System-assign if necessaryThe proposed primary key values should preferably be system-assigned. If no key exists, assign a code or number column as the primary key of the entity.

DETERMINE THE PRIMARY KEY Ask:

What uniquely identifies the entity from another? Check for nulls

Make sure that the potential primary key is never null.

Check for duplicatesMake sure that the proposed primary key is always unique.

Check for changesThe proposed primary key values must never be changed.

System-assign if necessaryThe proposed primary key values should preferably be system-assigned. If no key exists, assign a code or number column as the primary key of the entity.

Basic Relational AnalysisBasic Relational Analysis

Page 30: Database Concepts and Definition of Terms

DOCUMENT THE ENTITY IN TABLE FORM Draw the table and assign: entity name, column/primary keys, PK/SA or UA, sample data or occurrences.

DOCUMENT THE ENTITY IN TABLE FORM Draw the table and assign: entity name, column/primary keys, PK/SA or UA, sample data or occurrences.

COURSECOURSECOURSECOURSENUMBERNUMBER

PK, UAPK, UA

BSCSBSITBSA

BSCSBSITBSA

STUDENTSTUDENTSTUDENTSTUDENTNUMBERNUMBER

PK, SAPK, SA

010203

010203

Entity namesEntity names

Primary key namesPrimary key names

PK and SA or UAPK and SA or UA

Sample occurrencesSample occurrences

Basic Relational AnalysisBasic Relational Analysis

Page 31: Database Concepts and Definition of Terms

“Well, Ma and I and the other three-hundred employees have been running this here little health food store just fine without a computer, but we reckon we’d better keep up with the times if we’re gonna keep up with the Joneses, know what I mean? I’m sure you do. Yes, you can assign Employee Numbers if you’d like to…

Anyway, we need to keep track of all these different kinds of items - wheat germ, Vitamin E, chocolate covered granola - that’s a big seller. You better give ‘em all numbers, ‘cause we’ve got more kinds of items than you can shake a stick at. And we need to know which items are sold in which stores, and which aren’t. Be nice to know how many each store’s got on hand, too. Excuse me? No, we don’t have numbers for the stores, but if you want to give ‘em some, its OK with Ma and me..

Did ya know we have stores in three different cities now? Youbetcha. And we’re thinking of branching out to other key cities before too long.”

“Well, Ma and I and the other three-hundred employees have been running this here little health food store just fine without a computer, but we reckon we’d better keep up with the times if we’re gonna keep up with the Joneses, know what I mean? I’m sure you do. Yes, you can assign Employee Numbers if you’d like to…

Anyway, we need to keep track of all these different kinds of items - wheat germ, Vitamin E, chocolate covered granola - that’s a big seller. You better give ‘em all numbers, ‘cause we’ve got more kinds of items than you can shake a stick at. And we need to know which items are sold in which stores, and which aren’t. Be nice to know how many each store’s got on hand, too. Excuse me? No, we don’t have numbers for the stores, but if you want to give ‘em some, its OK with Ma and me..

Did ya know we have stores in three different cities now? Youbetcha. And we’re thinking of branching out to other key cities before too long.”

Basic Relational AnalysisBasic Relational Analysis

Example: Modeling EntitiesExample: Modeling Entities

Page 32: Database Concepts and Definition of Terms

EMPLOYEEEMPLOYEEEMPLOYEEEMPLOYEENUMBERNUMBER

PK, SAPK, SA

123

123

STORESTORESTORESTORECODECODE

PK, SAPK, SA

123

123

ITEMITEMITEMITEMCODECODE

PK, UAPK, UA

456DFG1264SG453FGH4D

456DFG1264SG453FGH4D

CITYCITYCITYCITYCODECODE

PK, UAPK, UA

CBUMLADVO

CBUMLADVO

Basic Relational AnalysisBasic Relational Analysis

Example: Modeling EntitiesExample: Modeling Entities

Page 33: Database Concepts and Definition of Terms

“It seems we’ve got more employees out in the field than ever before. Almost 200 in area N, the north area, and nearly 100 in the south - area S. The eastern area, E, is still the largest though. It’s alright with us if you want to number the employees.

Good thing our customer base is growing as well. Fourteen new customers in the western area alone. You want to number the customers too? Well, why not?

I understand the boss has come up with a classification scheme to keep track of what kind of customers are out there, and what kind of experience we employees have - Class Codes, I think he calls them. Things like B for Banks, G for government agencies, H for hospitals, and so on…”

“It seems we’ve got more employees out in the field than ever before. Almost 200 in area N, the north area, and nearly 100 in the south - area S. The eastern area, E, is still the largest though. It’s alright with us if you want to number the employees.

Good thing our customer base is growing as well. Fourteen new customers in the western area alone. You want to number the customers too? Well, why not?

I understand the boss has come up with a classification scheme to keep track of what kind of customers are out there, and what kind of experience we employees have - Class Codes, I think he calls them. Things like B for Banks, G for government agencies, H for hospitals, and so on…”

Basic Relational AnalysisBasic Relational Analysis

Example: Modeling EntitiesExample: Modeling Entities

Page 34: Database Concepts and Definition of Terms

EMPLOYEEEMPLOYEEEMPLOYEEEMPLOYEENUMBERNUMBER

PK, SAPK, SA

123

123

AREAAREAAREAAREACODECODE

PK, UAPK, UA

SWE

SWE

CUSTOMERCUSTOMERCUSTOMERCUSTOMERCODECODE

PK, UAPK, UA

C451C342C343

C451C342C343

CLASSCLASSCLASSCLASSCODECODE

PK, UAPK, UA

BGH

BGH

Basic Relational AnalysisBasic Relational Analysis

Example: Modeling EntitiesExample: Modeling Entities

Page 35: Database Concepts and Definition of Terms

Workshop:Modeling Entities

Workshop:Modeling Entities

SPECIAL TRAINING EDITIONSPECIAL TRAINING EDITION

Page 36: Database Concepts and Definition of Terms

What is a Relation ?What is a Relation ?

A mode of being, an association, an action or an event that connects two or more entities together is called a relation.

A mode of being, an association, an action or an event that connects two or more entities together is called a relation.

Relational Analysis: Modeling RelationsRelational Analysis: Modeling Relations

Page 37: Database Concepts and Definition of Terms

Types of RelationsTypes of Relations One-to-One Relations

Each occurrence of one entity can be related to zero or one, but no more than one occurrence of another entity.

One-to-Many Relations Each occurrence of one entity, say X, can be related to zero, one

or more occurrences of another entity, say Y; but Y can be related to zero or one, but no more than one occurrence of X.

Many-to-Many Relations Each occurrence of one entity, say X, can be related to zero, one

or more occurrences of another entity, say Y and vice-versa.

One-to-One Relations Each occurrence of one entity can be related to zero or one, but

no more than one occurrence of another entity.

One-to-Many Relations Each occurrence of one entity, say X, can be related to zero, one

or more occurrences of another entity, say Y; but Y can be related to zero or one, but no more than one occurrence of X.

Many-to-Many Relations Each occurrence of one entity, say X, can be related to zero, one

or more occurrences of another entity, say Y and vice-versa.

Relational Analysis: Modeling RelationsRelational Analysis: Modeling Relations

Page 38: Database Concepts and Definition of Terms

Steps in Modeling RelationsSteps in Modeling Relations DISCOVER A RELATION

Ask: Is there a relation between this entity and that entity?

Focus on one relation at a timeIf a relation exists, document that relation in table form before proceeding to the next.

Exhaust all possible relationsFor every entity identified, check if ti has a relation with all other entities defined.

DISCOVER A RELATION Ask:

Is there a relation between this entity and that entity?

Focus on one relation at a timeIf a relation exists, document that relation in table form before proceeding to the next.

Exhaust all possible relationsFor every entity identified, check if ti has a relation with all other entities defined.

Relational Analysis: Modeling RelationsRelational Analysis: Modeling Relations

Page 39: Database Concepts and Definition of Terms

DEFINE THE SCOPE OF THE RELATION

Verify user interest Relations may exist that are of no use or interest to the user. EXCLUDE IT FROM THE MODEL.

Concentrate on direct relationsSome relations can be derived (indirectly) from other relations. EXCLUDE IT FROM THE MODEL.

DEFINE THE SCOPE OF THE RELATION

Verify user interest Relations may exist that are of no use or interest to the user. EXCLUDE IT FROM THE MODEL.

Concentrate on direct relationsSome relations can be derived (indirectly) from other relations. EXCLUDE IT FROM THE MODEL.

Relational Analysis: Modeling RelationsRelational Analysis: Modeling Relations

Page 40: Database Concepts and Definition of Terms

DETERMINE THE TYPE OF RELATION

ASK 2 Questions: Can entity A be related to more than one entity B?Can entity B be related to more than one entity A?

Interpret the answers 2 No answers - one-to-one relation 1 Yes / 1 No answer - one-to-many relation 2 Yes answers - many-to-many relation

DETERMINE THE TYPE OF RELATION

ASK 2 Questions: Can entity A be related to more than one entity B?Can entity B be related to more than one entity A?

Interpret the answers 2 No answers - one-to-one relation 1 Yes / 1 No answer - one-to-many relation 2 Yes answers - many-to-many relation

Relational Analysis: Modeling RelationsRelational Analysis: Modeling Relations

Page 41: Database Concepts and Definition of Terms

DOCUMENT THE RELATION IN TABLE FORM

One-to-one relation Place the foreign key, no duplicates allowed (FK,ND) into the smaller table.

One-to-many relationPlace the foreign key, allowing duplicates (FK) into the table on the YES side of the relation.

Many-to-many relationDraw a new table with a multi-column primary key consisting of two single-column foreign key.

DOCUMENT THE RELATION IN TABLE FORM

One-to-one relation Place the foreign key, no duplicates allowed (FK,ND) into the smaller table.

One-to-many relationPlace the foreign key, allowing duplicates (FK) into the table on the YES side of the relation.

Many-to-many relationDraw a new table with a multi-column primary key consisting of two single-column foreign key.

Relational Analysis: Modeling RelationsRelational Analysis: Modeling Relations

Page 42: Database Concepts and Definition of Terms

One-to-one SituationOne-to-one SituationIn a taxi-service company, each driver is assigned to one and only one unit. On the other hand, each unit is also assigned to one and only one driver.

In a taxi-service company, each driver is assigned to one and only one unit. On the other hand, each unit is also assigned to one and only one driver.

DRIVERDRIVERDriverNumberPK,UA

D1D2D3

DriverNumberPK,UA

D1D2D3

UNITUNITUnitNumberPK,UA

T201T202

UnitNumberPK,UA

T201T202

DriverNumberFK,ND

D1D3

DriverNumberFK,ND

D1D3

The relation is placed on the unit side since there are fewer units than drivers.

The relation is placed on the unit side since there are fewer units than drivers.

Relational Analysis: Modeling RelationsRelational Analysis: Modeling Relations

Page 43: Database Concepts and Definition of Terms

One-to-many SituationOne-to-many SituationA student is allowed to take only one course. However, there could be more than one student enrolled in each of the courses.

A student is allowed to take only one course. However, there could be more than one student enrolled in each of the courses.

COURSECOURSECourseNumberPK,UABSITBSCSBSA

CourseNumberPK,UABSITBSCSBSA

STUDENTSTUDENTStudentNumberPK,UA

S01S02S03

StudentNumberPK,UA

S01S02S03

CourseNumberFK, NNBSITBSITBSCS

CourseNumberFK, NNBSITBSITBSCS

The relation is placed on the student entity being in the YES side of the relation.

The relation is placed on the student entity being in the YES side of the relation.

Relational Analysis: Modeling RelationsRelational Analysis: Modeling Relations

Page 44: Database Concepts and Definition of Terms

Many-to-many SituationMany-to-many Situation

SUBJECTSUBJECTSubjectCodePK,UA

CS11CS12CS13

SubjectCodePK,UA

CS11CS12CS13

STUDENTSTUDENTStudentNumberPK,UA

S01S02S03

StudentNumberPK,UA

S01S02S03

A new table is created to implement the many-to-many relation.

A new table is created to implement the many-to-many relation.

SubjectCodePK,FK

CS11CS12CS11

SubjectCodePK,FK

CS11CS12CS11

STUDENT/SUBJECTSTUDENT/SUBJECTStudentNumberPK,FK

S01S01S02

StudentNumberPK,FK

S01S01S02

Relational Analysis: Modeling RelationsRelational Analysis: Modeling Relations

Page 45: Database Concepts and Definition of Terms

STAFFSTAFF

CITYCITY

ITEMITEM

STORESTORESTA

FFSTA

FF

CIT

YC

ITY

ITEM

ITEM

STO

RE

STO

RE

-- -- 1:M1:M

Using theRelationsMatrix

Using theRelationsMatrix

-- 1:11:1

M:MM:M

Relational Analysis: Modeling RelationsRelational Analysis: Modeling Relations

Page 46: Database Concepts and Definition of Terms

Workshop:Modeling Relations

Workshop:Modeling Relations

SPECIAL TRAINING EDITIONSPECIAL TRAINING EDITION

Page 47: Database Concepts and Definition of Terms

What is an Attribute ?What is an Attribute ?A qualifier of an entity or a relation describing its character, quantity, degree or extent is called an attribute.

A qualifier of an entity or a relation describing its character, quantity, degree or extent is called an attribute.

Relational Analysis: Modeling AttributesRelational Analysis: Modeling Attributes

Page 48: Database Concepts and Definition of Terms

Steps in Modeling AttributesSteps in Modeling Attributes DISCOVER AN ATTRIBUTE

Ask: What other characteristics of [entity or relation] are you interested in?

Focus on one attribute at a timeIf an attribute exists, model it in table form before proceeding to the next attribute.

DISCOVER AN ATTRIBUTE Ask:

What other characteristics of [entity or relation] are you interested in?

Focus on one attribute at a timeIf an attribute exists, model it in table form before proceeding to the next attribute.

Relational Analysis: Modeling AttributesRelational Analysis: Modeling Attributes

Page 49: Database Concepts and Definition of Terms

Steps in Modeling AttributesSteps in Modeling Attributes DEFINE THE SCOPE OF THE ATTRIBUTE

Verify user interest Some attributes are obvious, reasonable, and easy to represent in table form; but they are of no use or interest to the user. EXCLUDE THEM FROM THE MODEL.

Concentrate on real attributesCheck whether the proposed attribute already exists (perhaps in other form) or can be derived from other attributes in the model.

DEFINE THE SCOPE OF THE ATTRIBUTE Verify user interest

Some attributes are obvious, reasonable, and easy to represent in table form; but they are of no use or interest to the user. EXCLUDE THEM FROM THE MODEL.

Concentrate on real attributesCheck whether the proposed attribute already exists (perhaps in other form) or can be derived from other attributes in the model.

Relational Analysis: Modeling AttributesRelational Analysis: Modeling Attributes

Page 50: Database Concepts and Definition of Terms

Steps in Modeling AttributesSteps in Modeling Attributes DEFINE THE KEY OF THE ATTRIBUTE

This steps determines where in a model an attribute is to be placed.

The Prepositional Phrase Method Explicit Prepositional Phrase

The user explicitly says it. Example: the name of each student.

Implicit Prepositional PhraseThe user did not say it; but it is implied. Example: the course of

each student.

DEFINE THE KEY OF THE ATTRIBUTEThis steps determines where in a model an attribute is to be placed.

The Prepositional Phrase Method Explicit Prepositional Phrase

The user explicitly says it. Example: the name of each student.

Implicit Prepositional PhraseThe user did not say it; but it is implied. Example: the course of

each student.

Relational Analysis: Modeling AttributesRelational Analysis: Modeling Attributes

Page 51: Database Concepts and Definition of Terms

Steps in Modeling AttributesSteps in Modeling Attributes DEFINE THE KEY OF THE ATTRIBUTE

PossessivesShorthand for prepositional phrases. Example: the student’s birthday.

The Normalization ProcessInvented by Dr. Edgar F. Codd, the father of relational

database.

The Intuitive ApproachThe key of any given attribute is very obvious.

DEFINE THE KEY OF THE ATTRIBUTE

PossessivesShorthand for prepositional phrases. Example: the student’s birthday.

The Normalization ProcessInvented by Dr. Edgar F. Codd, the father of relational

database.

The Intuitive ApproachThe key of any given attribute is very obvious.

Relational Analysis: Modeling AttributesRelational Analysis: Modeling Attributes

Page 52: Database Concepts and Definition of Terms

Steps in Modeling AttributesSteps in Modeling Attributes DOCUMENT THE ATTRIBUTE IN TABLE FORM

Ask about nullsIf a value is required at all times, mark the column NN.

Ask about duplicatesIf all the values in the column must always be unique, mark the column ND.

Minimize derivative dataIf the values in the column can always be derived from data elsewhere in the model, mark the column DD.

DOCUMENT THE ATTRIBUTE IN TABLE FORM

Ask about nullsIf a value is required at all times, mark the column NN.

Ask about duplicatesIf all the values in the column must always be unique, mark the column ND.

Minimize derivative dataIf the values in the column can always be derived from data elsewhere in the model, mark the column DD.

Relational Analysis: Modeling AttributesRelational Analysis: Modeling Attributes

Page 53: Database Concepts and Definition of Terms

Workshop:Modeling Attributes

Workshop:Modeling Attributes

SPECIAL TRAINING EDITIONSPECIAL TRAINING EDITION

Page 54: Database Concepts and Definition of Terms

NormalizatiNormalization Processon ProcessNormalizatiNormalization Processon Process

SPECIAL TRAINING EDITIONSPECIAL TRAINING EDITION

Page 55: Database Concepts and Definition of Terms

SESSION OBJECTIVESESSION OBJECTIVEThis session will introduce you to the the process of normalization. It will present the purpose of normalization and will teach you how to define normal forms for tables and how to undertake the normalization process.

This session will introduce you to the the process of normalization. It will present the purpose of normalization and will teach you how to define normal forms for tables and how to undertake the normalization process.

Database Concepts and Definition of TermsDatabase Concepts and Definition of Terms

Page 56: Database Concepts and Definition of Terms

COURSECOURSE

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFO. TECHNOLOGYINFO. TECHNOLOGYACCOUNTANCYACCOUNTANCY

STUDENTSTUDENT

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

010102020303

HERBERTHERBERT

NICOLAINICOLAICARMELCARMEL

COURSECOURSE

BSCSBSCSBSCSBSCS

YEARYEAR

112244

TUITIONTUITION

7,000.007,000.00

5,000.005,000.00

CODECODE

PK, UAPK, UA NN, NDNN, ND NN, ND1NN, ND1 FK,ND1FK,ND1PK, SAPK, SA

BSABSA

The Process of Normalization:The Process of Normalization:Redundancy and Update AnomaliesRedundancy and Update Anomalies

STUDENT_COURSESTUDENT_COURSE

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

010102020303

HERBERTHERBERT

NICOLAINICOLAICARMELCARMEL

YEARYEAR

112244

TUITIONTUITION

7,000.007,000.00

5,000.005,000.00

NNNNPK, SAPK, SA

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFO. TECHNOLOGYINFO. TECHNOLOGYACCOUNTANCYACCOUNTANCY

NNNN NNNNNNNN NNNN

Page 57: Database Concepts and Definition of Terms

Normalization / Update Anomalies:

Normalization / Update Anomalies:Insertion AnomaliesInsertion Anomalies

STUDENT_COURSESTUDENT_COURSE

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

010102020303

HERBERTHERBERT

NICOLAINICOLAICARMELCARMEL

YEARYEAR

112244

TUITIONTUITION

7,000.007,000.00

5,000.005,000.00

NN, ND1NN, ND1PK, SAPK, SA

To insert the details of new students in Student_Course table, we must include the details of the courses at which the students are enrolled.

To insert the details of new students in Student_Course table, we must include the details of the courses at which the students are enrolled.

For example, to insert the details of new BSIT student, we must enter the correct details of the BSIT course so that the course details are consistent with values for BSIT in other rows of the Student_Course table.

For example, to insert the details of new BSIT student, we must enter the correct details of the BSIT course so that the course details are consistent with values for BSIT in other rows of the Student_Course table.

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFO. TECHNOLOGYINFO. TECHNOLOGYACCOUNTANCYACCOUNTANCY

NN,ND,NCNN,ND,NC NN, NDNN, ND

Page 58: Database Concepts and Definition of Terms

Normalization / Update Anomalies:

Normalization / Update Anomalies:Insertion AnomaliesInsertion Anomalies

To insert the details of a new course that currently has no enrolled students into the Student_Course table, it is necessary to enter nulls into the attributes for students such as Student Number.

To insert the details of a new course that currently has no enrolled students into the Student_Course table, it is necessary to enter nulls into the attributes for students such as Student Number.

However, the Student Number is the primary key for the Student_Course table, attempting to enter nulls for Student Number violates entity integrity.However, the Student Number is the primary key for the Student_Course table, attempting to enter nulls for Student Number violates entity integrity.

STUDENT_COURSESTUDENT_COURSE

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

010102020303

HERBERTHERBERT

NICOLAINICOLAICARMELCARMEL

YEARYEAR

112244

TUITIONTUITION

7,000.007,000.00

5,000.005,000.00

NN, ND1NN, ND1PK, SAPK, SA

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFO. TECHNOLOGYINFO. TECHNOLOGYACCOUNTANCYACCOUNTANCY

NN,ND,NCNN,ND,NC NN, NDNN, ND

Page 59: Database Concepts and Definition of Terms

Normalization / Update Anomalies:

Normalization / Update Anomalies:Deletion AnomaliesDeletion Anomalies

If we delete a student row from the Student_Course table that represents that last student enrolled in a particular course, the information about that course is also lost from the database.

If we delete a student row from the Student_Course table that represents that last student enrolled in a particular course, the information about that course is also lost from the database.

For example, if we delete the row for student number 02 (Carmel), the information relating to BSIT course is lost from the database.For example, if we delete the row for student number 02 (Carmel), the information relating to BSIT course is lost from the database.

STUDENT_COURSESTUDENT_COURSE

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

010102020303

HERBERTHERBERT

NICOLAINICOLAICARMELCARMEL

YEARYEAR

112244

TUITIONTUITION

7,000.007,000.00

5,000.005,000.00

NN, ND1NN, ND1PK, SAPK, SA

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFO. TECHNOLOGYINFO. TECHNOLOGYACCOUNTANCYACCOUNTANCY

NN,ND,NCNN,ND,NC NN, NDNN, ND

Page 60: Database Concepts and Definition of Terms

Normalization / Update Anomalies:

Normalization / Update Anomalies:Modification AnomaliesModification Anomalies

If we want to change the value of one of the attributes of a particular course, for example the course description for BSIT, we must update the rows of all students enrolled in BSIT.

If we want to change the value of one of the attributes of a particular course, for example the course description for BSIT, we must update the rows of all students enrolled in BSIT.

If this modification is not carried our on all the appropriate rows of the Student_Course table, the database will become inconsistent.If this modification is not carried our on all the appropriate rows of the Student_Course table, the database will become inconsistent.

STUDENT_COURSESTUDENT_COURSE

STUDENTSTUDENTNUMBERNUMBER

STUDENTSTUDENTNAMENAME

010102020303

HERBERTHERBERT

NICOLAINICOLAICARMELCARMEL

YEARYEAR

112244

TUITIONTUITION

7,000.007,000.00

5,000.005,000.00

NN, ND1NN, ND1PK, SAPK, SA

COURSECOURSECODECODE

COURSECOURSEDESCRIPTIONDESCRIPTION

BSCSBSCSBSITBSITBSABSA

COMPUTER SCIENCECOMPUTER SCIENCEINFO. TECHNOLOGYINFO. TECHNOLOGYACCOUNTANCYACCOUNTANCY

NN,ND,NCNN,ND,NC NN, NDNN, ND

Page 61: Database Concepts and Definition of Terms

Sample Case:Sample Case: Process of Normalization Process of Normalization

Enrolment Form ( unnormalized form]Enrolment Form ( unnormalized form]Student NumberDateFamily NameGiven NameMaternal NameGenderCourseYearMajorTerm

Student NumberDateFamily NameGiven NameMaternal NameGenderCourseYearMajorTerm

School YearSubject CodeCourse NumberCourse DescriptionUnitsTimeDaysRoom

School YearSubject CodeCourse NumberCourse DescriptionUnitsTimeDaysRoom

RepeatingGroupsRepeatingGroups

Page 62: Database Concepts and Definition of Terms

Normalization:Normalization:First Normal Form (1NF)

ConversionFirst Normal Form (1NF)

Conversion

STUDENT TABLEStudent NumberDateFamily NameGiven NameMaternal NameGenderCourseYearMajorTermSchool Year

STUDENT TABLEStudent NumberDateFamily NameGiven NameMaternal NameGenderCourseYearMajorTermSchool Year

LOAD TABLEStudent NumberSubject CodeCourse NumberCourse DescriptionUnitsTimeDaysRoom

LOAD TABLEStudent NumberSubject CodeCourse NumberCourse DescriptionUnitsTimeDaysRoom

• Remove repeating groups of attributes and split into 2 or more tables

• Underline key attributes that uniquely identify the rows in each new table.

• Remove repeating groups of attributes and split into 2 or more tables

• Underline key attributes that uniquely identify the rows in each new table.

Page 63: Database Concepts and Definition of Terms

Normalization:Normalization:Second Normal Form (2NF)

ConversionSecond Normal Form (2NF)

Conversion

STUDENT TABLEStudent NumberDateFamily NameGiven NameMaternal NameGenderCourseYearMajorTermSchool Year

STUDENT TABLEStudent NumberDateFamily NameGiven NameMaternal NameGenderCourseYearMajorTermSchool Year

LOAD TABLEStudent NumberSubject CodeCourse NumberCourse DescriptionUnitsTimeDaysRoom

LOAD TABLEStudent NumberSubject CodeCourse NumberCourse DescriptionUnitsTimeDaysRoom

• Isolate any attributes not dependent on the table’s concatenated (composite) primary key.

• Isolate any attributes not dependent on the table’s concatenated (composite) primary key.

LOAD TABLEStudent NumberSubject Code

LOAD TABLEStudent NumberSubject Code

SUBJECT TABLESubject CodeCourse NumberCourse DescriptionUnitsTimeDaysRoom

SUBJECT TABLESubject CodeCourse NumberCourse DescriptionUnitsTimeDaysRoom

Page 64: Database Concepts and Definition of Terms

Normalization:Normalization:Third Normal Form (3NF)

ConversionThird Normal Form (3NF)

Conversion

• Remove attributes dependent on data item(s) other than the primary key.

• Remove attributes dependent on data item(s) other than the primary key.

SUBJECT TABLESubject CodeCourse NumberCourse DescriptionUnitsTimeDaysRoom

SUBJECT TABLESubject CodeCourse NumberCourse DescriptionUnitsTimeDaysRoom

SUBJECT TABLESubject CodeCourse NumberTimeDaysRoom

SUBJECT TABLESubject CodeCourse NumberTimeDaysRoom

COURSE TABLECourse NumberCourse DescriptionUnits

COURSE TABLECourse NumberCourse DescriptionUnits

Page 65: Database Concepts and Definition of Terms

Normalization:Normalization:The Set of Third Normal EntitiesThe Set of Third Normal Entities

STUDENT(Student Number, Date, Family Name, Given Name, Maternal Name, Gender, Course, Year, Major, Term, School Year)

STUDENT(Student Number, Date, Family Name, Given Name, Maternal Name, Gender, Course, Year, Major, Term, School Year)

LOAD (Student Number, Subject Code)LOAD (Student Number, Subject Code)

SUBJECT (Subject Code, Course Number, Time, Days, Room)SUBJECT (Subject Code, Course Number, Time, Days, Room)

COURSE (Course Number, Course Description, Units)COURSE (Course Number, Course Description, Units)

Page 66: Database Concepts and Definition of Terms

Workshop:Normalization Process

Workshop:Normalization Process

SPECIAL TRAINING EDITIONSPECIAL TRAINING EDITION