71
S 2060 Lecture 2 – Data Literacy & Data Mode

Lecture2 slides

Embed Size (px)

DESCRIPTION

Database literacy and modeling

Citation preview

Page 1: Lecture2 slides

BSYS 2060 Lecture 2 – Data Literacy & Data Modeling

Page 2: Lecture2 slides

We live in an information age where data is king.

Page 3: Lecture2 slides

Data often most valuable asset of a companye.g. Aeroplan worth more than Air Canada

Page 4: Lecture2 slides

We live in a data mash-up world.

Page 5: Lecture2 slides
Page 6: Lecture2 slides
Page 7: Lecture2 slides
Page 8: Lecture2 slides
Page 9: Lecture2 slides

Where does data belong?

Page 10: Lecture2 slides

You control completely

You don’t control the data at all

Self-hostedWebsite containing all your data

convenientNot so easy...

Trend is towards you controlling your data

Diaspora

Many “fly by night” Web 2.0 apps

Page 15: Lecture2 slides

Who owns data?

Page 17: Lecture2 slides

Building a database for an organization?

Page 18: Lecture2 slides

What is the organization’s mission?

Page 19: Lecture2 slides

What is the project’s mission?

Page 20: Lecture2 slides

What data is required to make good decisions or for other reporting needs?

Page 21: Lecture2 slides

What data is currently being collected?

Page 22: Lecture2 slides

How is the data collected being used?

Page 23: Lecture2 slides

What data should be collected?

Page 24: Lecture2 slides

What are the main data entities?These will become your tables

Page 25: Lecture2 slides

What are the required fields and field data types?

Page 26: Lecture2 slides

What are the relationships between the tables?

Page 27: Lecture2 slides

Select your tools?e.g. MS Access, MS SQL, MySQL, OracleWhat is being used now if anything?

Page 28: Lecture2 slides

Be careful of the hammer!To a hammer, everything looks like a nail. If you only know MS Access, you may see always see MS Access as the solution even when it’s not. If you only know MS Excel, it seems like the perfect choice!

Source:http://www.flickr.com/photos/fixersphotos/3199566032/

Page 29: Lecture2 slides

Normalization

A brief introduction to the first three forms...

Page 30: Lecture2 slides

“Normalization”

• In the field of relational database design, normalization is a systematic way of ensuring that a database structure is suitable for general-purpose querying and free of certain undesirable characteristics—insertion, update, and deletion anomalies—that could lead to a loss of data integrity.

Codd, E.F. The Relational Model for Database Management: Version 2. Addison-Wesley (1990), p. 271

Page 32: Lecture2 slides

“...insertion, update, and deletion anomalies...”

Until a Course Code is assigned to this record, it can not be inserted in the table

Page 33: Lecture2 slides

“...insertion, update, and deletion anomalies...”

An edit made to one record may not be made to ALL records for the same employee

Page 34: Lecture2 slides

“...insertion, update, and deletion anomalies...”

If the Course Code is deleted the information for the Faculty Member will be lost.

Page 35: Lecture2 slides

Three Normal Forms

• 1NF– Eliminate repeating groups– No redundant data

• 2NF– Eliminate independent data– All fields depend on Primary Key

• 3NF– Eliminate dependency on non-key fields– Fields do not depend on each other

Page 36: Lecture2 slides

Un-Normalized Table (i.e. Excel)

Page 37: Lecture2 slides

First Normal Form (1NF)

0NF – “un-normalized”

1NF

Page 38: Lecture2 slides

Second Normal Form (2NF)

1NF

2NF

Page 39: Lecture2 slides

Third Normal Form (3NF)

2NF

3NF

Page 40: Lecture2 slides

COMPREHENSIVE

Access Tutorial 2

Building a Database and Defining Table Relationships

Page 41: Lecture2 slides

Objectives

• Learn the guidelines for designing databases and setting field properties

• View and modify field data types and formatting

• Create a table in Design view• Define fields and specify a table’s primary key• Modify the structure of a table

New Perspectives on Microsoft Office Access 2007 41

Page 42: Lecture2 slides

Objectives

• Import data from an Excel worksheet• Create a table by importing an existing

table structure• Delete, rename, and move fields• Add data to a table by importing a text

file• Define a relationship between two tables

New Perspectives on Microsoft Office Access 2007 42

Page 43: Lecture2 slides

Guidelines for Designing Databases

• Identify all the fields needed to produce the required information

• Organize each piece of data into its smallest useful part

• Group related fields into tables• Determine each table’s primary key• Include a common field in related tables• Avoid data redundancy• Determine the properties of each field

New Perspectives on Microsoft Office Access 2007 43

Page 44: Lecture2 slides

Guidelines for Setting Field Properties• You must name each

field, table, and other object

• Choose an appropriate data type

New Perspectives on Microsoft Office Access 2007 44

Page 45: Lecture2 slides

Guidelines for Setting Field Properties

• The Field Size property defines a field value’s maximum storage size for Text, Number, and AutoNumber fields only– Byte– Integer– Long Integer– Single– Double– Replication ID– Decimal

New Perspectives on Microsoft Office Access 2007 45

Page 46: Lecture2 slides

Viewing and Modifying Field Data Types and Formatting

New Perspectives on Microsoft Office Access 2007 46

Page 47: Lecture2 slides

Creating a Table in Design View

New Perspectives on Microsoft Office Access 2007 47

Page 48: Lecture2 slides

Defining a Field in Design View

• In the Field Name box, type the name for the field, and then press the Tab key

• Accept the default Text data type, or click the arrow and select a different data type for the field. Press the Tab key

• Enter an optional description for the field, if necessary

• Use the Field Properties pane to type or select other field properties, as appropriate

New Perspectives on Microsoft Office Access 2007 48

Page 49: Lecture2 slides

Defining a Field in Design View

New Perspectives on Microsoft Office Access 2007 49

Page 50: Lecture2 slides

Specifying the Primary Key in Design View

• In the Table window in Design view, click in the row for the field you’ve chosen to be the primary key. If the primary key will consist of two or more fields, click the row selector for the first field, press and hold down the Ctrl key, and then click the row selector for each additional primary key field

• In the Tools group on the Table Tools Design tab, click the Primary Key button

New Perspectives on Microsoft Office Access 2007 50

Page 51: Lecture2 slides

Specifying the Primary Key in Design View

New Perspectives on Microsoft Office Access 2007 51

Page 52: Lecture2 slides

Moving a Field

• To move a field, you use the mouse to drag it to a new location in the Table window in Design view

New Perspectives on Microsoft Office Access 2007 52

Page 53: Lecture2 slides

Adding a Field Between Two Existing Fields

• In the Table window in Design view, select the row for the field above which you want to add a new field

• In the Tools group on the Table Tools Design tab, click the Insert Rows button

• Define the new field by entering the field name, data type, optional description, and any property specifications

New Perspectives on Microsoft Office Access 2007 53

Page 54: Lecture2 slides

Adding a Field Between Two Existing Fields

New Perspectives on Microsoft Office Access 2007 54

Page 55: Lecture2 slides

Importing Data from an Excel Worksheet

• The import process allows you to copy the data from a source without having to open the source file

• Click External Data on the Ribbon• Click the Excel button in the Import group to

start the wizard

New Perspectives on Microsoft Office Access 2007 55

Page 56: Lecture2 slides

Importing Data from an Excel Worksheet

New Perspectives on Microsoft Office Access 2007 56

Page 57: Lecture2 slides

Importing Data from an Excel Worksheet

New Perspectives on Microsoft Office Access 2007 57

Page 58: Lecture2 slides

Importing Data from an Excel Worksheet

New Perspectives on Microsoft Office Access 2007 58

Page 59: Lecture2 slides

Creating a Table by Importingan Existing Table Structure

• Make sure the External Data tab is the active tab on the Ribbon

• In the Import group, click the Access button• Click the Browse button• Navigate to the file• Make sure the Import tables, queries, forms,

reports, macros, and modules into the current database option button is selected, and then click the OK button

• Click the Options buttonNew Perspectives on Microsoft Office

Access 2007 59

Page 60: Lecture2 slides

Creating a Table by Importingan Existing Table Structure

New Perspectives on Microsoft Office Access 2007 60

Page 61: Lecture2 slides

Deleting a Field from a Table Structure

• In Datasheet view, select the column heading for the field you want to delete

• In the Fields & Columns group on the Datasheet tab, click the Delete button

or• In Design view, click in the Field Name box for

the field you want to delete• In the Tools group on the Table Tools Design

tab, click the Delete Rows buttonNew Perspectives on Microsoft Office

Access 2007 61

Page 62: Lecture2 slides

Deleting a Field from a Table Structure

New Perspectives on Microsoft Office Access 2007 62

Page 63: Lecture2 slides

Adding Data to a Table by Importing a Text File

• Click the External Data tab on the Ribbon• In the Import group, click the Text File button• Click the Browse button• Navigate to the file• Click the Append a copy of the records to the

table option button• Select the table• Click the OK button

New Perspectives on Microsoft Office Access 2007 63

Page 64: Lecture2 slides

Adding Data to a Table by Importing a Text File

New Perspectives on Microsoft Office Access 2007 64

Page 65: Lecture2 slides

Defining Table Relationships

• One of the most powerful features of a relational database management system is its ability to define relationships between tables

• You use a common field to relate one table to another

New Perspectives on Microsoft Office Access 2007 65

Page 66: Lecture2 slides

Defining Table Relationships

New Perspectives on Microsoft Office Access 2007 66

Page 67: Lecture2 slides

Defining Table Relationships

• A one-to-many relationship exists between two tables when one record in the first table matches zero, one, or many records in the second table, and when one record in the second table matches at most one record in the first table– The Primary table is the “one” in a one-to-many

relationship– The Related table is the “many” table

New Perspectives on Microsoft Office Access 2007 67

Page 68: Lecture2 slides

Defining Table Relationships

• Referential integrity is a set of rules that Access enforces to maintain consistency between related tables when you update data in a database

• The Relationships window illustrates the relationships among a database’s tables

• Click the Database Tools tab on the Ribbon• In the Show/Hide group on the Database Tools

tab, click the Relationships buttonNew Perspectives on Microsoft Office

Access 2007 68

Page 69: Lecture2 slides

Defining Table Relationships

New Perspectives on Microsoft Office Access 2007 69

Page 70: Lecture2 slides

Defining Table Relationships

New Perspectives on Microsoft Office Access 2007 70

Page 71: Lecture2 slides

Defining Table Relationships

New Perspectives on Microsoft Office Access 2007 71