Berkeley DB Reference Guide:
Simple Tutorial


Key/data pairs

Berkeley DB uses key/data pairs to identify elements in the database. That is, in the general case, whenever you call a Berkeley DB interface, you present a key to identify the key/data pair on which you intend to operate.

For example, you might store some key/data pairs as follows:


In each case, the first element of the pair is the key, and the second is the data. To store the first of these key/data pairs into the database, you would call the Berkeley DB interface to store items, with fruit as the key, and apple as the data. At some future time, you could then retrieve the data item associated with fruit, and the Berkeley DB retrieval interface would return apple to you. While there are many variations and some subtleties, all accesses to data in Berkeley DB come down to key/data pairs.

Both key and data items are stored in simple structures (called DBTs) that contain a reference to memory and a length, counted in bytes. (The name DBT is an acronym for database thang, chosen because nobody could think of a sensible name that wasn't already in use somewhere else.) Key and data items can be arbitrary binary data of practically any length, including 0 bytes. There is a single data item for each key item, by default, but databases can be configured to support multiple data items for each key item.


Copyright Sleepycat Software