Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Computer Science АС (ГСФ) / CS Work at practical classes / 7 Work with package MS Office.doc
Скачиваний:
10
Добавлен:
18.02.2016
Размер:
316.93 Кб
Скачать

Setting the Key and Saving the Table

After you complete your table's fields, you cannot close the table's Design view without designating a field as the table's primary key field. If you do not designate a key and attempt to close the table, Access warns you that no key exists. Access adds a key field using the AutoNumber format if your data does not contain a key field.

Consider adding your own key field for tables that you access often. The key field enables you to search the table more quickly. The key might be a Social Security number, a phone number, or some other code (such as a unique inventory code or customer number) that is unique for each record in the table. The Key field also prevents duplicate entries.

To specify a key field, select the field by clicking the row selector at the left of the field name and then clicking the Primary Key toolbar button (the button with the icon of the key). Access adds a small key icon to the left of the record, indicating the table's key field.

After you add the key field, save the table by clicking the Save button on the toolbar. (If you attempt to close the table before saving it, Access prompts you for a name.) If you don't specify a new name, Access uses Table1 (and Table2, Table3, and so on as you create additional tables); however, you should use a more meaningful table name, such as Tenants, so that you can easily identify the table. When you close the table, Access returns you to the Database window where you will see the table in the right pane.

Modifying Table Structures

The beauty of Access is that, unlike some other database programs, you can easily change the structure of your tables even after you add data. Access makes it easy to add and delete fields, as well as change field properties.

Note

Some table-structure changes affect table data. After you add data to a table, for example, you lose columns of data if you delete fields, and you lose some data through truncation if you limit a field's Size property after you've entered data. If you add fields to an existing table, you must add the data for the new fields in every existing record in the table.

To modify a table, switch to the table's Design view. If you have closed the table and returned to the Database window, select the table name (which now appears in the Database window) and click the Database window toolbar's Design button.

Adding Fields

When you return to the table's Design view, you can add a field to the end of your table just by clicking the first empty Field Name box and entering the field information as you did when adding the table's initial fields.

To insert a new field between two other fields, right-click the row to display the shortcut menu and select Insert Rows. Access opens a new field row and enables you to enter the new field information. Figure 17.7 shows a new field being inserted into a table.

Figure 17.7 The new field will go in the empty space.

Deleting Fields

To delete a field, right-click over the field name and select Delete Rows from the shortcut menu that appears.

Note

Use Undo (Ctrl+Z) to reverse an accidental field deletion. Access supports multiple levels of Undo so that you can reverse several recent row deletions by issuing Undo multiple times. Once you save your new table design, however, you will not be able to reverse the row deletions.

Resizing and Rearranging Fields

Drag your mouse pointer to make minor size adjustments to your table (such as the height of each row and the width of columns). Although the Field Size property determines the exact data storage width of each field in your table, the column widths determine how much of a field you can read while entering and editing table data and the table's structure.

At any time during your table design or subsequent data entry, you can drag a column divider left or right to increase or decrease the width of a column displayed. For example, if your field names are short, you might want to shorten the width of the Field Name column by dragging the right edge to the left to make more room for the field's Description. You can also drag a record divider up or down to increase or decrease a record height.

To rearrange the location of a field, drag the field name by dragging its selector (the gray area to the left of the field) to its new location in the table and release the mouse. Access moves the field to the location you select.

After you make changes to a table's design, Access will prompt you to save your changes when you leave the Design view. Always save any changes you want Access to keep. regardless of the physical order in which you entered the fields. Order your fields in whatever way makes the most sense to you.

Note

The order in which you structure a table's fields has little bearing on the table's use. You can report a table's data in any field order that you want

Соседние файлы в папке CS Work at practical classes