data models lect 2

Post on 01-May-2017

228 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Data Models

Data Models

• A data model is a collection of conceptual tools for describing data, data relationships, data semantics, and consistency constraints. In this part, we study two data models—the In this part, we study two data models—the entity– relationship model and the relational model.

ER and Relational Model• The entity– relationship (E-R) model is a high-level data

model. It is based on a perception of a real world thatconsists of a collection of basic objects, called entities,and of relationships among these objects.

• The relational model is a lower-level model. It uses acollection of tables to represent both data and thecollection of tables to represent both data and therelationships among those data. Its conceptual simplicityhas led to its widespread adoption; today a vast majorityof database products are based on the relational model.

• Designers often formulate database schema design byfirst modeling data at a high level, using the E-Rmodel,and then translating it into the the relational model.

Entity-Relationship Model

• The entity-relationship(E-R) data modelperceives the real world as consisting of basicobjects, called entities, and relationshipsamong these objects. It was developed toamong these objects. It was developed tofacilitate database design by allowingspecification of an enterprise schema, whichrepresents the overall logical structure of adatabase.

Entity Sets

• An entity is a “thing”or“object”in the realworld that is distinguishable from all otherobjects. For example, each person in anenterprise is an entity. An entity has a set ofenterprise is an entity. An entity has a set ofproperties, and the values for some set ofproperties may uniquely identify an entity

Attributes

• An entity is represented by a set of attributes.Attributes are descriptive propertiespossessed by each member of an entity set.

• Each entity has a value for each of its• Each entity has a value for each of itsattributes.

• For each attribute, there is a set of permittedvalues, called thedomain,or value set, of thatattribute.

Simple and composite attributes

• The attributes have been simple; that is, theyare not divided into subparts. Compositeattributes, on the other hand, can be dividedinto subparts (that is, other attributes). Forinto subparts (that is, other attributes). Forexample, an attribute name could bestructured as a composite attribute consistingof first-name, middle-initial, and last-name.

Single-valued and multi-valued attributes.

• The loan-number attribute for a specific loan entity refers to only one loan number. Such attributes are said to be single valued. There may be instances where an attribute has a set of values for a specific entity.values for a specific entity.

• Consider an employee entity set with theattribute phone-number. An employee may havezero, one, or several phone numbers, anddifferent employees may have different numbersof phones. This type of attribute is said to bemulti-valued.

Derived attribute.

• The value for this type of attribute can be derivedfrom the values of other related attributes orentities.

• Suppose that the customer entity set has anattribute age, which indicates the customer’s age.attribute age, which indicates the customer’s age.If the customer entity set also has an attributedate-of-birth, we can calculate agefrom date-of-birth and the current date. Thus, ageis a derivedattribute. In this case,date-of-birth may bereferred to as a base attribute, or astoredattribute.

Null Value

• An attribute takes a null value when an entity does not have a value for it. The null value may indicate“not applicable”—that is, that the value does not exist for the entity.value does not exist for the entity.

Relationship Sets• A relationship is an association among several

entities.

Constraints

• Mapping Cardinalities

• Participation Constraints

Mapping Cardinalities

• Mapping cardinalities, or cardinality ratios,express the number of entities to whichanother entity can be associated via arelationship set.

Participation Constraints

• The participation of an entity set E in arelationship set R is said to be total if everyentity in E participates in at least onerelationship in R.relationship in R.

• If only some entities in E participate inrelationships in R, the participation of entityset E in relationship R is said to be partial.

Keys• A key allows us to identify a set of attributes

that suffice to distinguish entities from eachother. Keys also help uniquely identifyrelationships, and thus distinguishrelationships from each other.relationships from each other.

• Therefore, the values of the attribute values ofan entity must be such that they can uniquelyidentify the entity. In other words, no twoentities in an entity set are allowed to haveexactly the same value for all attributes.

Super key• A super key is a set of one or more attributes

that, taken collectively, allow us to identifyuniquely an entity in the entity set.

• For example, the customer-id attribute of theentity set customer is sufficient to distinguish onecustomer entity from another. Thus, customer-idis a superkey.is a superkey.

• Similarly, the combination of customer-name andcustomer-id is a super key for the entity setcustomer.

• The customer-name attribute of customer is nota superkey, because several people might havethe same name.

candidate keys• The concept of a super key is not sufficient for

our purposes, since, as we saw, a super key maycontain extraneous attributes. If K is a super key,then so is any superset Of K. We are ofteninterested in super keys for which no propersubset is a super key. Such minimal super keys arecalled candidate keys.called candidate keys.

• We shall use the term primary key to denote acandidate key that is chosen by the databasedesigner as the principal means of identifyingentities within an entity set.

primary key

• The primary key should be chosen such thatits attributes are never, or very rarely,changed. For instance, the address field of aperson should not be part of the primary key,person should not be part of the primary key,since it is likely to change.

Entity-Relationship Diagram

Weak Entity Sets

• An entity set may not have sufficientattributes to form a primary key. Such anentity set is termed a weak entity set. Anentity set that has a primary key is termed aentity set that has a primary key is termed astrong entity set.

Extended E-R Features

• specialization,

• generalization,

• higher- and lower-level entity sets,

• attribute inheritance,• attribute inheritance,

• and

• aggregation.

Specialization

• The process of designating sub groupingswithin an entity set is called specialization.The specialization of person allows us todistinguish among persons according todistinguish among persons according towhether they are employees or customers.

Generalization

• This commonality can be expressed bygeneralization, which is a containmentrelationship that exists between a higher-levelentity set and one or more lower-level entitysets.

• In our example, person is the higher-level entity• In our example, person is the higher-level entityset and customer and employee are lower-levelentity sets.Higher- and lower-level entity sets alsomay be designated by the terms super class andsubclass, respectively.

• The person entity set is the superclass of thecustomer and employee subclasses.

Attribute Inheritance

Aggregation

Relational Model

Reduction of an E-R Schema to Tables

• We can represent a database that conforms toan E-R database schema by a collection oftables. For each entity set and for eachrelationship set in the database, there is arelationship set in the database, there is aunique table to which we assign the name ofthe corresponding entity set or relationshipset. Each table has multiple columns, each ofwhich has a unique name.

Tabular Representation of Strong Entity Sets

Tabular Representation of Weak Entity Sets

Tabular Representation of Relationship Sets

Redundancy of Tables

The Unified Modeling Language UML

top related