Database 2: Database Creation and Management
Database 2: Database Creation and Management
OrderNum Short Text primary key Field size (3), Required (Yes)
BillingDate Date/Time
InvoiceAmt Currency
Primary Key
is a key in a relational database system that
is unique for each record (or row) and a table
as well.
Unique identifier of each record (and table).
Example:
SS#, driver license number, vehicle identification
number (VIN).
Rule for Primary Key
No “null” value can be allowed.
Null value does not mean zero.
OK to have “null” value for a non-PK.
Adding Records to a Table
Enter data sequentially in Datasheet view
Use tab key to enter data
Add following data to each filed: 211, 201, paid (mark the
DEPARTMT EMPLOYEE
A one-to-one relationship
A one-to-one relationship exists when one
table has one record associated with only
one record of another table.
Example on the class website (PK as FK)
Primary table: customer table
Related table: Shipping Address table
1:M relationship in set notation
DEPARTMT EMPLOYEE
M:N relationship in set notation
(Not Possible using Access)
PRODUCT
WAREHOUSE
Importing External Access Table and
Excel Worksheet
Very common practice in real world.
Almost any data type (e.g., text)
Barbara also wants you to include the Product and
Order Detail tables from the FineFood database in
the Restaurant database.
Download and Review design view of FineFood
DB first
Composite FK in “Order Detail” table
Importing External Access Table and
Excel Worksheet (con’t)
And she wants you to include the Billing Address
Excel worksheet as a Access table in the Restaurant
database.
Before try to import the excel file, review it first
Use Excel column headings for Access table
PK: CustomerNum
Specify in the description area of Design View that
CutomerNum is not only primary key of BillingAddress table
but also a foreign key of Customer table.
Enforcing referential integrity
Referential integrity makes sure to maintain the
integrity and consistency between related tables.
If you choose to enforce referential integrity, you can insure
that you will not have records that have no matching
record in the primary table.
That is, when updating or deleting a record (PK) in the
primary table, a matching record (FK) in the related record
must be updated or deleted.
Two Ways:
Cascade Update & Cascade Delete
In Access referential integrity, there are two options.
If you choose Cascaded Update, making a change in a field
that is common to two related tables will cause the update
to be made in both tables.
If you delete a field that is common to two tables, the
deletion will take place in both tables.
Try Referential Integrity Example DB on the class
web page.
Creating Relationship
Download Restaurant 2 from the class web
Create relationships using 5 table
To create a relationship between Customer and
BillingAddress, start from the Customer table.
Enforce referential integrity
Primary key of the Order Detail table
Composite PK: OrderNum + ProductCode
Otherwise, a duplication of the quantity field in both the
Order and Product tables.
Creating Relationship con’t