+ All Categories
Home > Documents > ITD 256 02

ITD 256 02

Date post: 11-Jul-2016
Category:
Upload: johnsimon
View: 220 times
Download: 2 times
Share this document with a friend
Description:
database
60
ITD 256 Database Concepts Lecture 02
Transcript
Page 1: ITD 256 02

ITD 256 Database Concepts

Lecture 02

Page 2: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 3: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 4: ITD 256 02

Database System

• 2 main Database System Component

– Database

– DBMS

Page 5: ITD 256 02

Database

• 1st Database System Component

• Database

– Self-describing collection of related tables logically stored together to facilitate integration and sharing

• Self-describing – Description of structure contained within database itself

• Related tables – Interrelated data

Page 6: ITD 256 02

Database

– Database Contents

Page 7: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 8: ITD 256 02

DBMS

• 2nd Database System Component

• DBMS (Database Management System) – Computer Program or SOFTWARE to Create,

Process, & Administer the Database

– Receive requests encoded in SQL and translate those into actions on the Database

– Examples are SQL Server, Oracle, Teradata, mySQL, DB2, etc

Page 9: ITD 256 02

DBMS

• Functions of a DBMS

Page 10: ITD 256 02

DBMS

• Functions of a DBMS

• Enforce rules – Data Types

– Limited list or choices

– Business driven rules

– Referential Integrity Constraints • Rules to control data referenced by related values in

related tables

Page 11: ITD 256 02

DBMS

• Functions of a DBMS

• Concurrency

– Ensuring one user’s work does not interfere with another user’s work

Page 12: ITD 256 02

DBMS

• Functions of a DBMS

• Security

– Authentication

– Authorization

– Encrypted Information

– Audit Trail

– Transaction Log

Page 13: ITD 256 02

DBMS

• Functions of a DBMS

• Backup/Recovery

– Ensure no loss of Data in event of errors (hardware, software, natural, or human)

– Backup strategies

– Restore from multiple media & sites

Page 14: ITD 256 02

DBMS

• Functions of a DBMS

• High Availability aka HA

– High Availability solutions like clustering, mirroring, replication, etc.

– HA solutions aim for 99.999% system availability

– Is HA interchangeable with Backup/Recovery?

Page 15: ITD 256 02

DBMS

• Enterprise-Class MS SQL Server 2012

Page 16: ITD 256 02

DBMS

• Enterprise-Class Oracle 11g

Page 17: ITD 256 02

DBMS

• MySQL 5.6

Page 18: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 19: ITD 256 02

Database System

• Personal Database System

– Individual users

– Include few tables

Page 20: ITD 256 02

Database System

• Enterprise-Class Database System

– Enormous Databases supporting organizations

– Hundreds of Databases, millions of records

– Thousands of concurrent users

Page 21: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 22: ITD 256 02

HW 1

1. Figure above shows a list that is used by a veterinary office. Give examples of three modification problems that are likely to occur when using this list. (3pts)

2. Break the list in figure above into two tables, each with data for a single theme. Assume that owners have a unique OwnerEmail and pets have unique PetName column. Indicate the unique identifiers and linking column. (5pts)

3. Describe how the tables you created in Q2 solves the problems you identified in Q1. (3pts)

4. Why is it a bad idea to assume PetName as a unique identifier? (2pts)

5. What is the difference between data and information? (2pts)

6. How is relational model better than traditional file processing? (2pts)

7. Describe in your own words how relationships between single themed tables are represented in a relational database. (2pts)

8. Define the term database. (2pts)

9. What is a DBMS? (2pts)

10. Define the term “Data Anomaly” and give an example. (2pts)

Page 23: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 24: ITD 256 02

Relations

• Relational model developed in 1970s by E.F. Codd

• Referred tables as “Relations” hence the term RDBMS

• Single theme in a table is referred as an “entity”

• Relation is two-dimensional “table” consisting of “rows” & “columns”

• A schema is the organization of data as a conceptual framework; how the database is constructed

Page 25: ITD 256 02

Relations

• Characteristics of a Relation

Page 26: ITD 256 02

Relations

• Are all relational characteristics satisfied?

Page 27: ITD 256 02

Relations

• What relational characteristics are violated?

Page 28: ITD 256 02

Relations

• What relational characteristics are violated?

Page 29: ITD 256 02

Relations

• What relational characteristics are violated?

Page 30: ITD 256 02

Relations

• Presenting Relation Structure

– RELATION_NAME(Col01, Col02, … , … , LastColumn)

– Table or relation name is all uppercase

– Column names have first letter capitalized for each word

– No blank spaces in Relation or Table names

– Relationships are inherent within data, there are no explicit linkage between tables

Page 31: ITD 256 02

Relations

• Presenting Relation Structure

• EMPLOYEE table is represented as

EMPLOYEE (EmployeeNumber, FirstName, LastName, Department, Email, Phone)

Page 32: ITD 256 02

Relations

• Equivalent Sets of Terms

Page 33: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 34: ITD 256 02

Keys

• Key

–One or more columns of a table that is used to identify a row

–A key can be

• Unique

• Nonunique

Page 35: ITD 256 02

Keys

• Unique Key – Query produces single row

– Unique keys?

Page 36: ITD 256 02

Keys

• Nonunique Key – Query produces multiple rows

– Nonunique keys?

Page 37: ITD 256 02

Keys

• Composite Keys

• A key that contains two or more attributes to uniquely identify any record

- OR -

• Unique key is formed by combining two or more attributes

• STUDENT (FirstName, LastName, City, State, Zip, Phone) – Assume none of the individual fields are unique

– What are potential composite keys?

Page 38: ITD 256 02

Keys

• Candidate Keys

• Keys that uniquely identify each row in a table

• Can be single or composite

• EMPLOYEE (EmployeeID, SSN, FirstName, LastName, Department, WorkEmail, HomePhone, CellPhone, ManagerID)

– What are potential candidate keys?

Page 39: ITD 256 02

Keys

• Primary Key

• The candidate key that is chosen as the key that DBMS will use to uniquely identify each row in a relation

• Best practice states that PRIMARY keys are short, numeric, and never change the value

• If EmployeeID is chosen as the PRIMARY KEY:

• EMPLOYEE (EmployeeID, SSN, FirstName, LastName, Department, WorkEmail, HomePhone, CellPhone, ManagerID)

Page 40: ITD 256 02

Keys

• Surrogate Key

• A column with a unique, DBMS-assigned identifier that has been added to a

table to be the primary key.

• Unique values are assigned each time a row is created, like auto-number

• Recall that ideal primary keys are short, numeric, & never changes

• An example of when surrogate key may be the answer

PROPERTY(Street, City, State, ZIP, OwnerID)

PROPERTY(PropertyID, Street, City, State, ZIP, OwnerID)

Page 41: ITD 256 02

Keys

• Foreign Key

• When an attribute in a table A is a Primary key in table B, then that attribute in table A is called a Foreign key to table B.

• EMPLOYEE (EmployeeNumber, FirstName, LastName, “Department”, Email, Phone)

• DEPARTMENT (DepartmentName, BudgetCode, OfficeNumber, DepartmentPhone)

• Department in EMPLOYEE is a foreign key to DEPARTMENT

Page 42: ITD 256 02

Keys

• Foreign Key

• Recall: Relationships are inherent within the data – there are no explicit linkages between tables.

• Foreign Keys form relationship between related tables.

Page 43: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 44: ITD 256 02

Referential Integrity Constraint

• Referential Integrity Constraint

• Every value of a foreign key must match a value of the referred primary key

• EMPLOYEE (EmployeeNumber, FirstName, LastName, “Department”)

• DEPARTMENT (DepartmentName, BudgetCode, DepartmentPhone)

• What is the Referential Integrity Statement?

Page 45: ITD 256 02

Referential Integrity Constraint

• Referential Integrity Constraint

• EMPLOYEE (EmployeeNumber, FirstName, LastName, “Department”)

• DEPARTMENT (DepartmentName, BudgetCode, DepartmentPhone)

Department in EMPLOYEE must exist in DepartmentName in DEPARTMENT

– Note: Foreign Key in CHILD must exist in Primary Key in PARENT

Page 46: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 47: ITD 256 02

Exercise

• A __________ is the organization of data as a conceptual __________ of how the database is constructed.

• When an attribute in a table A is a __________ key in table B, then that attribute in table A is called a __________ key to table B.

• In relational model __________ are inherent within the data so there are no explicit linkages between tables.

• __________ ensures that every value of a foreign key must match a value of the referred primary key.

Page 48: ITD 256 02

CUSTOMER

PRESCRIPTION

• What are Primary keys? Need for Surrogate key?

• Parent/Child tables, Foreign keys?

• Referential Integrity Constraint statement?

Page 49: ITD 256 02

STUDENT DORM

• What are Primary keys? Need for Surrogate key?

• Parent/Child tables, Foreign keys?

• Referential Integrity Constraint statement?

Page 50: ITD 256 02

EMPLOYEE DEPARTMENT

• What are Primary keys? Need for Surrogate key?

• Parent/Child tables, Foreign keys?

• Referential Integrity Constraint statement?

Page 51: ITD 256 02

ATTORNEY_MEETING CLIENT

• What are Primary keys? Need for Surrogate key?

• Parent/Child tables, Foreign keys?

• Referential Integrity Constraint statement?

Page 52: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 53: ITD 256 02

HW 2

1. Explain the difference between a primary key and a candidate key. (2pts)

2. What is a surrogate key and why would you use one? (2pt)

3. Explain the term foreign key. (2pt)

4. Define the term referential integrity constraint. (2pts)

5. Define the terms functional dependency and determinant. (2pts)

6. Define the term primary key in terms of functional dependencies. (2pts)

7. Draw Relations Equivalent set of terms for Table, Row, and Column. (2pts)

8. In your own words, describe the purpose of the normalization process. (2pts)

9. Apply the normalization process to figure above to develop a set of normalized relations (assume PetName is unique in the relation above). Show the results of each of the steps in the normalization process 1,2,3a,3b,3c,3d. (5pts)

10. Draw and populate the two normalized tables from Q9. (4pts)

Page 54: ITD 256 02

Agenda

• Database

• DBMS

• Database System

• Recap HW1

• Relations

• Keys

• Referential Integrity Constraint

• Class Exercise

• HW2

• Quiz

Page 55: ITD 256 02

Quiz Exercise

• CLIENT schema fields – ClientFirst

– ClientLast

– ClientID

– ClientEmail

– AttorneyName

– AttorneyEmail

– AttorneyLocation

Assume a client is assigned an Attorney but attorney serves many clients

Draw the single themed solution

Identify the themes

Page 56: ITD 256 02

Quiz Exercise • CLIENT schema fields

– ClientFirst

– ClientLast

– ClientID

– ClientEmail

– AttorneyName

– AttorneyEmail

– AttorneyLocation

Assume a client is assigned an Attorney but attorney serves many clients

CLIENT

ATTORNEY

Identify the fields

Page 57: ITD 256 02

Quiz Exercise • CLIENT schema fields

– ClientFirst

– ClientLast

– ClientID

– ClientEmail

– AttorneyName

– AttorneyEmail

– AttorneyLocation

Assume a client is assigned an Attorney but attorney serves many clients

CLIENT (ClientFirst, ClientLast, ClientID, ClientEmail)

ATTORNEY (AttorneyName, AttorneyEmail, AttorneyLocation)

Identify the unique identifiers

Page 58: ITD 256 02

Quiz Exercise • CLIENT schema fields

– ClientFirst

– ClientLast

– ClientID

– ClientEmail

– AttorneyName

– AttorneyEmail

– AttorneyLocation

Assume a client is assigned an Attorney but attorney serves many clients

CLIENT (ClientFirst, ClientLast, ClientID, ClientEmail)

ATTORNEY (AttorneyName, AttorneyEmail, AttorneyLocation)

Identify the parent & child tables, add the linking field

Page 59: ITD 256 02

Quiz Exercise • CLIENT schema fields

– ClientFirst

– ClientLast

– ClientID

– ClientEmail

– AttorneyName

– AttorneyEmail

– AttorneyLocation

Assume a client is assigned an Attorney but attorney serves many clients

CLIENT (ClientFirst, ClientLast, ClientID, ClientEmail, “AttorneyEmail”)

ATTORNEY (AttorneyName, AttorneyEmail, AttorneyLocation)

Page 60: ITD 256 02

Quiz Exercise CLIENT (ClientFirst, ClientLast, ClientID, ClientEmail, “AttorneyEmail”)

ATTORNEY (AttorneyName, AttorneyEmail, AttorneyLocation)

– Which table is the PARENT? CHILD?

– Which table can benefit from Surrogate key?

– Candidate Keys in CLIENT besides chosen primary key?

– Candidate Keys in ATTORNEY besides chosen primary key?

– Non-unique keys in CLIENT?

– Non-unique keys in ATTORNEY?

– Referential Integrity Constraint statement?


Recommended