Subscribe to the wiseGEEK Feed

What is a Flat File?

Much of the information available today is contained in some type of database. Blogs use databases to store posts and user information, discussion sites use them to store information about members, and organizations use them to store useful data for their business — from financial records to customer information.

The majority of the databases used today are relational databases that use structured queries to retrieve information and present it to the user. This was not always the case, and flat file databases were created to store information in a non-structured way.

A flat file is a collection of data stored and accessed sequentially. A comma separated values (CSV) sheet in Microsoft Excel is a flat file. There are no application specific formats applied to the data contained within the file and only a comma denotes the end of one field in a record. Each record is written on a line in the file, allowing all data for a single record to be stored separately from other records.

A flat file does not incorporate relationships with other tables that rely on special instructions to be used. The common database used today is a relational database. The data model used for this kind of storage allows information in one table to be related to information in other tables using key fields which exist in each table.

For example, suppose a customer calls an organization to place an order. The customer information is entered and stored. Then the order information is entered and stored. In a flat file, this information would be stored with the information for the order itself to allow the record for the order and/or the customer to be retrieved. Keep in mind that flat file databases do not have to use a single flat file. Information about orders could be stored in one flat file, while information about customers is stored in a different flat file. These files are not related in any way, so the flat file database for customer information has no idea that any information exists about orders.

To make a flat file data model functional, all relevant information about a record needs to be stored in the same file. Flat file databases can quickly become very large and difficult to manage because of the simple way they are organized. Many of today’s more advanced data models use tables to organize groups of related data. This makes the data easier to locate and more flexible to work with.

The same customer example given above might look a bit different if a different data model were applied to the scenario. When the customer calls to place an order, his or her information is entered and stored in a customers table within the database. The information for his or her order is stored in two tables, order header and order details. Information like order number, order date, and customer id are stored in the order header table. The items ordered along with quantities and unit costs are stored in the order details table. The order details table also contains the order number, allowing this information to be related back to the order header information. In the order header table for this record, there is a reference to the customer id linking this order to the customer who ordered it.

Flat file databases do have many uses; however the functionality of this data model is not quite as efficient as a faster and structured relational approach.

Written by Derek Schauland