INTRODUCTION TO
DATABASE CONCEPTS
MUHAIMIN P. MACAPUNDAG
INTRODUCTION TO DATABASE CONCEPTS
Historical Roots of Database: Files and File Systems
Manual file system: traditionally composed of a collection of file
folders, each properly tagged and kept in a filing cabinet.
As long as data collection was small, the manual system served its
role as a data repository.
Keeping track of data in a manual file system became more difficult.
Finding data - time consuming
Report generation – slow
INTRODUCTION TO DATABASE CONCEPTS
Key Terminologies
Data - raw facts (Ex. Letter A, number 5, or some symbol)
Field - characteristic of entity; column
Record - set of logically related fields; row
File - set of logically related records; table
Database - set of logically related files
INTRODUCTION TO DATABASE CONCEPTS
File System Data Management
Each file must have its own file management system, composed of programs
that allow the user to:
Create the file structure
Add data to the file
Delete data from the file
Modify the data in the file
List the file contents
INTRODUCTION TO DATABASE CONCEPTS
File System Data Management
Modifications are likely to produce errors (bugs), and additional time
can be spent finding the errors in a debugging process.
INTRODUCTION TO DATABASE CONCEPTS
Structural and Data Dependence
Structural dependence
A change in any file’s structure (ex. addition or deletion of a field)
requires modification of all programs using that file
Data dependence
A change in any file’s data characteristics (ex. changing the data
characteristic from integer to decimal) requires changes in all
programs that access the file
INTRODUCTION TO DATABASE CONCEPTS
Field Definitions and Naming Conventions
Field Definition
Data structures are meant to last much longer than application
code. Anyone that has worked on a long running system can attest
to that.
Well defined data structures and table layouts will outlive any
application code.
INTRODUCTION TO DATABASE CONCEPTS
It's not uncommon to see an application completely rewritten
without any changes done to its database schema.
A good (flexible) record definition anticipates reporting
requirements by breaking up fields into their components.
Example:
Student Name: Last Name, First Name, Middle Name
Student Address: Street, Municipality, Province
INTRODUCTION TO DATABASE CONCEPTS
Selecting proper field names is very important
Make sure that the field names are reasonably descriptive.
By simply looking at the field names, we are able to determine to
which files the fields belong to and what information the fields
contain
Example:
Stud_Lastname than Lastname
INTRODUCTION TO DATABASE CONCEPTS
Length of the field name – short but specific
Add a field for primary key (unique key that holds a certain record)
INTRODUCTION TO DATABASE CONCEPTS
Naming Convention
Database models require that objects be named.
While several facets of naming an object deserve consideration, in
this article we’ll focus on the most important one: defining a
convention and sticking to it.
INTRODUCTION TO DATABASE CONCEPTS
Planning a Naming Convention:Table Elements
Naming all the obvious database elements such as:
Tables
Views
Columns
Keys – including the primary key, alternate keys, and foreign keys
Schemas
INTRODUCTION TO DATABASE CONCEPTS
But don’t leave out the less-visible items:
Tablespaces
Constraints
References
Indexes
Stored procedures
Triggers
Sequences
Variables
INTRODUCTION TO DATABASE CONCEPTS
Consider all the decisions that are involved.
The case of the name.You can choose between:
UPPERCASE names
lowercase names
camelCase names – the name starts with a lowercase letter, but new
words start with an uppercase letter
PascalCaseNames (also known as upper camel) – similar to camelCase,
but the name starts with an uppercase letter, as do all additional words
INTRODUCTION TO DATABASE CONCEPTS
How to separate words in names:
you can separate them by case (starting each new word with an
uppercase letter)
you can separate them with an underscore (like_this)
you can separate them with spaces, though that is very
uncommon
Whether to use singular or plural names
INTRODUCTION TO DATABASE CONCEPTS
Database Naming Conventions Best Practices
1. Consistency is always the best policy.
2. Every table should have its own row identifier.
3. Plural or singular names don’t really matter.
4. Prefix names make sense when you include them as an indication of
the object type involved.
5. Never allow the database to put in the constraint names
automatically.
INTRODUCTION TO DATABASE CONCEPTS
6. Use plain old English whenever possible.
7. Spaces are just bad news.
8. Follow the rule of pillar data.
9. Avoid being redundant so you can avoid being redundant.
INTRODUCTION TO DATABASE CONCEPTS
Errors in Database
1. Data Redundancy - same data are stored in the same location
2. Data inconsistency - exists when different and conflicting versions of the
same data appeared in different places (changing the data in a certain field)
3. Data anomalies (abnormality)
Modification anomalies
Insertion anomalies
Deletion anomalies
INTRODUCTION TO DATABASE CONCEPTS
INTRODUCTION TO DATABASE CONCEPTS
Insertion anomaly
If a tuple is inserted in referencing relation and referencing attribute
value is not present in referenced attribute, it will not allow
inserting in referencing relation.
For Example, If we try to insert a record in STUDENT_COURSE
with STUD_NO =7, it will not allow.
INTRODUCTION TO DATABASE CONCEPTS
Deletion and Updation anomaly:
If a tuple is deleted or updated from referenced relation and
referenced attribute value is used by referencing attribute in
referencing relation, it will not allow deleting the tuple from
referenced relation.
For Example, If we try to delete a record from STUDENT with
STUD_NO =1, it will not allow.
INTRODUCTION TO DATABASE CONCEPTS
For Example, If we try to delete a record from STUDENT with
STUD_NO =1, it will not allow. To avoid this, following can be used
in query:
ON DELETE/UPDATE SET NULL
ON DELETE/UPDATE CASCADE
INTRODUCTION TO DATABASE CONCEPTS