Designing a Table from Scratch
Many people believe that designing tables from
scratch offers flexibility and encourages good design principles.
Although it requires some knowledge of database and table design, it
gives you more control and precision than designing a table from
datasheet view. It allows you to select each field name and field type,
and to define field properties. To design a table from scratch, you
select Tables from the list of objects and double-click the Create
Table in Design View icon. The Table Design view window appears.
When the Table Design view window appears, follow these steps to design a table:
1. | Define each field in the table by typing its name in the Field Name column.
|
2. | Tab
to the Data Type column. Select the default field type, which is Text,
or use the drop-down combo box to select another field type. Note that if you use the Field Builder, it sets a data type value for you that you can modify.
If you forget a field and need to insert it later,
you can right-click the column heading to the right of where you want
to insert the new column and then select Insert Field from the context
menu. Access inserts a column that you can rename by double-clicking
the column heading. You can then use the Fields tab of the Ribbon to
set properties of the field.
|
|
3. | Tab
to the Description column and enter a description for the data. What
you type in this column appears on the status bar when the user is
entering data into the field. This column is also great for documenting
what data is actually stored in the field.
|
4. | Continue
entering fields. If you need to insert a field between two existing
fields, click the Insert Rows button in the Tools group of the Design
tab of the Ribbon. Access inserts the new field above the field you
were on. To delete a field, select it and click the Delete Rows button.
|
5. | To save your work, click the Save tool on the QuickAccess toolbar. The Save As dialog box, shown in Figure 6,
appears. Enter a table name and click OK. A dialog box appears,
recommending that you establish a primary key. Every table should have
a primary key.
|
Field names can be up to 64 characters long. For
practical reasons, you should try to limit them to 10–15 characters,
which is enough to describe the field without making the name difficult
to type.
Access supplies default names for the tables that
you create (for example, Table1, Table2). I suggest that you supply a
more descriptive name. I generally follow the industry-wide naming
convention of prefixing all my table names with tbl.
|
Field names can include any combination of letters,
numbers, spaces, and other characters, excluding periods, exclamation
points, accents, and brackets. I recommend that you stick to letters.
Spaces in field names can be inconvenient when you’re building queries,
modules, and other database objects. You shouldn’t be concerned that
users will see the field names without the spaces. The Caption property of a field allows you to designate the text that Access displays for users.
A field name cannot begin with leading spaces. As
mentioned previously, field names shouldn’t contain any spaces, so the
rule to not begin a field name with spaces shouldn’t be a problem.
Field names also cannot include ASCII control characters (ASCII values
0–31).
You should try not to duplicate property names,
keywords, function names, or the names of other Access objects when
naming fields (for example, naming a field Date). Although the code
might work in some circumstances, you might get unpredictable results
in others.
To make a potential move to the
client/server platform as painless as possible, you should be aware
that not all field types are supported by every back-end database.
Furthermore, most back-end databases impose stricter limits than Access
does on the length of field names and the characters that are valid in
field names. To reduce the number of problems you’ll encounter if you
migrate tables to a back-end database server, you should consider these
issues when you’re naming the fields in Access tables.