Flat-file database: Difference between revisions
the "other" flat-file model: see talk page on: flat-file != relational database? |
No edit summary |
||
Line 20: | Line 20: | ||
==Flat files== |
==Flat files== |
||
A [[flat file]] |
A [[flat file]][[database record|records]], generally one record per line. [[Field (computer science)|Field]]s may simply have a [[fixed width]] with padding, or [[delimiter|delimited]] by [[whitespace (computer science)|whitespace]] or tabs or commas ([[Comma-separated values|CSV]]) or other characters. Extra formatting may be needed to avoid [[Delimiter#Delimiter_collision|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. |
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. |
Revision as of 08:40, 8 February 2007
A flat file database describes any of various means to encode a data model (most commonly a table) as a plain text file.
Flat files
A flat filerecords, 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.
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.
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.
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.
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.
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.
Flat-File relational database storage model
There is a difference between the concept of a single flat-file database as a flat database model as used above, and multiple flat-file tables as a relational database model. In order for flat-files to be part of a relational database the RDBMS must be able to recognize various foreign key relationships between multiple flat-file tables.
File1
file-offset id name team 0x00 8 Hank Reds 0x13 1 Amy Blues 0x27 3 Chuck Blues 0x3B 4 Dick Blues 0x4F 5 Ethel Reds 0x62 7 Gilly Blues 0x76 6 Fred Blues 0x8A 2 Bob Reds
The file-offset isn't actually part of the database, rather it is only there for clarification.
File2
team arena Blues le Grand Bleu Reds Super Smirnoff Stadium
In this setting flat-files simply act as a data store of a modern relational-database, all that is needed to be a modern database are separate files supplied by the RDBMS for storing indexes, constraints, triggers, foreign key relationships, fragmentation plans, replication plans, and other modern distributed relational database concepts.
Simple example name index on File1
0x00000013 0x0000008A 0x00000027 0x0000003B 0x0000004F 0x00000076 0x00000062 0x00000000