Database

4 CHAPTER 1. INTRODUCTION customer CustAcct account name street city number balance Figure 1.2: A sample E-R diagram. { Object-oriented model. { Binary model. { Semantic data model. { Infological model. { Functional data model. 2. At this point, we'll take a closer look at the entity-relationship (E-R) and object-oriented models. The E-R Model 1. The entity-relationship model is based on a perception of the world as consisting of a collection of basic objects (entities) and relationships among these objects. An entity is a distinguishable object that exists. Each entity has associated with it a set of attributes describing it. E.g. number and balance for an account entity. A relationship is an association among several entities. e.g. A cust acct relationship associates a customer with each account he or she has. The set of all entities or relationships of the same type is called the entity set or relationship set. Another essential element of the E-R diagram is the mapping cardinalities, which express the number of entities to which another entity can be associated via a relationship set. We'll see later how well this model works to describe real world situations. 2. The overall logical structure of a database can be expressed graphically by an E-R diagram: rectangles: represent entity sets. ellipses: represent attributes. diamonds: represent relationships among entity sets. lines: link attributes to entity sets and entity sets to relationships. See gure ?? for an example. The Object-Oriented Model 1. The object-oriented model is based on a collection of objects, like the E-R model. An object contains values stored in instance variables within the object. Unlike the record-oriented models, these values are themselves objects. 1.3. DATA MODELS 5 Thus objects contain objects to an arbitrarily deep level of nesting. An object also contains bodies of code that operate on the the object. These bodies of code are called methods. Objects that contain the same types of values and the same methods are grouped into classes. A class may be viewed as a type de nition for objects. Analogy: the programming language concept of an abstract data type. The only way in which one object can access the data of another object is by invoking the method of that other object. This is called sending a message to the object. Internal parts of the object, the instance variables and method code, are not visible externally. Result is two levels of data abstraction. For example, consider an object representing a bank account. The object contains instance variables number and balance. The object contains a method pay-interest which adds interest to the balance. Under most data models, changing the interest rate entails changing code in application programs. In the object-oriented model, this only entails a change within the pay-interest method. 2. Unlike entities in the E-R model, each object has its own unique identity, independent of the values it contains: Two objects containing the same values are distinct. Distinction is maintained in physical level by assigning distinct object identi ers. 1.3.2 Record-based Logical Models 1. Record-based logical models: Also describe data at the conceptual and view levels. Unlike object-oriented models, are used to { Specify overall logical structure of the database, and { Provide a higher-level description of the implementation. Named so because the database is structured in xed-format records of several types. Each record type de nes a xed number of elds, or attributes. Each eld is usually of a xed length (this simpli es the implementation). Record-based models do not include a mechanism for direct representation of code in the database. Separate languages associated with the model are used to express database queries and updates. The three most widely-accepted models are the relational, network, and hierarchical. This course will concentrate on the relational model. The network and hierarchical models are covered in appendices in the text. The Relational Model Data and relationships are represented by a collection of tables. Each table has a number of columns with unique names, e.g. customer, account. Figure ?? shows a sample relational database. 6 CHAPTER 1. INTRODUCTION name street city number Lowery Maple Queens 900 Shiver North Bronx 556 Shiver North Bronx 647 Hodges Sidehill Brooklyn 801 Hodges Sidehill Brooklyn 647 name balance 900 55 556 100000 647 105366 801 10533 Figure 1.3: A sample relational database. Lowery Maple Queens 900 55 Shiver North Bronx Hodges Sidehill Brooklyn 100000 647 105366 801 10533 556 Figure 1.4: A sample network database The Network Model Data are represented by collections of records. Relationships among data are represented by links. Organization is that of an arbitrary graph. Figure ?? shows a sample network database that is the equivalent of the relational database of Figure ??. The Hierarchical Model Similar to the network model.