⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ug_ch2.htm

📁 db.* (pronounced dee-be star) is an advanced, high performance, small footprint embedded database fo
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"><meta http-equiv="content-type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 97"><title>db.* User's Guide Chapter 2</title></head><body><h1><a name="Concepts" id="Concepts"></a>Chapter 2<br>Database Concepts</h1><h2><a name="Introduction" id="Introduction"></a>2.1Introduction</h2><p><font size="2">This chapter presents the basic database conceptsof the <b><i>db.*</i></b> system. The database terms used in thismanual are defined in section 2.2. The network database model,which forms the basis of the <b><i>db.*</i></b></font> <font size="2">system, is described in section 2.3. Section 2.4, "OtherDatabase Models," describes the hierarchical and relationaldatabase models. Section 2.5 describes the advantages of thenetwork model over the relational database model. Specific elementsof a <b><i>db.*</i></b></font> <font size="2">database aredescribed in the final section.</font></p><p>To use <b><i>db.*</i></b> productively, you need to understand<b><i>db.*</i></b> database concepts. This chapter intends toprovide sufficient information for a database novice to use<b><i>db.*</i></b> effectively. As part of our efforts tofamiliarize you with database concepts, we have provided a Glossaryof database terms at the end of this manual.</p><h2><a name="Definitions" id="Definitions"></a>2.2 Definitions</h2><p><font size="2">The basic unit of information in a database is afield. A field (or data field) is an item of data with attributessuch as name, type (for example, a character or an integer), andlength. Examples of fields are employee name, date of birth, socialsecurity number, inventory item code, and serial number. Otherdatabase systems or books may use other terms (such as attribute,entity, or column) for field.</font></p><p>A record is a named collection of related fields, which arestored and accessed as a unit. Other database systems or books mayuse other terms (such as table or file) for record. For example, arecord named <b>check</b> in a checking account database may havethe following fields:</p><div style="margin-left: 4em"><p><b>date<br>check number<br>paid to<br>amount</b></p></div><p>Each occurrence (or instance) of a <b>check</b> record in thedatabase contains a value for each of these fields. The definitionof a record (made up by its fields) is called the record type andis similar to C structures.</p><p>All occurrences of a particular record type are stored in anoperating system file. Files are the primary physical storage unitsof database organization. A database, therefore, is a collection ofrelated files.</p><p>A key is a field through which rapid or sorted access to arecord is possible. In the <b>check</b> record, you might define<b>check number</b> as a key field, to allow quick retrieval of a<b>check</b> record occurrence through specification of a checknumber.</p><p>An index is a file containing only keys. It is synonymouslyreferred to as a key file. The index to this manual demonstratesthe features of a key file: the individual subject entries in theindex are the "keys," while the page where the subject is discussedis analogous to the associated "records." You can find the pagethat discusses a desired subject much more quickly by using theindex than by reading through each page. And, because the keys aresorted in the index, you can quickly find a specific key. Key filesare similar, except the computer does the sorting and look-ups foryou. To maintain its key files, <b><i>db.*</i></b> uses the B-treemethod, one of the most efficient techniques for implementing anindex.</p><p>In a key scan operation, the keys in an index are read in theorder they appear. Key scans are used to produce sorted listings ofrecords and for fast search operations requiring inspection of alarge number of record occurrences (for example, retrieving allchecks entered between two dates).</p><p>Data relationships often exist between record types. Forexample, the checking account database may include budgetcategories. A second record type named <b>budget</b> could bedefined with the following data fields:</p><div style="margin-left: 4em"><p><b>budget code (a key field)<br>category description<br>monthly allocation<br>balance</b></p></div><p>To associate a particular budget category with each <b>check</b>record, we add a <b>budget code</b> field to the <b>check</b>record type, forming a relationship between the <b>budget</b>record and the <b>check</b> record. Whenever a check is entered,the related <b>budget</b> record is located via the budget code,and the balance for that budget is updated by the amount specifiedin the <b>check</b> record.</p><p>The schema is the conceptual definition of the content andorganization of a database. A schema will include the definitionsof all record types, with their fields and keys. The form of theschema used by the DBMS is called the dictionary. In<b><i>db.*</i></b> (and most other DBMSs) a Database DefinitionLanguage, or DDL, specifies the schema. A <b><i>db.*</i></b> DDLspecification for the checking account database is shown below. Thespecifics of the actual DDL statements are explained in Chapter 4,"Database Design."</p><pre><font color="#0000FF">database ckngacct {   data file "chkng.dat" contains budget, check;   key  file "chkng.key" contains code, check_no;   record budget {      key char code[6];      char cat_desc[48];      float allocation;          float balance;   }   record check {      key int check_no;      int check_date;      char bud_code[6];      char paid_to[48];   float amount;   }}</font></pre><p><font size="2">A data model (or database model) is a conceptualrepresentation of inter-record relationships. The relationaldatabase model establishes and maintains inter-record relationshipsthrough common data fields. For example, in the checking accountexample a common data field, <b>budget code</b>, establishes therelationship between the <b>budget</b> record and the <b>check</b>record.</font></p><p>Other database models, in particular the network database model,establish inter-record relationships directly, through physicallinks between the related records, rather than through common datafields. These models are discussed in the following sections. Since<b><i>db.*</i></b> supports both the relational and the networkdatabase models, you can combine the features of these models tomeet the needs of your particular application.</p><h2><a name="NetworkModel" id="NetworkModel"></a>2.3 The NetworkDatabase Model</h2><p><font size="2">In the network database model, the relationshipsbetween record types are explicitly defined and directly maintainedthrough sets. A set defines a one-to-many relationship between tworecord types. Examples of sets are:</font></p><div style="margin-left: 4em"><p>one baseball league has many teams<br>one baseball team has many players</p></div><p>Sets are implemented with linked lists of pointers to the recordlocations of the set <a name="member" id="member">member</a><a name="owner" id="owner">s and owners. Theresult is a network of interconnected records.</a></p><p>Figure 2-1 illustrates the set relationships for the baseballexample. The boxes represent instances of the <b>league</b>,<b>team</b>, and <b>player</b> record types. The arrows representthe links that connect the related records.</p><p align="center"><b><img alt="Example of Set Relationships"border="0" height="342" src="dbstar_2-1.gif" width="403"></b></p><p align="center">Fig. 2-1. Example of Set Relationships</p><p>Schema diagrams are used to illustrate graphically theinter-record relationships of the database design. Figure 2-2 showsthe schema diagram for the baseball example. In this diagram (andin all other schema diagrams in this manual), the boxes representrecord types and the arrows represent set types. The<b>league_team</b> set forms a one-to-many relationship between the<b>league</b> record type (called the owner of set<b>league_team</b>) and the <b>team</b> record type (called themember of set <b>league_team</b>). The <b>team_player</b> set formsa one-to-many relationship between the <b>team</b> record type andthe <b>player</b> record type.</p><p align="center">&nbsp;</p><p align="center"><img alt="Example of a Schema Diagram" border="0"height="269" src="dbstar_2-2.gif" width="331"></p><p align="center">Fig. 2-2. Example of a Schema Diagram</p><p>In the checking account example discussed earlier, therelationship between the <b>budget</b> and <b>check</b> recordtypes could be specified using a set called <b>transactions</b>,defining a one-to-many relationship between a <b>budget</b> record(owner) and the <b>check</b> records (members) written against aparticular budget category. In this case, the <b>bud_code</b> fieldin the <b>check</b> record would not be defined in the <b>check</b>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -