[ Database tutorial | Text databases ]

Field order

While this is not relevant in "real" databases, when you are using text file databases, it becomes rather important to put your fields into a record in an order that makes sense. The main two reasons for this are that it makes the sorting of records easier, and it makes it easier to locate an individual record when you want it.

While this will be addressed in more detail in the section on sorting, it makes a lot of sense to put a field in the first slot in a record if you will frequently be sorting on that field. For example, if you frequently sort records on the field LastName, and that field occurs first in your records, you can sort the records by simply ...:

@records = sort(@records);
Whereas, if it is buried somewhere in the middle of the record, you will have to take a somewhat more convoluted approach.

For reasons that will be most obvious in the sections about editing and deleting records, it is useful to put the ID number at the one end of the record or the other. Since the beginning is already taken, it makes sense to put it at the end.

If you choose some other ordering for your fields, it is no cause for alarm. There are ways around this. This is really a matter of efficiency - efficiency in writing the code, and efficiency in running the code. It is a lot faster to do both if you take a little time to plan details like this one. Field order is often overlooked on your first textfile database application, but after doing a few, you begin to realize that you could save yourself a lot of time with these simple guidelines.

[ Database tutorial | Text databases ]