Está en la página 1de 4

Ex 4: Creating a simple database system (part 1)

This exercise, you will learn how to create a simple database system using MS Access. Upon completion of this exercise, you can use this file to

a. List the chemicals and their quantities at a given lab location

b. Search a given chemical and find out which lab has this chemical.

c. Based on criteria of your query you can determine other fields and obtain data related to this field i.e which lab has flammable chemicals?

d. Add new data into the inventory system i.e. new chemical

In the first part, you will import data from excel, change primary keys, change datatype for some fields and create a relationship.

1.

Open MS Access, select and open a new file and save it as

CMT400ChemInventory.accdb.

2.

Right-click Table1: table situated on the left, you can see a few options including import. Select import and move the pointer to its right where you see the arrow. You will see more options on import. Select excel

3.

Click Browse to find the excel file with the name Data ChemInventory.xls.

4.

After you have located and selected the excel file, tick the top option i.e import the source data into a new table… Then Click OK

5.

Access will need some information from you before it can import the data

6.

Import the three files with the names lab, chem and chem lab relation into Access (See Fig. 4). Note that the primary key for the Chem table is Chemical field and the primary key for the Lab table is Lab (ie lab room number). To set the primary keys:

7.

Right-click the chem table and choose Design view. Move the mouse pointer to the Chemical field name at the leftmost column (the small column next to the Filed name column) just under the yellow key. An orange rectangle surrounding the Chemical record (second row) will be displayed. You also see a few options including primary key. Select primary key. The yellow key should be next to the Chemical fieldname.(See Fig. 4a). Save and close this table.

8.

Now set the primary key for the the lab table by repeating the same procedure as in the Chem table. Open the lab table. Right click the table. Select the lab field as the primary key. Save and close the table.

9.

Right-click Chem lab relation table and select Design view. Change the datatype from text to number for the these fields: amt received, amt used and new balance. Save the table. Close all tables.

10.

We will now create a relationship. Click Database tools in the ribbon and select Relationship from the Show/Hide group. A Show table will be displayed (See Fig. 4b)

11.

Add all three tables and close the dialog box (Fig. 4c)

12.

Select the Chemical field from the chemical table and drag it to the Chemical field in the Chem lab relation table until you see a positive sign. Release the mouse. You will see an Edit relationship dialog box. Select the appropriate check box as in Fig 4d. A one to many relation is also shown in the dialog box. You will see a black line joining the two tables. On one side is 1 and on the other side is

13.

Now relate the lab field in the lab table to the lab field in the chem lab relation table. Select the lab field in the lab table and drag it to the chem. lab relation table. Release the mouse when it changes to a positive sign. Select the appropriate check box as in Fig 4e. A relationship line is also displayed (Fig. 4f)

Borhan/cmt400/Access

Fig. 4 Fig. 4a Borhan/cmt400/Access

Fig. 4

Fig. 4 Fig. 4a Borhan/cmt400/Access

Fig. 4a

Borhan/cmt400/Access

Fig. 4b Fig. 4c Fig. 4d Borhan/cmt400/Access Fig. 4e

Fig. 4b

Fig. 4b Fig. 4c Fig. 4d Borhan/cmt400/Access Fig. 4e

Fig. 4c

Fig. 4b Fig. 4c Fig. 4d Borhan/cmt400/Access Fig. 4e

Fig. 4d

Borhan/cmt400/Access

Fig. 4b Fig. 4c Fig. 4d Borhan/cmt400/Access Fig. 4e

Fig. 4e

Fig. 4f 14. Save the relationship by right-clicking the relationship tab and choose save. Close

Fig. 4f

14. Save the relationship by right-clicking the relationship tab and choose save. Close the relationship tab. 15. Close and save your work.

Borhan/cmt400/Access