
- •7 Work with package ms Office: ms Access
- •Database Basics
- •Database Tables
- •Records and Fields
- •Using a Key Field
- •Looking at Access
- •Creating a Database
- •Understanding Database Objects
- •To Do: Create a Table
- •Setting Field Properties
- •Setting the Key and Saving the Table
- •Modifying Table Structures
- •Viewing Table Design and Entering Simple Data
- •Summary
To Do: Create a Table
You must create tables before you can enter data in a database. The tables hold the data on which the other objects operate.
When you create a table, you follow these general steps:
-
After creating a new database, select the Database window's option called Create Table in Design View and then click Open to create a new table. The Design view window appears (shown in Figure 17.5). You must now describe your table's fields in the Design view dialog box.
Figure 17.5 Define your table's fields in the Design view window.
-
Type a field name, such as First Name or Quantity , for the first field in your database. The names have nothing to do with the data type that you will eventually store in the table's field. The field name enables you to refer to the field as you design your table. Only after you completely design the table do you enter data in the table. The order in which you add fields does not affect the order in which you ultimately enter the table data. Nevertheless, try to add the fields in the general order in which you want to enter the table data.
-
Press Tab and click the drop-down list that appears in the Data Type field to select the field's data type.
-
Press Tab and type a description for the field. Some field names are optional and don't require a description, but the more you document and describe your data, the easier it is to modify your database later.
-
After you enter the first field's name, data type, and optional description, describe the field properties in the lower half of the Design view dialog box. Some fields do not require property settings, but most require some type of setting.
The next section describes in more detail how you set field property values.
Setting Field Properties
The lower half of the Design view contains settings for your field property values. Each field has a data type, as you already know. In addition to describing the field's data type in the Design view's top half, you can further refine the field's description and limitations in the Field Properties section.
You can configure a different set of field property values for each data type. Text fields contain properties related to text data (such as an address or a name), whereas numeric fields contain properties related to numbers (such as decimal positions).
The field properties appear in the lower half of the screen. A few common field property values that you might want to set as you create your table are as follows:
-
Field Size— Limits the number of characters the field can hold, thereby limiting subsequent data entry of field data.
-
Format— Displays a drop-down list with several formats that the field's data type can take.
-
Caption— Holds a text prompt that Access displays when you enter data into this table's field. If you don't specify a caption, Access uses the field name. Access displays the caption in its status bar when you enter data into the table.
-
Default Value— Contains the field's default value, which appears when you enter data into this table. The user can enter a value that differs from the default if desired. A common default field value would be your company's state. Many of your vendors will be located in your own state so, if this is the case, your vendor database's State field would include your company's state as the default value.
-
Required— Holds either Yes or No to determine whether Access requires a value in this field before you can save a table's data record. If you don't want the user leaving a field blank, enter Yes for the Required property.
-
Decimal Places— Holds the number of default decimal places shown for numbers entered into this field.
Figure 17.6 shows a completed table's Design view. The selected field's (the field with the arrow, or field selector in the left column) property values appear at the bottom of the dialog box. As you enter your own table fields, edit any information that you type incorrectly by clicking the field name, data type, description, or property value, and move the insertion point to the mistake to correct the problem.
Figure 17.6 A complete table definition shows you how the column names, data types, and descriptors appear.