1
Geography 357
Geographic Information Systems
Realtional Databases
Relational data model
• Composed of a set of tables called relations
• Records (rows) in the table are called tuples
• Fields (columns) in the table are called domains
• We will use the terms tables, records, and fields
Relational data model
• Each record represents a logical entity (e.g. a student) (or a relationship)
• Each field represents an attribute (property) of the logical entity
1 Wood Bob C Geog357
2 Kent Chuck B Geog115
3 Smith Jane A Geog357
4 Boone Dan B Geog357
ID Last First Grade Class
Student
Relational data model• Each table has a primary key, one field (or a
combination of fields) that has a unique value for each and every record in the table
ID is the primary key in this table (two students may share either a last or first name)
1 Wood Bob C Geog357
2 Kent Chuck B Geog115
3 Smith Jane A Geog357
4 Boone Dan B Geog357
ID Last First Grade Class
Student
Relational data model
• Tables can be related (joined or linked) together based on their keys.
1 Wood Bob C Geog357
2 Kent Chuck B Geog115
3 Smith Jane A Geog357
4 Boone Dan B Geog357
ID Last First Grade Class
Student
Geog357 48 Jones
Geog115 120 Brower
Geog20 120 Fountain
Class
Name #Stud Instructor
Relational data model
1 Wood Bob C Geog357
2 Kent Chuck B Geog115
3 Smith Jane A Geog357
4 Boone Dan B Geog357
ID Last First Grade Class
Student
Geog357 48 Jones
Geog115 120 Brower
Geog20 120 Mennis
Class
Name #Stud Instructor
Primary key Primary keyForeign key
Relational data model
1 Wood Bob C Geog357
2 Kent Chuck B Geog115
3 Smith Jane A Geog357
4 Boone Dan B Geog357
ID Last First Grade Class
Student
Geog20 120 Brower
Geog115 120 Jones
Geog357 48 Jones
Class
Name #Stud Instructor
Jones 332
Brower 517
Instructor
Name Office
Relational data model
• Normalization– process of structuring tables and table
relationships in a logical way that minimizes data redundancy
– 3 rules or steps in normalization• first normal form
• second normal form
• third normal form
Functional Dependency• Main concept associated with
normalization.• Functional Dependency
– Describes the relationship between attributes in a relation.
– For example, B is functionally dependent on A (denoted A B), if each value of A in relation R is associated with exactly one value of B in relation R.
• Diagrammatic representation.
Relational data model
• First normal form– only one value per field for each record
1 Wood Bob C, B Geog357, Geog20
2 Kent Chuck B, D Geog115, Geog356
3 Smith Jane A, B Geog357, Geog20
4 Boone Dan B, A Geog357, Geog455
ID Last First Grades Classes
Student
Violates first normal form
Relational data model
• Second normal form– each non-primary key field must be totally
dependent on the entire primary key (and not on only part of the primary key)
2 Wood Bob C sophomore
4 Kent Chuck B senior
3 Smith Jane A junior
3 Boone Dan B junior
Year Last First Grade Status
Student
Violates second normal form because Status is dependent only on Year, not on Year/Last/First
primary key
Relational data model
• To resolve second normal form violation - create separate tables
Wood Bob C 2
Kent Chuck B 4
Smith Jane A 3
Boone Dan B 3
Last First Grade Year
Student
1 freshman
2 sophomore
3 junior
4 senior
Year Status
Wood Bob C
Kent Chuck B
Smith Jane A
Boone Dan B
Last First Grade
Year
primary key primary key
Relational data model
1 Wood Bob C Geog357 Jones
2 Kent Chuck B Geog115 Brower
3 Smith Jane A Geog357 Jones
4 Boone Dan B Geog357 Jones
ID Last First Grade Class Instructor
Student
• Third normal form– every field that is not a primary key must be
totally and directly dependent on the primary key (no transitive dependency)
Violates third normal form because Instructor is dependent on Class, not on the primary key ID
Relational data model
• To resolve third normal form violation - create separate tables
1 Wood Bob C Geog357
2 Kent Chuck B Geog115
3 Smith Jane A Geog357
4 Boone Dan B Geog357
ID Last First Grade Class
Student
Geog357 48 Jones
Geog115 120 Brower
Geog20 120 Jones
Class
Name #Stud Instructor
Class is dependent on primary key ID
Instructor is dependent on primary key Name
Why Normalization?
1 Wood Bob C Geog357 Jones
2 Kent Chuck B Geog115 Brower
3 Smith Jane A Geog357 Jones
4 Boone Dan B Geog357 Jones
ID Last First Grade Class Instructor
Student
1. If the instructor to a class changed - all students with that class would have to have their instructors changed
2. Every time a student changed a class, the instructor would also have to be changed
Why Normalization?
1 Wood Bob C Geog115 Jones
2 Kent Chuck B Geog115 Brower
3 Smith Jane A Geog357 Knight
4 Boone Dan B Geog357 Jones
ID Last First Grade Class Instructor
Student
Logical inconsistency
Logical inconsistency
1 Wood Bob C Geog357 Jones
2 Kent Chuck B Geog115 Brower
3 Smith Jane A Geog357 Jones
4 Boone Dan B Geog357 Jones
ID Last First Grade Class Instructor
These update problems may result in logical inconsistencies in the database
Original table
Updated table
Why Normalization?
When the table is in third normal form, these logical inconsistencies cannot take place.
When an instructor is changed, the change is enforced for all students
When a student changes classes, the change is instructor is automatically enforced
1 Wood Bob C Geog357
2 Kent Chuck B Geog115
3 Smith Jane A Geog357
4 Boone Dan B Geog357
ID Last First Grade Class
Geog357 48 Jones
Geog115 120 Brower
Geog20 120 Jones
Class
Name #Stud Instructor
Relational data model
• Operations on the relational data model: defined by relational algebra
– intersection– union– difference– join– projection– selection
Each operation takes one or more tables as input and returns one table as output
Relational data model
• Intersection: find records common to two tables given certain criteria (an and operation)
• Intersection: Find all classes that are Geography classes and that are also Gen Ed classes
Geog357 Jones
Geog115 Brower
Geog20 Fountain
Geog435 Karnes
Geog20 Fountain
Geog115 Brower
Meteo110 Stankle
Meteo200 Turlock
Class Instructor Class InstructorGeography Classes Gen Ed Classes
Geog20 Fountain
Geog115 Brower
Class InstructorResult of Intersection
Relational data model
Relational data model
• Union: find records common to either of two tables (an or operation)
• Union: Find all classes that are either Geography classes or that are Gen Ed classes
Geog357 Jones
Geog115 Brower
Geog20 Fountain
Geog435 Karnes
Geog20 Fountain
Geog115 Brower
Meteo110 Stankle
Meteo200 Turlock
Class Instructor Class InstructorGeography Classes Gen Ed Classes
Geog357 Jones
Geog20 Fountain
Geog115 Brower
Geog435 Karnes
Meteo110 Stankle
Meteo200 Turlock
Class Instructor
Relational data model
Results of Union
Relational data model
• Difference: Find the records in one table that are not also present in another table (an xor operation)
• Difference: Find all classes that are Geography classes but that are not Gen Ed classes
Geog357 Jones
Geog115 Brower
Geog20 Fountain
Geog435 Karnes
Geog20 Fountain
Geog115 Brower
Meteo110 Stankle
Meteo200 Turlock
Class Instructor Class InstructorGeography Classes Gen Ed Classes
Geog357 Jones
Geog435 Karnes
Class Instructor
Relational data model
Results of Difference
Relational data model
• Join: Match records in both tables based on a common field
Geog357 Jones
Geog115 Brower
Geog20 Fountain
Geog435 Karnes
Class InstructorGeography Classes
Jones 332
Brower 423
Fountain 125
Karnes 312
Instructor Office Instructor
Geog357 Jones 332
Geog115 Brower 423
Geog20 Fountain 125
Geog435 Karnes 312
Class Instructor Office
Result of Join
Relational data model
• Projection: reduces one table in the attribute dimension (a selection of a subset of fields, for all records)
• Projection: List all Geography classes, but not the instructors
Geog357 Jones
Geog115 Brower
Geog20 Fountain
Geog435 Karnes
Class InstructorGeography Classes
Relational data model
Geog357
Geog115
Geog20
Geog435
ClassResult of Projection
Relational data model• Selection (restriction): reduces one table in the record dimension (a selection of a subset of
records, for all fields)
• Criteria for selection is called a predicate
• Selection: Find Geography classes taught by ‘Jones’
Geog357 Jones
Geog115 Brower
Geog20 Fountain
Geog435 Karnes
Class InstructorGeography Classes
Relational data model
Result of Selection
Geog357 Jones
Class Instructor