You are on page 1of 66

Database Concepts and Definition of Terms

SPECIAL TRAINING

Database Concepts and Definition of Terms

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

Database Concepts and Definition of Terms

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.

Database

Database Concepts and Definition of Terms

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.

Database Concepts and Definition of Terms

What is a Table ?
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 Terms

Example

COURSE
COURSE CODE BSCS BSIT BSA BSC COURSE DESCRIPTION COMPUTER SCIENCE INFORMATION TECHNOLOGY ACCOUNTANCY COMMERCE

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 Terms

Table 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 unique


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

Database Concepts and Definition of Terms

Example

COURSE
COURSE CODE BSCS BSIT BSA BSC COURSE DESCRIPTION COMPUTER SCIENCE INFORMATION TECHNOLOGY ACCOUNTANCY COMMERCE

STUDENT
STUDENT STUDENT NUMBER NAME 01 02 03 04 HERBERT CARMEL NICOLAI GENE COURSE CODE YEAR TUITION BSCS BSCS BSA BSIT 1 2 4 4 7,000.00 6,500.00 5,000.00 8,000.00

Database Concepts and Definition of Terms

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.
STUDENT STUDENT STUDENT NUMBER NAME 01 02 03 04 HERBERT CARMEL NICOLAI GENE COURSE CODE YEAR BSCS BSCS BSA BSIT 1 2 4 4 STUDENT COURSE CODE BSA BSIT BSCS BSCS STUDENT NUMBER 03 04 02 01 YEAR 4 4 2 1 STUDENT NAME NICOLAI GENE CARMEL HERBERT

Database Concepts and Definition of Terms

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).
STUDENT STUDENT STUDENT NUMBER NAME 01 02 03 04 HERBERT CARMEL NICOLAI GENE COURSE YEAR CODE BSCS BSCS BSA BSIT 1/2 2/3 4 4

Database Concepts and Definition of Terms

Null Values

Def. A missing or unknown value of a column of a table.

Null 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)

Database Concepts and Definition of Terms

Example on Nulls

COURSE COURSE CODE NN BSCS BSIT BSA COURSE DESCRIPTION NN COMPUTER SCIENCE INFORMATION TECHNOLOGY ACCOUNTANCY

STUDENT STUDENT STUDENT NUMBER NAME NN 01 02 03 NN HERBERT CARMEL NICOLAI BSCS BSCS 1 2 4 7,000.00 5,000.00 COURSE CODE YEAR TUITION

Database Concepts and Definition of Terms

Duplicate Values
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.

Database Concepts and Definition of Terms

Example on Duplicate Values

COURSE COURSE CODE NN, ND BSCS BSIT BSA COURSE DESCRIPTION NN, ND COMPUTER SCIENCE INFORMATION TECHNOLOGY ACCOUNTANCY

STUDENT STUDENT STUDENT NUMBER NAME NN, ND 01 02 03 NN, ND1 HERBERT CARMEL NICOLAI COURSE CODE YEAR TUITION ND1 BSCS BSCS 1 2 4 7,000.00 5,000.00

Database Concepts and Definition of Terms

Changeable Values
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.

Database Concepts and Definition of Terms

Example on Changeable Values

COURSE COURSE CODE NN,ND,NC BSCS BSIT BSA COURSE DESCRIPTION NN, ND COMPUTER SCIENCE INFORMATION TECHNOLOGY ACCOUNTANCY

STUDENT STUDENT NUMBER NN,ND,NC 01 02 03 STUDENT NAME NN, ND1 HERBERT CARMEL NICOLAI COURSE CODE YEAR TUITION ND1 BSCS BSCS 1 2 4 7,000.00 5,000.00

Database Concepts and Definition of Terms Primary Keys


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

Primary 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.

Database Concepts and Definition of Terms

Constraints 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.

Database Concepts and Definition of Terms Other Primary Keys Notations system-assigned SA means
Mark a column with SA, in addition to PK if the values are automatically generated by the system.

UA means user-assigned
Mark a column with UA, in addition to PK, if the values of the primary key are assigned by the user.
COURSE COURSE CODE PK, UA BSCS BSIT BSA COURSE DESCRIPTION NN, ND COMPUTER SCIENCE INFORMATION TECHNOLOGY ACCOUNTANCY

Database Concepts and Definition of Terms Foreign Keys


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

Foreign 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.

Database Concepts and Definition of Terms


Foreign Key Rules and Constraints (cont.)
FK values must refer to existing PK values
(Referential Integrity)
COURSE COURSE CODE PK,UA BSCS BSIT BSA COURSE DESCRIPTION NN, ND COMPUTER SCIENCE INFO. TECHNOLOGY ACCOUNTANCY STUDENT STUDENT NUMBER PK,SA 01 02 03 04 STUDENT NAME NN, ND1 HERBERT CARMEL NICOLAI LOUIE COURSE CODE YEAR TUITION FK,ND1 BSCS BSA AB 1 2 4 3 7,000.00 5,000.00

Database Concepts and Definition of Terms

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.

Database Concepts and Definition of Terms

Derivative Data Example


COURSE COURSE CODE PK,UA BSCS BSIT BSA COURSE DESCRIPTION NN, ND COMPUTER SCIENCE INFO. TECHNOLOGY ACCOUNTANCY STUDENT COUNT DD 1 21 0

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.

Basic Relational Analysis


SPECIAL TRAINING

Basic Relational Analysis

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

Basic Relational Analysis

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.

Basic Relational Analysis

Steps in Modeling Entities


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

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

Beware of attributes in disguise


Entities 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 Analysis


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 detail


When 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 Analysis


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 duplicates


Make sure that the proposed primary key is always unique.

Check for changes


The proposed primary key values must never be changed.

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

Basic Relational Analysis


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

COURSE
COURSE NUMBER PK, UA BSCS BSIT BSA

Entity names Primary key names PK and SA or UA Sample occurrences

STUDENT
STUDENT NUMBER PK, SA 01 02 03

Basic Relational Analysis


Example: Modeling Entities
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 wed better keep up with the times if were gonna keep up with the Joneses, know what I mean? Im sure you do. Yes, you can assign Employee Numbers if youd like to Anyway, we need to keep track of all these different kinds of items - wheat germ, Vitamin E, chocolate covered granola - thats a big seller. You better give em all numbers, cause weve 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 arent. Be nice to know how many each stores got on hand, too. Excuse me? No, we dont 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 were thinking of branching out to other key cities before too long.

Basic Relational Analysis


Example: Modeling Entities
EMPLOYEE
EMPLOYEE NUMBER PK, SA 1 2 3

STORE
STORE CODE PK, SA 1 2 3

ITEM
ITEM CODE PK, UA 456DFG1 264SG45 3FGH4D

CITY
CITY CODE PK, UA CBU MLA DVO

Basic Relational Analysis


Example: Modeling Entities
It seems weve 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. Its 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 Analysis


Example: Modeling Entities
EMPLOYEE
EMPLOYEE NUMBER PK, SA 1 2 3

AREA
AREA CODE PK, UA S W E

CUSTOMER
CUSTOMER CODE PK, UA C451 C342 C343

CLASS
CLASS CODE PK, UA B G H

Workshop: Modeling Entities


SPECIAL TRAINING

Relational Analysis: Modeling Relations

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.

Relational Analysis: Modeling Relations

Types 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.

Relational Analysis: Modeling Relations

Steps in Modeling Relations


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

Focus on one relation at a time


If a relation exists, document that relation in table form before proceeding to the next.

Exhaust all possible relations


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

Relational Analysis: Modeling Relations


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 relations


Some relations can be derived (indirectly) from other relations. EXCLUDE IT FROM THE MODEL.

Relational Analysis: Modeling Relations


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 Relations


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 relation
Place the foreign key, allowing duplicates (FK) into the table on the YES side of the relation.

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

Relational Analysis: Modeling Relations

One-to-one Situation
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. DRIVER Driver Number PK,UA D1 D2 D3 UNIT Unit Number PK,UA T201 T202 Driver Number FK,ND D1 D3
The relation is placed on the unit side since there are fewer units than drivers.

Relational Analysis: Modeling Relations

One-to-many Situation
A student is allowed to take only one course. However, there could be more than one student enrolled in each of the courses. COURSE Course Number PK,UA BSIT BSCS BSA STUDENT Student Number PK,UA S01 S02 S03 Course Number FK, NN BSIT BSIT BSCS
The relation is placed on the student entity being in the YES side of the relation.

Relational Analysis: Modeling Relations

Many-to-many Situation
STUDENT Student Number PK,UA S01 S02 S03 STUDENT/SUBJECT Subject Student Code Number PK,FK PK,FK CS11 S01 CS12 S01 CS11 S02
A new table is created to implement the many-to-many relation.

SUBJECT Subject Code PK,UA CS11 CS12 CS13

Relational Analysis: Modeling Relations

Using the Relations Matrix

STAFF CITY ITEM STORE

M:M

STORE
1:M 1:1

STAFF

CITY

ITEM

Workshop: Modeling Relations


SPECIAL TRAINING

Relational Analysis: Modeling Attributes

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

Relational Analysis: Modeling Attributes

Steps in Modeling Attributes


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

Focus on one attribute at a time


If an attribute exists, model it in table form before proceeding to the next attribute.

Relational Analysis: Modeling Attributes

Steps 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 attributes


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

Relational Analysis: Modeling Attributes

Steps 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 Phrase


The user did not say it; but it is implied. Example: the course of each student.

Relational Analysis: Modeling Attributes

Steps in Modeling Attributes


DEFINE THE KEY OF THE ATTRIBUTE Possessives
Shorthand for prepositional phrases. Example: the students birthday.

The Normalization Process


Invented by Dr. Edgar F. Codd, the father of relational database.

The Intuitive Approach


The key of any given attribute is very obvious.

Relational Analysis: Modeling Attributes

Steps in Modeling Attributes


DOCUMENT THE ATTRIBUTE IN TABLE FORM Ask about nulls
If a value is required at all times, mark the column NN.

Ask about duplicates


If all the values in the column must always be unique, mark the column ND.

Minimize derivative data


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

Workshop: Modeling Attributes


SPECIAL TRAINING

Normalization Process
SPECIAL TRAINING

Database Concepts and Definition of Terms

SESSION OBJECTIVE
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.

The Process of Normalization: Redundancy and Update Anomalies


COURSE COURSE CODE PK, UA BSCS BSIT BSA COURSE DESCRIPTION NN, ND COMPUTER SCIENCE INFO. TECHNOLOGY ACCOUNTANCY STUDENT_COURSE STUDENT NUMBER PK, SA 01 02 03 STUDENT NAME NN HERBERT CARMEL NICOLAI YEAR NN 1 2 4 TUITION NN 7,000.00 5,000.00 COURSE CODE NN BSCS BSIT BSA COURSE DESCRIPTION NN COMPUTER SCIENCE INFO. TECHNOLOGY ACCOUNTANCY STUDENT STUDENT NUMBER PK, SA 01 02 03 STUDENT NAME NN, ND1 HERBERT CARMEL NICOLAI COURSE CODE YEAR TUITION FK,ND1 BSCS BSCS BSA 1 2 4 7,000.00 5,000.00

Normalization / Update Anomalies: Insertion Anomalies


STUDENT_COURSE STUDENT NUMBER PK, SA 01 02 03 STUDENT NAME NN, ND1 HERBERT CARMEL NICOLAI 1 2 4 7,000.00 5,000.00 YEAR TUITION COURSE CODE NN,ND,NC BSCS BSIT BSA COURSE DESCRIPTION NN, ND COMPUTER SCIENCE INFO. TECHNOLOGY ACCOUNTANCY

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.

Normalization / Update Anomalies: Insertion Anomalies


STUDENT_COURSE STUDENT NUMBER PK, SA 01 02 03 STUDENT NAME NN, ND1 HERBERT CARMEL NICOLAI 1 2 4 7,000.00 5,000.00 YEAR TUITION COURSE CODE NN,ND,NC BSCS BSIT BSA COURSE DESCRIPTION NN, ND COMPUTER SCIENCE INFO. TECHNOLOGY ACCOUNTANCY

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.

Normalization / Update Anomalies: Deletion Anomalies


STUDENT_COURSE STUDENT NUMBER PK, SA 01 02 03 STUDENT NAME NN, ND1 HERBERT CARMEL NICOLAI 1 2 4 7,000.00 5,000.00 YEAR TUITION COURSE CODE NN,ND,NC BSCS BSIT BSA COURSE DESCRIPTION NN, ND COMPUTER SCIENCE INFO. TECHNOLOGY ACCOUNTANCY

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.

Normalization / Update Anomalies: Modification Anomalies


STUDENT_COURSE STUDENT NUMBER PK, SA 01 02 03 STUDENT NAME NN, ND1 HERBERT CARMEL NICOLAI 1 2 4 7,000.00 5,000.00 YEAR TUITION COURSE CODE NN,ND,NC BSCS BSIT BSA COURSE DESCRIPTION NN, ND COMPUTER SCIENCE INFO. TECHNOLOGY ACCOUNTANCY

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.

Sample Case: Process of Normalization Enrolment Form ( unnormalized form]


Student Number Date Family Name Given Name Maternal Name Gender Course Year Major Term School Year Subject Code Course Number Course Description Units Time Days Room

Repeating Groups

Normalization: First Normal Form (1NF) Conversion


Remove repeating groups of attributes and split into 2 or more tables Underline key attributes that uniquely identify the rows in each new table.
STUDENT TABLE Student Number Date Family Name Given Name Maternal Name Gender Course Year Major Term School Year LOAD TABLE Student Number Subject Code Course Number Course Description Units Time Days Room

Normalization: Second Normal Form (2NF) Conversion


Isolate any attributes not dependent on the tables concatenated (composite) primary key.
STUDENT TABLE Student Number Date Family Name Given Name Maternal Name Gender Course Year Major Term School Year LOAD TABLE Student Number Subject Code Course Number Course Description Units Time Days Room LOAD TABLE Student Number Subject Code SUBJECT TABLE Subject Code Course Number Course Description Units Time Days Room

Normalization: Third Normal Form (3NF) Conversion


Remove attributes dependent on data item(s) other than the primary key.
SUBJECT TABLE Subject Code Course Number Course Description Units Time Days Room SUBJECT TABLE Subject Code Course Number Time Days Room COURSE TABLE Course Number Course Description Units

Normalization: The Set of Third Normal Entities


STUDENT (Student Number, Date, Family Name, Given Name, Maternal Name, Gender, Course, Year, Major, Term, School Year) LOAD (Student Number, Subject Code) SUBJECT (Subject Code, Course Number, Time, Days, Room) COURSE (Course Number, Course Description, Units)

Workshop: Normalization Process

SPECIAL TRAINING

You might also like