📄 ug_ch2.htm
字号:
record type, as it is redundant. The <b><i>db.*</i></b> DDL wouldbe modified as follows:</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 paid_to[48]; float amount; } set transactions { order last; owner budget; member check; }}</font></pre><p><font size="2">Any given record type can be the owner of anynumber of different sets and also a member of any number ofdifferent sets. Thus, network structures like that shown in Figure2-3 are valid.</font></p><p align="center"> </p><p align="center"><img alt="Example of a Network Structure" border="0" height="197" src="dbstar_2-3.gif" width="276"></p><p align="center">Fig. 2-3. Example of a Network Structure</p><p>Notice that records of type E may own other records of type E.Record type C is a member of two sets (A and B) and itself owns twosets (D and E). Records also can own other records through multiplesets, as in the case of B owning E. All these are legitimateconstructs in <b><i>db.*</i></b>.</p><h2><a name="OtherModels" id="OtherModels"></a>2.4 Other DatabaseModels</h2><p><font size="2">Two other major database models are thehierarchical and relational models. These are describedbelow.</font></p><h3><a name="Hierarchical" id="Hierarchical"></a>2.4.1 TheHierarchical Database Model</h3><p><font size="2">In the hierarchical database model (a subset ofthe network model) a record type is allowed to be a member of onlyone set. Record types can still, however, own more than one set.The owner is called the parent and the member is called thechild.</font></p><p>As in the network model, sets are implemented through linkedlists. Figure 2-4 shows an example of a hierarchical schemastructure.</p><p align="center"> </p><p align="center"><img alt="Example of a Hierarchical Structure"border="0" height="171" src="dbstar_2-4.gif" width="246"></p><p align="center">Fig. 2-4. Example of a Hierarchical Structure</p><h3><a name="Relational" id="Relational"></a>2.4.2 The RelationalDatabase Model</h3><p><font size="2">The relational database model views the databaseas a set of two-dimensional tables (or relations). The columns(also called attributes) of a table correspond to data fields, andthe rows of the table correspond to record occurrences. Thistabular view of a database is particularly easy to manipulate withstandard relational database operations, which are based onmathematical set theory.</font></p><p>In the relational model, relationships between tables areusually established through common data fields. Recall from theinitial checking account example that the relationship between the<b>budget</b> and <b>check</b> records was formed by including inthe <b>check</b> record a <b>budget code</b> field to identify thebudget category.</p><p>The principal distinction between the relational and networkmodels is that in the relational model, relationships are formedthrough common data fields between the related record types, whilein the network model those relationships are defined directly.</p><p>Note that it is possible to transform databases from relationalto network and from network to relational.</p><h2><a name="Combined" id="Combined"></a>2.5 Advantages of theCombined Model</h2><p><font size="2">Relational model database systems have beenextremely popular, primarily because the simplicity of theunderlying data model makes them easy to use. With the networkmodel, the primary benefits are better performance, reduced storagerequirements, and greater assurance of data integrity. Consider thediagram in Figure 2-5.</font></p><p align="center"> </p><p align="center"><strong><img alt="Relational DBMS Overhead"border="0" height="108" src="dbstar_2-5.gif" width="251"></strong></p><p align="center"><strong>Fig. 2-5. Relational DBMSOverhead</strong></p><p align="left"><font size="2">This diagram shows two tables thatare related through a common data field, C. Note that C must bedefined in both tables and that an index must exist in order toaccess the related table 2 occurrences. Contrast this with thecorresponding network model diagram in Figure 2-6.</font></p><p align="left"> </p><p align="center"><strong><img alt="dbstar_2-6.gif - 1962 Bytes"border="0" height="149" src="dbstar_2-6.gif" width="252"></strong></p><p align="center"><strong>Fig. 2-6. Network DBMSOverhead</strong></p><p><font size="2">The network model eliminates data redundancy byrelating the two record types directly, without requiring theduplicate field and index file. Moreover, the related record isaccessed directly with one database read operation, where therelational model forces you to read first an index and then therelated record.</font></p><p><font size="2">For those situations where an index is moreefficient, db.* provides you with that option. With db.*, networkaccess and indexed access are independent methods, so you cancombine them to suit the needs of your particular application.Combining these technologies gives you maximum database designflexibility.</font></p><h2><a name="Access" id="Access"></a>2.6 Access Methods in<i>db.*</i></h2><p><font size="2">We have already discussed two access methodsavailable in <b><i>db.*</i></b>: indexes and sets. A third methodis called sequential access. All three methods can be used togetherfor navigating and searching in a database. Each has its own waysof establishing and changing a position in the database. Themethods are nearly orthogonal, meaning that the use of one will notdisrupt the use of the others. The one value they share is thecurrent record, which points to the record in the database that hasbeen found most recently. The current record is the default objectfor many of the <b><i>db.*</i></b></font> <font size="2">functions.All three access methods set the current record.</font></p><p><font size="2">The indexed method allows you to find a recordoccurrence by supplying a key. The key can be an exact match, inwhich case you are positioned directly on a record, or a nearmatch, which will position you just before the record containing akey value higher in the collating sequence. You can also positionyourself to the first or last keys of a given key type, regardlessof their values. Once at a position, you can move to the previousor next key in the collating sequence. The keys are maintained andnavigated in the order maintained in the index, regardless of thephysical order of the records to which they point.</font></p><p><font size="2">The set method allows you to move through setconnections in various directions. You can move from the owner of aset instance to the first or last member of the set. From a setmember, you can move to the next or previous member record, or tothe owner record. During the navigation of sets, positions areestablished on a per-set basis: the current owner and currentmember is indicated for each set type that has been used. Ifdefined, a system record can be used as the entry point into adatabase. When the database is opened, the system record is thecurrent owner of all sets owned by the system record.</font></p><p><font size="2">The sequential method allows you to find thefirst, last, next, or previous physical instance of a given recordtype. <b><i>db.*</i></b> does not allow the programmer to insertrecords at specific physical positions in a file. Their insertionis normally at the end of a file, but this is not guaranteed if youare using the delete chain (see the entry on Option Settings insection 5.2.4, "Option Settings," of Chapter 5). The sequentialmethod is useful when you are searching all records of a giventype, but do not care about the order.</font></p><h2><a name="Elements" id="Elements"></a>2.7 Elements of a<i>db.*</i> Database</h2><p><font size="2">A <b><i>db.*</i></b> database consistsof:</font></p><ul><li><font size="2">A dictionary, which stores informationdescribing the content and organization of the database</font></li><li><font size="2">Data files, which contain occurrences of one ormore record types</font></li><li><font size="2">Key files, which contain an index for one ormore key fields</font></li></ul><p><font size="2">Records contain data fields, key fields, and setlinkages (which are transparent to the user). They can be accessedthrough set navigation (that is, traversing through the linkedlists associated with specific sets), through key fields (using afast look-up of the index), sequentially, or through a combinationof all three methods.</font></p><p><font size="2">Details relating to these elements are fullydiscussed in Chapters 4 and 5, "Database Design," and "DatabaseManipulation" respectively.</font></p><p><a href="UG_Ch3.htm">Next Page</a></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -