Database Basics: Good Database Design Will Get You Through Poor
Database Basics: Good Database Design Will Get You Through Poor
Relational Database
Definition:
Data stored in tables that are associated by
shared attributes (keys).
Any data element (or entity) can be found in the
database through the name of the table, the
attribute name, and the value of the primary
key.
CRUD !
Refers to the most common Database
Operations:
Create
Read
Update
Delete
Database Tables
Tables represent entities
Tables are always named in the singular,
such as: Vehicle, Order, Grade, etc.
Tables in database jargon are flat files,
dBase or Spreadsheet like..
Attributes
Characteristics of an entity
Examples:
Vehicle (VIN, color, make, model, mileage)
Student (SSN, Fname, Lname, Address)
Fishing License (Type, Start_date, End_date)
Database Views
A View is an individuals picture of a
database. It can be composed of many
tables, unbeknownst to the user.
Its a simplification of a complex data model
It provides a measure of database security
Views are useful, primarily for READ-only
users and are not always safe for CREATE,
UPDATE, and DELETE.
Table Indexing
An Index is a means of expediting the
retrieval of data.
Indexes are built on a column(s).
Indexes occupy disk space; occasionally a lot.
Indexes arent technically necessary for
operation and must be maintained by the
database administrator.
Primary Key #
37
12
49
59
19
44
3
37
12
3
19
49
44
Number
Low
High
59
Database Relationships
How is one entity related to another entity?
Real-world sources:
Ownership
Parentage
Assignment
Regulation
Types of Keys
PRIMARY KEY
Serves as the row level addressing mechanism in the relational
database model.
It can be formed through the combination of several items.
FOREIGN KEY
A column or set of columns within a table that are required to
match those of a primary key of a second table.
These keys are used to form a RELATIONAL JOIN thereby connecting row to row across the individual
tables.
Address
Parcel #
John Smith
T. Brown
18 Lawyers Dr.
14 Summers Tr.
756554
887419
Table B
Parcel #
887419
446397
Assessed Value
152,000
100,000
Database Keys
Primary Key - Indicates uniqueness within
records or rows in a table.
Foreign Key - the primary key from another
table, this is the only way join relationships
can be established.
There may also be alternate or secondary
keys within a table.
Entity Integrity
Entity integrity deals
with within-entity
rules.
These rules deal with
ranges and the
permission of null
values in attributes or
possibly between
records
Enforcing Integrity
Not a trivial task!
Not all database management systems or GIS
software enable users to enforce data
integrity during attribute entry or edit
sessions.
Therefore, the programmer or the Database
Administrator must enforce and/or check for
Integrity.
Referential Integrity
Referential integrity concerns two or more
tables that are related.
Example: IF table A contains a foreign key
that matches the primary key of table B
THEN values of this foreign key either
match the value of the primary key for a
row in table B or must be null.
Functions of a Database
Management System
CRUD
Four basic functions, for a given entity they
should all be performed with few
exceptions, in your system:
CREATE
READ
UPDATE
DELETE
Definition
Retrieval
Functions (COUNT, SUM, MIN, MAX, etc)
Updates and Deletes
SQL Examples
CREATE TABLE SALESREP
Item definition expression(s)
{item, type, (width)}
DELETE table
WHERE expression
Data Retrieval
SELECT list FROM table WHERE
condition
list - a list of items or * for all items
WHERE - a logical expression limiting the
number of records selected
can be combined with Boolean logic: AND,
OR, NOT
ORDER may be used to format results
UPDATE tables
Database Normalization
Normalization: The process of structuring data to
minimize duplication and inconsistencies.
The process usually involves breaking down a
single Table into two or more tables and defining
relationships between those tables.
Normalization is usually done in stages, with each
stage applying more rigorous rules to the types of
information which can be stored in a table.
Normalization
Normalization: a process for analyzing the
design of a relational database
Database Design - Arrangement of attributes into
entities
Greater Complexity
Possibly a greater impact of a failure
Recovery is more difficult
Although these are all debated issues,
opportunities for complete failure are often
reduced with the latest database products, but
reliability results in higher investment costs.