Docsity

database chapter one, Essays (university) of Computer Science

Toggle sidebar
bg1
FDB 2009
Chapter 3
Data Modelling using Entity Relationship
Basic Data Models
A specific DBMS has its own specific Data Definition Language, but this type of
language is too low level to describe the data requirements of an organization in a way that is
readily understandable by a variety of users. We need a higher-level language. Such a higher-
level is called data-model.
Data Model: a set of concepts to describe the structure of a database, and certain
constraints that the database should obey.
A data model is a description of the way that data is stored in a database. Data model helps
to understand the relationship between entities and to create the most effective structure to
hold data.
Data Model is a collection of tools or concepts for describing:
Data
Data relationships
Data semantics
Data constraints
The main purpose of Data Model is to represent the data in an understandable way.
Categories of data models include:
Object-based
Record-based
Physical
Record-based Data Models Consist of a number of fixed format records. Each record type
defines a fixed number of fields; each field is typically of a fixed length.
Hierarchical Data Model
Network Data Model
Relational Data Model
Prepared by: Haimanot.T 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download database chapter one and more Essays (university) Computer Science in PDF only on Docsity!

Chapter 3

Data Modelling using Entity Relationship

Basic Data Models

A specific DBMS has its own specific Data Definition Language, but this type of language is too low level to describe the data requirements of an organization in a way that is readily understandable by a variety of users. We need a higher-level language. Such a higher- level is called data-model.  Data Model : a set of concepts to describe the structure of a database, and certain constraints that the database should obey.  A data model is a description of the way that data is stored in a database. Data model helps to understand the relationship between entities and to create the most effective structure to hold data.  Data Model is a collection of tools or concepts for describing:  Data  Data relationships   Data semanticsData constraints

 The main purpose of Data Model is to represent the data in an understandable way. Categories of data models include:  Object-based  Record-based  Physical Record-based Data Models defines a fixed number of fields; each field is typically of a fixed length. Consist of a number of fixed format records. Each record type

 Hierarchical Data Model

 Network Data Model

 Relational Data Model

a) Hierarchical Model

 The simplest data model  Record type is referred to as node or segment  The top node is the root node  Nodes are arranged in a hierarchical structure as sort of upside-down tree  A parent node can have more than one child node  A child node can only have one parent node  The relationship between parent and child is one-to-many  Relation is established by creating physical link between stored records (each is stored with a predefined access path to other records)  To add new record type or relationship, the database must be redefined and then stored in a new form.

ADVANTAGES of Network Data Model:  Network Model is able to model complex relationships and represents semantics of add/delete on the relationships.  Can handle most situations for modeling using record types and relationship types.  (^) NEXTLanguage is navigational; uses constructs like FIND, FIND member, FIND owner, FIND within set, GET etc. Programmers can do optimal navigation through the database. DISADVANTAGES of Network Data Model:  Navigational and procedural nature of processing   Database contains a complex array of pointers that thread through a set of records.Little scope for automated "query optimization”

c) Relational Data Model

 Developed by Dr. Edgar Frank Codd in 1970 (famous paper, 'A Relational Model for Large Shared Data Banks')  Terminologies originates from the branch of mathematics called set theory and relation   Can define more flexible and complex relationshipViewed as a collection of tables called “Relations” equivalent to collection of record types  Relation : Two dimensional table  Stores information or data in the form of tables  rows and columns  A row of the table is called tuple equivalent to record   AData value is the value of the Attribute column of a table is called attribute equivalent to fields  Records are related by the data stored jointly in the fields of records in two tables or files. The related tables contain information that creates the relation  The tables seem to be independent but are related somehow   No physical consideration of the storage is required by the userMany tables are merged together to come up with a new virtual view of the relationship

Alternative terminologies o Relation=Table = File o Tuple = Row = Record o Attribute = Column = Field  The rows represent records (collections of information about separate items)   The columns represent fields (particular attributes of a record)Conducts searches by using data in specified columns of one table to find additional data in another table  In conducting searches, a relational database matches information from a field in one table with information in a corresponding field of another table to produce a third table that combines requested data from both tables

A relation is a collection of tuples , each of which contains values for a fixed number of attributesExistence Dependency more entities. : the dependence of an entity on the existence of one or

 Weak entity : an entity that cannot exist without the entity with which it has

a relationship – it is indicated by a double rectangle.

e.g

2. The ATTRIBUTES - the items of information which characterize and describe these entities. Attributes are pieces of information ABOUT entities. The analysis must of course identify those which are actually relevant to the proposed application. Attributes will give rise to recorded items of data in the database. At this level we need to know such things as:  Attribute name (be explanatory words or phrases)  The domain from which attribute values are taken (A DOMAIN is a set of values from which attribute values may be taken.) Each attribute has values taken from a domain. For example, the domain of Name is string and that for salary is real whether the attribute is part of the entity identifier (attributes which just describe an entity and those which help to identify it uniquely).  Whether it is values over time) permanent or time-varying (which attributes may change their  Whether it is required or optional for the entity (whose values will sometimes be unknown or irrelevant)

Types of Attributes

1) Simple (atomic) Vs Composite attributesSimple : contains a single value (not divided into sub parts) E.g. Age, gender  Composite : Divided into sub parts (composed of other attributes) E.g. Name, address 2) Single-valued Vs multi-valued attributes

Single-valued: have only single value(the value may change but has only one value at one time) E.g. Name, Sex, Id. No. color_of_eyes.  Multi-Valued: E.g. Address, dependent-name Person may have several college degrees. have more than one value

3) Stored vs. Derived AttributeStored: not possible to derive or compute E.g. Name, Address  Derived : The value may be derived (computed) from the values of other attributes. E.g. Age (current year – year of birth) Length of employment (current date- start date) Profit (earning-cost) G.P.A (grade point/credit hours) 4) Null Values   NULL applies to attributes which are not applicable or which do not have values.You may enter the value NA (meaning not applicable)  Value of a key attribute cannot be null.  Default value - assumed value if no explicit value

The RELATIONSHIPS The RELATIONSHIPS between entities which exist and must be taken into account when processing information. In any business processing one object another object due to some event. Such kind of association may be associated with is what we call a RELATIONSHIP between entity objects.  One external event or process may affect several related entities.  Related entities require setting of LINKS from one part of the database to another.  A relationship should be named by a word or phrase which explains its function •  Role names are different from the names of entities forming the relationship: one entity may take on many roles, the same role may be played by different entities

Role can be used when two entities are associated through more than one relationship to classify the purpose of each relationship.

Cardinality of a Relationship  Another important concept about relationship is the number of instances/tuples that can be associated with a single instance from one entity in a single relationship. The number of instances participating or associated with a single instance from an entity in a relationship is called the CARDINALITY of the relationship.  The major cardinalities of a relationship are: a) ONE-TO-ONE : one tuple is associated with only one other tuple. E.g. Building – Location As a single building will be located in a single location and as a single location will only accommodate a single Building. b) ONE-TO-MANY , one tuple can be associated with many other tuples, but not the reverse. E.g. Department-Student As one department can have multiple students. c) MANY-TO-ONE , many tuples are associated with one tuple but not the reverse. E.g. Employee – Department: A s many employees belong to a single department.

d) MANY-TO-MANY : one tuple is associated with many other tuples and from the other side, with a different role name one tuple will be associated with many tuples,. E.g. Student – Course As a student can take many courses and a single course can be attended by many students.

E/R Diagram Representation Now we shall learn how ER Model is represented by means of ER diagram. Every object like entity, attributes of an entity, relationship set, and attributes of relationship set can be represented by tools of ER diagram

E/R diagram Case study for E/R diagram Consider the following set of requirements for a Bank database that is used to keep track of Customer. a) Each bank has a unique name. b) Each branch has a number, name, address (number, street, city), and set of phones. c) Customer includes their name, set of address (P.O. Box, city, zip code, country), set of phones, and social security number. d) Accounts have numbers, types (e.g. saving, checking) and balance. Other branches might use the same designation for accounts. So to name an account uniquely, we need to give both the branch number to which this account belongs to and the account number. e) Not all bank customers must own accounts and a customer may have at most 5 accounts in the bank. f) g) An account must have only one customer.A customer may have many accounts in different branches Q2. A football club has a name and a ground and is made up of players. A player can play for only one club and a manager, represented by his name manages a club. A footballer has a registration number, name and age. A club manager also buys players. Each club plays against each other club in the league and matches have a date, venue and score.”

 Key constraints If tuples are need to be unique in the database, and then we need to make each tuple distinct. To do this we need to have relational keys that uniquely identify each relation. Super Key Candidate Key : an attribute or set of attributes that uniquely identifies a tuple within a relation.: a super key such that no proper subset of that collection is a Super Key within the relation. A candidate key has two properties:

1. Uniqueness

2. Irreducibility

If a super key is having only one attribute, it is automatically a Candidate key. If a candidate key consists of more than one attribute it is called Composite Key. Primary Key: the candidate key that is selected to identify tuples uniquely within the relation. The entire set of attributes in a relation can be considered as a primary case in a worst case. Foreign Key: candidate key of some relation. A foreign key is a link between different relations to an attribute, or set of attributes, within one relation that matches the create the view or the unnamed relation assume a value of NULL Participation ConstraintsTotal Participation: Each entity in the entity is involved in the relationship. Total participation is represented by double lines.  Partial participation: Not all entities are involved in the relationship. Partial participation is represented by single line.

[ Image: Participation Constraints]

Relational Views

Relations are perceived as a Table from the users’ perspective. Actually, there are

two kinds of relation in relational database. The two categories or types of Relations are

Named and Unnamed Relations. The basic difference is on how the relation is created,

used and updated:

  1. Base Relation A Named Relation corresponding to an entity in the conceptual

schema, whose tuples are physically stored in the database.

  1. View (Unnamed Relation) A View is the dynamic result of one or more

relational operations operating on the base relations to produce another virtual

relation that does not actually exist as presented. So a view is virtually derived

relation that does not necessarily exist in the database but can be produced upon

request by a particular user at the time of request. The virtual table or relation can

be created from single or different relations by extracting some attributes and

records with or without conditions.

Purpose of a view

 Hides unnecessary information from users: since only part of the base relation (Some

collection of attributes, not necessarily all) are to be included in the virtual table.

 Provide powerful flexibility and security: since unnecessary information will be

hidden from the user there will be some sort of data security.

 Provide customized view of the database for users: each users are going to be

interfaced with their own preferred data set and format by making use of the Views.

 A view of one base relation can be updated.

 Update on views derived from various relations is not allowed since it may violate the

integrity of the database.