day 15: access chapter 1 rahul kavi [email protected] october 6, 2015 1

16
DAY 15: ACCESS CHAPTER 1 Rahul Kavi [email protected] October 6, 2015 1

Upload: shauna-shields

Post on 05-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

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

DAY 15:ACCESS CHAPTER 1

Rahul Kavi

[email protected]

October 6, 2015

1

Page 2: 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?

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

3

TODAY

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

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

4

ACCESS INTERFACE

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

repair database).

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

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).

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

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)

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

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?

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

8

IDENTIFY PRIMARY KEYS

• Address Table

• PhoneNumber Table

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

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).

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

10

RELATIONSHIP BETWEEN TABLES• Address Table

• PhoneNumber Table

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

11

REFERENTIAL INTEGRITY (IDENTIFY COMMON FIELDS)

• Address Table

• PhoneNumber Table

• Use common field to create a relationship

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

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)”.

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

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.

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

14

THINGS TO DO

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

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

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.

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