Sie sind auf Seite 1von 6

Module 2: Creating Table

Microsoft Access 2007

Module 2: Creating Table

Name of Module Learning Outcomes

: :

Creating Table At the end of the lesson, students should be able to: 1. Create table in database. 2. Assign primary key. 2. Insert data into table. At the end of this module, a table below will be created by students (Figure 1).

Module summary

Figure 1: Table Activities summary : This module involved a few activities such as: 1. Creating tables. 2. Assigning primary key. 3. Setting data type. 4. Exercise.

Activitiy 1: Creating Table 1. Open file KPMStudent.accdb as created in Module 1. A database below will be appear (Figure 2).

Figure 2: KPMStudent database 2. The first object to add to your database is a table. You use tables to store all the data in the database. Therefore, now you will be creating the fields that make up a table (database). This is similar to creating a blank personnel form (on paper) that will be "filled-in" for each students

Microsoft Access 2007

Module 2: Creating Table

(Name, Address, Phone Number, etc are called fields in a database). Each "form" is called record in a database. There will be a record (or form) for each student. All the forms, together, make up a table (database). Look at Figure 3 to view the relation of field and record.
record 4

Field 1 (ID)

Field 3 (studentname)

Field 6 (icno)

Field 8 (address)

Figure 3: Fields and records

How many fields and records in the Access table above?

3. The following are the fields that you are going to create in your table: a. ID (auto-created by Access) b. IDNo c. StudentName d. Course e. Gender f. ICNumber g. DOB (Date of birth) h. Address i. Phone j. Email k. Room 4. Click Save to save changes. Rename your table to TableStudent and click OK.

Microsoft Access 2007

Module 2: Creating Table

Figure 4: Saving new table

TableStudent

Figure 5: Renaming table as TableStudent

Activity 2: Assigning Primary Key 1. Every table in Access must have a field that uniquely identifies each record in the table. The primary key ensures that you can retrieve data accurately and efficiently when you pull information from the database. (Note: In Access 2007, the field ID is automatically set as primary key for your table.)
Your primary key must be the most uniquely field to identify each record; which means, no record can have the same value in this field!!

2. To set primary key, click View button to switch to Design View of your table. (Note: Your current view is Datasheet View).

Click here to switch view

Figure 6: Switching to Design View 3. You can see that primary key is set to ID field by default (Figure 7). To change primary key: a. Highlight ID field. b. Click Primary Key button c. Highlight IDNO field. d. Click Primary Key button to deselect. to select.

Microsoft Access 2007

Module 2: Creating Table

Figure 7: Default primary key is ID.

Figure 8: Primary key assigned to IDNO

Activity 3: Setting Data Type 1. Data type can be set in Design View. There are 10 types of data in Access as stated in the table below: Data Types Text Memo Function You may type in any alphabetical/numerical data that you desire-up to a maximum of 255 characters. As indicated, this is a text field, so you can't do mathematical calculations. Examples of Text data are: names, addresses, stock numbers, room numbers, zip codes, etc This field is for lots of text. You can have up to 32,000 characters. This field is for numbers where you want to add, subtract, multiply, divide, average, and do numerical calculations. This field can be a very large size, so when we get to Field Properties, we'll talk about "sizing" this field so it doesn't take up too much "space" in storage. Dates and Times. You may format this later, as you may desire. Dollar ($). You may format this later, as you may desire. For example Ringgit Malaysia (RM). This field is an "automatic" counter that assigns a number each time you put data into a new field. This is a "True/False" or "Yes/No, 0/1 type of field. This means "Object Link Embedding" which indicates you can insert a graphic, picture, sound, etc. Pretty neat to put a photograph in a personnel record or a picture of an inventory item in the stock record (advanced stuff). A hyperlink is a pointer from one object to another. The destination is frequently another Web page, but it can also be a picture, an e-mail address, a file (such as a multimedia file or Microsoft Office document), or a program. The hyperlink itself can be displayed as text or as a picture. This wizard creates a lookup column, which displays a list of values you can choose from.

Number Date/Time Currency AutoNumber Yes/No OLE Object

Hyperlink

Lookup Wizard

Microsoft Access 2007

Module 2: Creating Table

2. Now, change the suitable data type for your fields: a. ID : Autonumber change to Number b. DOB : Text change to Date/Time c. Email : Text change to Hyperlink (Note: Autonumber is the default data type for ID field. Text is the default data type for any fields that you add. )

Figure 9: Setting data type 3. Click Save to save changes to your table.

Exercise: 1. Add 5 records into TableStudent that you have created just now.