Working with Fields
The heart of the database is the data within it, data that is stored in fields. This section provides some basics about working with fields.
Field Naming Conventions
The naming conventions for tables with regard to spaces, characters, capitalization, and so forth apply also to fields. There are some additional considerations when it comes to naming fields. Specifically, they have to do with the identification of field types and the naming of internally used fields.
Many developers use abbreviations for data types in field names. Often it's handy to know the data type of a given field when working with it without having to refer to the Manage Database dialog. Here we've used "t" for text, "n" for number, and "c" for calculation:
- ProductName_t
- Price_n
- TaxRate_n
- Tax_c
Some developers also note whether a field is indexed ("x" for indexed, "n" for unindexed):
- Location_Name_tx
- Location_Desc_tn
- Location_Size_nn
Some naming conventions also break out a division between data fields and what are commonly referred to as developer fields—those fields that you need only to make your FileMaker Pro solution work. If you ever went to import your database wholesale into another system, you would probably leave behind the developer fields. Here we have two abbreviations: "k" for key (or match field), and "z" (so that it sorts to the bottom of the list) for developer utility fields. We also use underscores to ensure that keys sort to the top of our field list, with the primary key coming first.
→ |
To understand how keys are used to identify records in tables and form relationships, see Chapter 5, "Relational Database Design," p. 163. |
- __kp_primary_AlbumID
- _kf_foreign_ArtistID
- AlbumName
- Date
- z_SelectedPortalRow
- z_UserColor_Preference
- z_UserGenre_Preference
Many developers use a minimal set of field-naming standards. It relies on leading lowercase characters to indicate the field type. If you choose to use that minimal set, here are the conventions used:
- g—Global
- c—Calculation
- s—Summary
- z—Internal use (This causes the field name when shown in an alphabetical list to be at the bottom.)
Descriptions of field types might or might not use this set of standards, which you can add to the end of the field name following an underscore:
- t—Text
- n—Number
- d—Date
- ts—Timestamp
- tm—Time
- c—Container
Putting these together, you could have field names such as these:
- creationDate_d
- gProcessingOffice_t
- gcNextInvoiceNumber_n
You can even go further by not bothering with field types where the field name already includes it. creationDate_d really adds no information to creationDate.
Whatever you do, be consistent. The point is not to create a set of naming conventions that overshadows the database but, rather, to create naming conventions that help you and future developers build and maintain the solution.
→ |
For more information on using databases on the Web, see "Designing for IWP Deployment," p. 701, as well as Chapter 26, "Custom Web Publishing with XML/XSLT," p. 715. |
Adding Field Comments
Notice also that you can add comments to your field definitions. We don't mean to be pedantic, but we want to drive home that establishing good programming habits will serve you well for the rest of your life as a developer: Use the field comments feature. Explain to yourself a year from now why a field exists, any dependencies or assumptions you made, and possibly how you intend to use it.
Creating New Fields
To create fields in FileMaker Pro, you need to enter some text in the Field Name area of the Manage Database dialog and click Create. One important aspect of databases to keep in mind is that it's important to establish a discrete field for each bit of information you want to store. If you create a field called Contact Information and cram an entire address and a set of phone numbers into it, technically it will work fine. But if it ever comes time to export that information, sort by area code, or run a report by city, you won't be able to cull the information you want from the field without suffering a good headache.
→ |
To database wonks, the Contact Information example would be a violation of first normal form, or more colloquially, "one fact, one field." For information on relational data modeling and defining fields, see "Relationship Types," p. 171. |
As shown previously in Figure 3.1, the Manage Database dialog lets you create, change, duplicate, and delete fields. As with the Tables tab, FileMaker Pro Advanced has additional buttons: Copy and Paste. If you select a field or fields, you can click Copy and paste the fields into the same or another table. Pasting them into the same table is the same as duplicating them.