Sunday 27 October 2013

The ER Model



In our previous sessions, we've been some what brief to the relational database models. Toady, we'll have an in detail examination of what is what. Basically, in R DBMS everything that is data before is now a relation. Hence, a relational database consists of relation aka tables which have rows and columns.

  • Rows are called Tuples.
  • Columns are called attributes.
  • Number of rows in a table constitute the cardinality.
  • Number of columns in a table constitute the arity.
  • The intersection of a row and a column is called a cell.
Hence, we work entirely on the cells, at each tuple of an attribute. the relational database was constructed based on a theory called the ER model. The ER model describes how a relation can be established, given a problem. The entities are the things that are under our examination. here we can assume an entity to be a table. An attribute describes the entity well. hence it is a description of the entity. we can assume this attribute to the columns of our table. A Relation is the thing that relates two entities: an intersection of two entities. We try to work out the model in our construction of a table. The model uses a diagrammatic approach for different cases of entities and attributes, and for a relation. The main elements of ER model are:

  • Entity
  • Attribute
  • Relation
Entity is represented by a rectangular box, an attribute by an ellipse and relationship is done by a Rhombus. A small example of ER model is discussed below:

Problem: a Student Joins in a College

Model:

There are principally 3 types of relationships, by their nature. They are:

  • One-to-One
  • One-to-Many/ Many-to-One
  • Many-to-Many
One to One relationship involves two entity relationship, One to Many involves more relations while many to many involves even more relations.

The Above problem can be modified to all the types like:

a Student Joins in a College (1-1)




many Students Join a College (m-1)



many Students Join many Colleges (m-m)




Another important element in the construction of a database, is the selection of the keys. A key is an attribute of a relation that uniquely identifies each tuple. For example if we take all the students information in a relation, then obviously student roll number or his admission number or his registration number will be unique of each student. hence they are all alternatives for the key.

One such attribute selected is called a Primary Key. If two relation have a common key that uniquely identifies its Tuples, is called a foreign key. This is similar to a Parent-Child relationship in class and objects concept: inheritance. If two or more keys are combined in case of forming a single key for a table, its called  a composite key. Hence there are:

  • Primary Key
  • Foreign Key
  • Composite Key
  • Candidate Key
in a table. The ER model of a relation is mapped in order to construct a database table. Hence we involve the following steps in the construction of a database:

  • Referring the Problem
  • Identifying the Entities, attributes and Relations
  • Framing a model for the problem
  • Mapping the model for our database table.

No comments:

Post a Comment