Table design

advertisement
ACTIVITY – CREATING TABLES
GOAL
The goal of this practice is to discover the table creation process using MS-ACCESS
software.
SCENARIO
You work as a database designer for a groceries reseller NorthWind that is selling its products
to different warehouses all over the world. Your goal is to define the set of tables that may be
used for storing sales information. The possible ERD structure is shown on the figure below.
CUSTOMER
CustomerID
CompanyName
ContactName
ContactTitle
Addres s
City
PostalCode
Country
Phone
Fax
ORDER
OrderID
OrderDate
RequiredDate
is_placed_by ShippedDate
places
ORDER DETAIL
w ith
w ith
UnitPric e
Quantity
in Dis count
PRODUCT
ProductID
ProductName
Category
Quantity PerUnit
UnitPric e
Units InStock
in Units OnOrder
ReorderLevel
Dis continued
is_taken_by
takes
EMPLOYEE
EmployeeID
f Name
lName
salary
tax
gross s alary
Figure. The ERD for NorthWind System.
YOUR ASSIGNMENT
1. Analyze the ERD structure presented on the figure and think about proper data types
for all fields in the tables Customers, Orders, Order Details, Products and Employees.
Read carefully the document entitled Access Data Types and think all definitions over
in the context of these tables.
2. Create a blank database called SaleSystem. In order to do so undertake the following
steps:
 Click Blank Database under the New category of the New File menu. If you
are on the Getting Started menu, select Create a New File to go to the New File
menu.
 The File New Database dialog box opens. You can see any existing *.mdb
files in the file list part of the window. The New File Database dialog box may
initially open to the My Documents folder. Navigate to the folder you want to
place your new database file in—in the case of the author, it is a folder named
“Access db Files.”
 A default name of db1.mdb will appear in the File Name text box at the bottom
of the window. Simply type over this default name with the name SaleSystem.

(Typing the extension .mdb is optional because Access automatically supplies
it if you do not.)
Click the Create button. When the new database is created, Access
automatically opens it for you.
3. Create the tables Customers, Orders, Order Details, Products and Employees using
the Table Design Window and define the names and types for all fields. Remember
about naming rules which are the following:
 Field names can be from 1 to 64 characters.
 Field names can include letters, numbers, and many special characters.
 Field names cannot include a period (.), exclamation point (!), brackets ([ ]), or
accent grave (`).
 You can’t use low-order ASCII characters, for example Ctrl-J or Ctrl-L (ASCII
values 0 to 31).
 You can’t start with a blank space.
 You can’t use a double quotation mark (“) in the name of a Microsoft Access
project file.
Creating a table design is a multi-step process. By following the steps in
order, your table design can be created readily and with minimal effort:
1. Create a new table.
2. Enter each field name, data type, and description.
3. Enter properties for each defined field (see Understanding field
properties document).
4. Set a primary key.
5. Create indexes for necessary fields.
6. Save the design.
You can use any of these four methods to create a new table design:
1. Click the New toolbar button in the Tables Object container of the
Database window.
2. Select Insert➪Table from the Access menu.
3. Select New Table from the New Object button in the Access toolbar.
4. Select Create table in Design view (first object in Tables pane
of database window) if the New object shortcuts option is turned on.
4. Define the input mask (using input mask wizard) for Postal Code and Phone fields in
table Customers.
5. Change the format of OrderDate field to Medium Date.
6. Change the format of ShippedDate field to Long Date.
7. Change the format of UnitPrice (Order Details table) to Euro and set the validation
rule that will enforce entering only positive numbers. Set the text “the price must be
positive number”.
8. Set the validation rule for OrderDate field. The OrderDate value must be greater than
or equal to current date. Hint: in order to define the current date use predefined
function Date(). Set validation text to “The date must be equal to or greater than
current date”.
9. Create a new field in table Employee, name it BirthDate and set the validation rule for
the age of the employees. The age of the each employee should be lower then 100
years.
10. Create the primary keys for all defined tables.
11. Check your skills in changing a table design.
 Try to insert a new field (in table Customers) with name eMail and type
hyperlink and put it between ContactTitle and Address fields.
 Delete field ContactName.
 In place of ContactName insert two fields ContactFName and ContactLName
(the field type is Text for both cases, think about the length property for these
fields).
12. Define the input mask that will automatically force to uppercase the first character of
the text entered in ContactFName and ContactLName fields in the Customers table.
13. Define the new field in the table Customers. Name it DocNumber and set a data type
to Text. Then define the input mask that will be playing the role of the placeholder for
a document number that consists of two capital letters and seven-digit number. All
letters and digits are required. The letters and the digits are separated with special
characters “-“ and “/”. The example of the document number that may be entered into
this filed is BB-45/05/907.
14. Join created tables according to the schema presented on the figure above and set up
the referential integrity rules (before joining the tables read the document entitled
Understanding relationships between tables). Use Relationship option from Tools
menu.
Download