data models lect 2

50
Data Models

Upload: rishi-raj-b

Post on 01-May-2017

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Data Models Lect 2

Data Models

Page 2: Data Models Lect 2

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.

Page 3: Data Models Lect 2

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.

Page 4: Data Models Lect 2

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.

Page 5: Data Models Lect 2

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

Page 6: Data Models Lect 2

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.

Page 7: Data Models Lect 2

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.

Page 8: Data Models Lect 2

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.

Page 9: Data Models Lect 2
Page 10: Data Models Lect 2

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.

Page 11: Data Models Lect 2

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.

Page 12: Data Models Lect 2

Relationship Sets• A relationship is an association among several

entities.

Page 13: Data Models Lect 2

Constraints

• Mapping Cardinalities

• Participation Constraints

Page 14: Data Models Lect 2

Mapping Cardinalities

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

Page 15: Data Models Lect 2

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.

Page 16: Data Models Lect 2

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.

Page 17: Data Models Lect 2

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.

Page 18: Data Models Lect 2

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.

Page 19: Data Models Lect 2

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.

Page 20: Data Models Lect 2

Entity-Relationship Diagram

Page 21: Data Models Lect 2
Page 22: Data Models Lect 2
Page 23: Data Models Lect 2
Page 24: Data Models Lect 2
Page 25: Data Models Lect 2
Page 26: Data Models Lect 2
Page 27: Data Models Lect 2
Page 28: Data Models Lect 2
Page 29: Data Models Lect 2
Page 30: Data Models Lect 2
Page 31: Data Models Lect 2

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.

Page 32: Data Models Lect 2
Page 33: Data Models Lect 2

Extended E-R Features

• specialization,

• generalization,

• higher- and lower-level entity sets,

• attribute inheritance,• attribute inheritance,

• and

• aggregation.

Page 34: Data Models Lect 2

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.

Page 35: Data Models Lect 2

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.

Page 36: Data Models Lect 2
Page 37: Data Models Lect 2

Attribute Inheritance

Page 38: Data Models Lect 2

Aggregation

Page 39: Data Models Lect 2
Page 40: Data Models Lect 2
Page 41: Data Models Lect 2

Relational Model

Page 42: Data Models Lect 2

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.

Page 43: Data Models Lect 2

Tabular Representation of Strong Entity Sets

Page 44: Data Models Lect 2

Tabular Representation of Weak Entity Sets

Page 45: Data Models Lect 2
Page 46: Data Models Lect 2
Page 47: Data Models Lect 2

Tabular Representation of Relationship Sets

Page 48: Data Models Lect 2

Redundancy of Tables

Page 49: Data Models Lect 2

The Unified Modeling Language UML

Page 50: Data Models Lect 2