access tables 1. creating a table design view define each field and its properties data sheet view...

42
Access Tables 1

Upload: citlali-sellinger

Post on 31-Mar-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Access Tables

1

Page 2: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Creating a Table• Design View

• Define each field and its properties

• Data Sheet View• Essentially spreadsheet• Enter fields• You must go to design view to set field

properties the way you want them

• Templates(2k7 and earlier)• Create table using predefined templates• Use design view to change field property

defaults of template2

Page 3: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Design View Access 2k7 & 2K10

• Select Create Tab• Select Table Design• Enter your data fields

• For each field select the data type• Based upon data type selected you can set

additional properties for the field• Enter description (good systems documentation

tool)

3

Page 4: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Design View Access 2007/2010

• Define your Primary Key(s)• Highlight field(s) that will be Primary key(s)• Select Key symbol to set primary key

• Save your table• You can click on save symbol

• You will be asked to give table a name

• Click on close symbol• You will be asked if you want to save changes• You will be asked to give table a name

4

Page 5: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Table Design

5

Page 6: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

6

Define Data Type

Define additional Properties for each

Field

Enter Fields

Enter Description for documentation

purposes

Page 7: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Data Types

7

Data type Description Text Text data, including numbers that don't require

calculations. Text can be up to 255 characters in length.

Memo Longer blocks of text, up to 65,535 characters

Number Numeric data that might be used in calculations

D ate /T im e Dates and times

Currency Currency (monetary) values. Also used to prevent rounding off dur ing calculations

AutoNumber Creates unique sequential (incrementing by 1) or random ID numbers and replication IDs.

Yes/No Two-valued data, such as Yes/No, True/False. Null values are not allowed

OLE Object OLE objects such as Word documents or Excel worksheets. Hyperlinks (either URLs or UNC paths).

Hyperlinks Hyperlinks (either URLs or UNC paths).

Lookup Wizard Not really a data type. Allows you to select a value for a f ield from another table or a list of values

Page 8: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Common Field Properties(available properties function of data type)• Field Size:

• determines the length of text and number fields

• Format: • customizes the way fields including number,

dates, times, and text appear when they are printed or displayed

• Input Mask: • makes user data entry easier by displaying a

mask (template) into which the user types data• (xxx)-xxx-xxxx

8

Page 9: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Field properties include:

• Caption: • the caption specifies an alternative field name

that appears in forms and reports as well as the datasheet view of a table or query• More user friendly

• Default Value: • the value that is automatically assigned a field

when you create a new record

9

Page 10: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Field properties include:

• Validation Rule and Validation Text: • Validation Rule property specifies, in a logical

expression, the value(s) or range of values that are permitted for the field.

• Validation Text is an error message displayed whenever a user enters a value not allowed for the field.

10

Page 11: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Field properties include:• Required:

• The required property is “Yes” or “No”. When set to “Yes,” the associated field must have a value—it cannot be empty

• Indexed: • Containing either “Yes” or “No,” the indexed

property indicates whether or not Access maintains a special, separate data area called an index that speeds searches on the field.

• Indexed fields are faster to search.

11

Page 12: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

12

In design view, Highlight field you want to be

primary key and select Primary

key symbol

Primary Key

Page 13: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

13

Key symbol indicates that Field One is

Primary key

Page 14: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

14

Key symbol indicates that Field One and Field Two

are Primary keys

Page 15: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

15

Enter name you want to Give

your table here and click on

OK

Click on Save

symbol

Page 16: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

16

Click on Close symbol and select yes to save changes

Page 17: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

17

Enter name you want to Give

your table here and click on

OK

Page 18: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

18

Saved Table

Page 19: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Data sheet View Access 2007/2010

• Select Create Tab• Select Table

• Table with a default primary key is created

• Click on Add New Field and enter Field Label for each Filed you want in table

• Enter Design View to define data types and properties for each field

• Change default Primary Key Field if necessary• Save your table

19

Page 20: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Data sheet View Access 2007

20

Select Table

Page 21: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

21

Click on Add New Field and

enter Field Label

Page 22: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

22

Click on View Symbol and select Design View to define field properties

Page 23: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

23

Define data type for each field

and any properties

Page 24: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Entering Data into table• Enter data for each field in a record• Data is automatically saved as you go to

enter next record• You will not be prompted to save when you exit

the table

• Situations where you will be prompted to save when exiting a table• Changes made in design view to field

properties• Changing display characteristics(how you view

it on the screen)24

Page 25: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Table (relation) Properties

• Each row(record) is unique• Columns(fields) for any record(row)

• Single valued(no repeating groups)• Values are like data type

25

Page 26: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Primary Key Attributes

• Primary key is a Field/column (or group of fields/columns) that uniquely identifies a given row(record)• the SaleID column, for example (on the next

slide)• Primary key can not be null (entity integrity

rule)• Guarantees uniqueness of entities and enables

proper referencing of primary key values by foreign key values

26

Page 27: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Primary Key Example

27

Primary Key

SaleID Date Amount SalespersonID

061401A 6/14 $4,218 123456

061401B 6/14 $6,437 654321

061501A 6/15 $1,112 654321

Sale Table

Page 28: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Foreign Key Attribute

• Foreign key is an attribute in one table that must match the primary key in another table or be null(referential integrity rule)• A primary key from a different table that has

been posted into the table to create a link(relationship)between the two tables

• the SalespersonID of Sales Rep table is a foreign key in the Sale Table

28

Page 29: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Foreign Key example

29

SalespersonID Name

123456 Fred

654321 Francis

SaleID Date Amount SalespersonID

061401A 6/14 $4,218 123456

061401B 6/14 $6,437 654321

061501A 6/15 $1,112 654321

Sale Table

Sales Rep Table

Page 30: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Creating Relationships

• Click on the relationship symbol• From the pop up box add the tables • Establish the relationship between the

tables• Enforce referential integrity• Cascade updates

• When exiting relationship view, save your changes

30

Page 31: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Referential integrity

• Referential Integrity are a set of rules that prevent addition, deletion or modification of data in a table if the changes would create a problem with a relationship• You can’t enter a value in foreign key field of a

related table unless there’s a matching value in the primary key of the primary(parent) table• Example- you can’t enter an order for a CustomerID

that does not exist in the customer table

31

Page 32: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Referential integrity• Prohibits removal of a parent table row until all

the rows in another table(s) referring to the parent table are first removed• You can’t delete a customer record from the

Customer table if there are associated invoices—linked back to the Customer table—in the Invoice table.

• To remove a “Parent” table record, you first have to delete all occurrences of “child” table records.

• Referential integrity essentially prevents “orphans”—records in related tables that have no master record in a “parent” table

32

Page 33: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Referential integrity

• You can’t change primary key value in the primary(parent ) table if there are matching records in the related table(s)• If you select cascade update related fields option

when establishing referential integrity, changes to primary key in parent table will be updated in the related table(s)

33

Page 34: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

34

Creating Relationships(2k7 & 2K10)

Select database Tools tab and then select relationships

Page 35: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

35

you will see a box similar to one on right. Select each table and click on add.

Page 36: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

36

First, Click on SalespersonID

Then, drag to matching attribute in other table

Page 37: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

37

• Enforce referential integrity

• Cascade updates• Select create

Page 38: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

38

Page 39: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Primary key/Foreign Key

• Establishing relationship• Primary key/Foreign key must

be like type data types• Auto# cannot be FK Data Type

PK FKauto# Auto# NOAuto# Number Yes

Number Auto# NONumber Number YesNumber Text NO

Text Text YesText Number NO

39

Page 40: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Edit Relationship

• Enter relationship window• Right click on the relationship line

between tables• Select from the pop-up box

• Edit relationship or• delete

40

Page 41: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

41

Right click on relationship line

Page 42: Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to

Database demos & exhibits

• On class web site• http://bergg.etsu.edu/classpages/4310/431

0databasedemos.htm

42