DAY 15: ACCESS CHAPTER 1 Rahul Kavi Rahul.Kavi@mail.wvu.edu October 6, 2015 1.

Post on 05-Jan-2016

217 views 0 download

Tags:

Transcript of DAY 15: ACCESS CHAPTER 1 Rahul Kavi Rahul.Kavi@mail.wvu.edu October 6, 2015 1.

DAY 15:ACCESS CHAPTER 1

Rahul Kavi

Rahul.Kavi@mail.wvu.edu

October 6, 2015

1

2

LAST LECTURE

• Introduction to Databases.• Tables.• Fields.• What is a primary key?

3

TODAY

• Creating databases.• Saving databases.• Creating tables.• Design tables.• Modify tables.• Set Primary key.• Set a relationship.• Import xml data.

4

ACCESS INTERFACE

• Ribbon interface.• Create (tables, forms, queries, reports)• External data(import data, export data)• Database tools (relationships, compact-

repair database).

5

TABLES

• Similar to a Excel Worksheet.• But can have “relationships” with other

tables.• If we enforce relationships between tables,

Access will enforce rules in data entering, editing, retrieval and removal.

• This makes it easier to manage and retrieve data (by enforcing relationships between tables).

6

TABLES: PRIMARY KEY

• The primary key uniquely identifies each record in a table.

• By default, tables have an ID field that is an auto-incremented integer– Whenever a new record is entered, its count

goes up by 1 (you can change this behavior)

7

EXAMPLE OF PRIMARY KEY

• How to come up with a primary key?• How do you uniquely identify something in

a given data table?• Name? (multiple people with same name)• SSN? Student ID? Email ID?• How do you uniquely identify a student

based on given data (on paper)? WVU ID, Phone Number?

8

IDENTIFY PRIMARY KEYS

• Address Table

• PhoneNumber Table

9

EXCEL VS ACCESS (TABLES)

• What do we use (Excel or Access) in this scenario (to store data)? If customer loses credit card, delete old credit card info, enter new credit card information. But this information cannot be empty.

• The above scenario is hard to do in Excel, but easy in Access.

• Cells can be left empty in Excel.• Records in Access can be forced to entered with

some value (and not left empty).

10

RELATIONSHIP BETWEEN TABLES• Address Table

• PhoneNumber Table

11

REFERENTIAL INTEGRITY (IDENTIFY COMMON FIELDS)

• Address Table

• PhoneNumber Table

• Use common field to create a relationship

12

RELATIONSHIPS: REFERENTIAL INTEGRITY• Wikipedia: “Referential integrity is a

property of data which, when satisfied, requires every value of one attribute (column) of a relation (table) to exist as a value of another attribute in a different (or the same) relation (table)”.

13

WHAT HAPPENS IF WE ENFORCE REFERENTIAL INTEGRITY?

• With referential integrity, we can relate fields in one table with fields in another table.

• Otherwise, Access will not know they are related.

14

THINGS TO DO

• Download data files for today.• Open instructions (pdf).• Follow instructions

15

NEXT CLASS

• What happens if referential integrity is not enforced.

• What happens when referential integrity is enforced.

• Access Forms.• Creating forms to enter data.• Basic Queries.