Which is the best one to use for a particular job will depend on factors such as the type and the amount of data to be processed; not to mention how frequently it will be used.
Flat-File
- Ideal for small amounts of data that needs to be human readable or edited by hand.
- Used for storing the more complex data types, are also likely to render the file unreadable and un-editable to anyone looking after the database.
- Split up using a common delimiter.
- If the data is simple enough, this could be a comma, but more complex strings are usually split up using tabs, new lines or a combination of characters.
- One of the main problems with using flat files for even a semi-active database is the fact that it is very prone to corruption.
- There is no inherent locking mechanism that detects when a file is being used or modified, and so this has to be done on the script level.
- Even if care is taken to lock and unlock the file on each access, a busy script can cause a "race condition" and it is possible for a file to be wiped clean by two or more processes that are fighting for the lock; the timing of your file locks will become more and more important as a site gets busy.
- Store data in more than one type of record.
- Described as a "parent-child, one-to-many" relationship. One field is key to all records, but data in one record does not have to be repeated in another.
- This system allows records with similar attributes to be associated together. The records are linked to each other by a key field in a hierarchy of files.
- Each record, except for the master record, has a higher level record file linked by a key field "pointer". In other words, one record may lead to another and so on in a relatively descending pattern.
Relational Files
- Connect different files or tables (relations) without using internal pointers or keys.
- Instead a common link of data is used to join or associate records. The link is not hierchical. A "matrices of tables" is used to store the information.
- The tables have a common link they may be combined by the user to form new inquires and data output.
- This is the most flexible system and is particularly suited to SQL (structured query language).
- Have functions "built in" that help them to retrieve, sort and edit the data in many different ways.
- These functions save script designers from having to worry about filtering out the results that they get, and so can go quite some way to speeding up the development and production of web applications.
- A description of how drives, directories, and files are displayed on an operating system that allows for a large quantity of files and directories to be listed in a small area.
Flat, Hierarchical, and Relational Files Compared
Structure | Advantages | Disadvantages |
---|---|---|
Flat Files |
|
|
Hierarchical Files |
|
|
Relational Files |
|
|