Flat file database

From Wikipedia, the free encyclopedia

A simple diagram depicting conversion of a CSV-format flat file database into a relational database table. This is one of several typical uses for a flat file database.
Enlarge
A simple diagram depicting conversion of a CSV-format flat file database into a relational database table. This is one of several typical uses for a flat file database.

A flat file database describes any of various means to encode a data model (most commonly a table) as a plain text file.

Contents

[edit] Flat files

A flat file is a file containing records, generally one record per line. Fields may simply have a fixed width with padding, or delimited by whitespace or tabs or commas (CSV) or other characters. Extra formatting may be needed to avoid delimiter collision. There are no structural relationships. The data are "flat" as in a sheet of paper, in contrast to more complex models such as a relational database.

The classic example of a flat file database is a basic name-and-address list, where the database consists of a small, fixed number of fields: Name, Address, and Phone Number. Another example is a simple HTML table, consisting of rows and columns. This type of database is routinely encountered, although often not expressly recognized as a database.

[edit] Implementation

It is possible to write out by hand, on a sheet of paper, a list of names, addresses, and phone numbers; this is a flat file database. This can also be done with any typewriter or word processor. But many pieces of computer software are designed to implement flat file databases.

[edit] Historical implementations

The first uses of computing machines were implementations of simple databases. Herman Hollerith conceived the idea that any resident of the United States could be represented by a string of exactly 80 digits and letters -- name, age, and so forth, padded as needed with spaces to make everyone's name the same length, so the database fields would "line up" properly. He sold his concept, his machines, and the punched cards which both recorded and stored this data to the US Census Bureau; thus, the Census of 1890 was the first ever computerized database -- consisting, in essence, of thousands of boxes full of punched cards.

Throughout the years following World War II, primitive electronic computers were run by governments and corporations; these were very often used to implement flat file databases, the most typical of which were accounting functions, such as payroll. Very quickly, though, these wealthy customers demanded more from their extremely expensive machines, which led to early relational databases. Amusingly enough, these early applications continued to use Hollerith cards, slightly modified from the original design; Hollerith's enterprise grew into computer giant IBM, which dominated the market of the time. The rigidity of the fixed-length field, 80-column punch card driven database made the early computer a target of attack, the butt of jokes, an idol worshipped, and a mystery to the common man.

In the 1980s, configurable flat-file database computer applications were popular on DOS and the Macintosh. These programs were designed to make it easy for individuals to design and use their own databases, and were almost on par with word processors and spreadsheets in popularity. Examples of flat-file database products were early versions of FileMaker and the shareware PC-File. Some of these offered limited relational capabilities, allowing some data to be shared between files.

[edit] Contemporary implementations

Today, there are few programs designed to allow novices to create and use general-purpose flat file databases. This function is implemented in Microsoft Works (available only for some versions of Windows) and AppleWorks, sometimes named ClarisWorks (available for both Macintosh and Windows platforms). Over time, products like Borland's Paradox, and Microsoft's Access started offering some relational capabilities, as well as built-in programming languages. Database Management Systems (DBMS) like MySQL or Oracle generally require programmers to build applications.

Flat file databases are still used internally by many computer applications to store configuration data. Many applications allow users to store and retrieve their own information from flat files using a pre-defined set of fields. Examples are programs to manage collections of books or appointments. Some small "contact" (name-and-address) database implementations essentially use flat files.

XML is now a popular format for storing data in plain text files, but as XML allows very complex nested data structures to be represented and contains the definition of the data, it would be incorrect to describe this type of database as conforming to the flat-file model.

[edit] Terms

"Flat file database" may be defined very narrowly, or more broadly. The narrower interpretation is correct in database theory; the broader covers the term as generally used.

Strictly, a flat file database should consist of nothing but data and delimiters. More broadly, the term refers to any database which exists in a single file in the form of rows and columns, with no relationships or links between records and fields except the table structure.

Terms used to describe different aspects of a database and its tools differ from one implementation to the next, but the concepts remain the same. FileMaker uses the term "Find", while MySQL uses the term "Query"; but the concept is the same. FileMaker "files" are equivalent to MySQL "tables", and so forth. To avoid confusing the reader, one consistent set of terms is used throughout this article.

However, the basic terms "record" and "field" are used in nearly every database implementation.

[edit] Example database

Consider a simple example database, storing a person's name, a numeric ID, and the team they support. The data -- the information itself -- has simply been written out in table form:

id    name    team
1     Amy     Blues
2     Bob     Reds
3     Chuck   Blues
4     Dick    Blues
5     Ethel   Reds
6     Fred    Blues
7     Gilly   Blues
8     Hank    Reds

Note that the data in the first column is "all the same" -- that is, they are all id numbers (serial numbers). Likewise, the data in the second column is "all the same" -- names. We have decided Pico users will gang up into teams, and some belong to the Reds and some to the Blues. All these team designations are found in the third column only. These columns are called "fields".

Also note that all the information in, say, the third line from the top "belongs to" one person: Bob. Bob's id is "2"; his name is "Bob" (no surprise!); and his team is the "Reds". Each line is called a "record". (Sometimes, although this is not strictly correct, the word "field" refers to just one datum within the file -- the intersection of a field and a record.)

The first line is not a record at all, but a row of "field labels" -- names that identify the contents of the fields which they head. Some databases omit this, in which case the question is left open: "What is in these fields?" The answer must be supplied elsewhere.

In this implementation, fields can be detected by the fact that they all "line up": each datum uses up the same number of characters as all other data in the same column; extra spaces are added to make them all the same length. This is a very primitive and brittle implementation, dating back to the days of punch cards.

Today, the same effect is achieved by delimiting fields with a tab character; records are delimited by a newline. This is "tab-separated" format. Other ways to implement the same database are:

"1","Amy","Blues"
"2","Bob","Reds"
"3","Chuck","Blues"
"4","Dick","Blues"
"5","Ethel","Reds"
"6","Fred","Blues"
"7","Gilly","Blues"
"8","Hank","Reds"

-- which is "comma-separated" (CSV) format. We could also write:

1-Amy-Blues/2-Bob-Reds/3-Chuck-Blues/4-Dick-Blues/5-Ethel-Reds/6-Fred-Blues/7-Gilly-Blues/8-Hank-Reds/

All are equivalent databases.

There is not much we can do with such a simple database. We can look at it, and, depending on the storage format, do a textual search for specific fields; if we can edit it at all, we can add new records to it; we can edit the contents of any field. We can import the entire database into another tool. Sometimes this is enough, but only for the most basic needs. Beyond those, we turn to a tool designed for the task, a database management system.

An advantage of a database tool is that it is specifically designed for database management. We can add, delete, or edit records or individual units of data. We can add additional records to the file explicitly, via an 'insert' or equivalent command; we can define certain processes to take place when this happens. We can add additional fields, too, extending the structure. We can choose to control what kind of data may be stored in a given field. For instance, id is defined to hold only a serial number, which is assigned automatically when a new record is created.

This is about the limit of what a simple flat file can do. For more advanced applications, relational databases are usually used.

[edit] See also

Topics in database management systems (DBMS) ( view talk edit )

Concepts
Database | Database model | Relational database | Relational model | Relational algebra | Primary key - Foreign key - Surrogate key - Superkey
Database normalization | Referential integrity | Relational DBMS | Distributed DBMS | ACID

Objects
Trigger | View | Table | Cursor | Log | Transaction | Index | Stored procedure | Partition

Topics in SQL
Select | Insert | Update | Merge | Delete | Join | Union | Create | Drop
Comparison of syntax

Implementations of database management systems

Types of implementations
Relational | Flat file | Deductive | Dimensional | Hierarchical | Object oriented | Temporal

Products
Apache Derby | Caché | db4o | dBASE | Firebird | Helix database | DB2 | Informix | Ingres | InterBase | Microsoft SQL Server | MySQL | OpenLink Virtuoso | Oracle | PostgreSQL | SQLite | Sybase IQ | Sybase | Teradata | Visual FoxPro | Comparison - relational | Comparison - object-relational

Components
Query language | Query optimizer | Query plan | ODBC | JDBC
Lists
List of object-oriented database management systems
List of relational database management systems

In other languages