Você está na página 1de 7

Data Models

A data model is a set of concepts that can be used to describe the structure of the database and the
different relationships and constraints which hold the data in the database.

Types of Data Model


1. Object Based models
2. Record Based models
3. Physical models

1. Object based models


This type of model concerns mainly to the conceptual level i.e, it concentrates on logical structure of
the database & proper relationship between the various objects. In this model, we do not bother much with
respect to the storage structures or on the access methods.
Some of the object based models are
i. Entity Relationship model
ii. Object Oriented model
iii. Semantic data model
iv. Functional data model

i. Entity Relationship model


It is a collection of real world objects called entities & their relationships. It is mainly represented
in graphical form using E-R diagrams. This is very useful in database design.

Example Database Application


Consider an example of database application containing COLLEGE database. COLLEGE database
keeps track of Students, Faculty, Departments and Courses organized by various departments.
College contains various departments like, English, Kannada, Computer Science, Physics etc. Each
department is assigned a unique id & name.
Some faculty members are also appointed to each department & one of them works as head of the
department.
There are various courses conducted by each department. Each course is assigned a unique id, name &
duration.
 Faculty information contains name, address, department, basic salary etc. A faculty member is
assigned to only one department but can teach various courses of other department also.
 Student information contain Reg.No(Unique), Name, Address etc. A student can opt only for one
course.
 Parent (Guardian) information is also kept along with each student. We keep each guardians name,
age, sex & address.

Entities
An entity is an object of concern used to represent the things in the real world.
Ex: Car, Table, Book, Project, Loan etc.

Entity Set
A collection of a similar kind of entities is called an Entity set. Entity set need not be disjoint.
For example, the collection of all the students entities form a entity set STUDENT. Similarly collection of all
the courses form an entity set COURSE.
1
Primary Key
Primary key is an attribute or set of attributes used to identify every instance uniquely in a entity.

Strong Entity set


The entity types containing a primary key attribute are called as Strong Entity. Ex: The Student entity
has key attribute Reg_no, which uniquely identifies every instance.

Weak Entity
Entity types that do not contain primary key attribute & hence cannot be identified independently, are
called Weak entity types.
Ex: Consider the entity type GUARDIAN/PARENT related to STUDENT entity, which is used to keep track
of the guardians related to students.

Attributes
An attribute is a property used to describe the specific feature of the entity.
For example, A STUDENT entity may be described by the student’s Reg-no, name, age, address, Course etc.
Reg_no: 1234
Name: Supriya
Age: 18
Address : Tumkur
Course: B.Sc

Domains
Each simple attribute of an entity type contains a possible set of values that can be attached to it.
For example, for PERSON entity person_id has a specific domain integer values say from 1 to 100.

Types of Attributes
1. Simple
The attribute that cannot be further divided into smaller parts is called simple attribute.
Ex: Reg_no, age

2. Composite
Attributes that can be divided into smaller units is called Composite attribute.
Ex: Name attribute can be divided into First_name & Last_name.

3. Single Valued
Attribute having a single value for a particular entity.
Ex: AGE

4. Multivalued
Attributesthat have more than one value for a particular entity is called a multivalued attribute.
Ex: Phone_no

5. Null Attributes
Attributes that does not have any values is called Null attribute.

6. Derived Attribute
An Attribute whose value is derived from the values of another attribute is termed as derived attribute
2
Ex: The years of experience (Services) of a PERSON entity can be determined from the current date &
the date of joining.

Relationships
An association among entities is called a relationship.
Ex: In COLLEGE database, the association between STUDENT & COURSE entity, i.e, “Students opts
Course”.

Relationship sets
A relationship set is a set of relationships of the same type.

Binary Relationship
A relationship is termed as binary if the number of entities involved in the relationship is two.

N-ary Relationship
A relationship which involves N entities is called an N-ary relationship.

Mapping Constraints
Two important mapping constraints are:
i. Mapping Cardinalities
ii. Existence dependencies.

i. Mapping Cardinalities
Cardinality specifies the number of instances of an entity associated with another entity
participating in a relationship.
Cardinality is classified into the following categories.

1. One to One
An entity in A is associated with at most one entity in B & vice versa.
Ex:
COLLEGE 1 1 PRINCIPAL
H
as
One college can have at the most one Principal & one principal can be assigned to only one
college.

2. One to many
An entity A is associated with any number of entities in B. An entity in B is associated with at the most
one entity in A.
Ex:
DEPARTMENT 1 Works N FACULTY
in

One department can appoint any number faculty members but a faculty member is assigned to only
one department.

3. Many to one

3
An entity in A is associated with at most one entity in B. An entity in B is associated with any number
in A.
Ex:
COURSE M Teach 1 FACULTY
es

An faculty can teach various courses but a course can be taught only by one faculty.
( Note: This is assumption)

4. Many to Many
Entities in A & B are associated with any number of entities from each other.

Ex:
BOOK M Teach N AUTHOR
es

One author can write many books & one book can be written by more than one author.

ii. Existence dependencies


If the existence of a particular entity depends on the existence of another entity then we say
that the first entity existence dependent on the second entity. If the second entity is deleted then all
associations with the first entity is lost.

Keys
1. Super Keys
A super key is an attribute or set of attributes used to identify the instances uniquely in a entity set.

2. Primary Keys
A primary key is an attribute used to identify the instances uniquely & should be not null.

3. Candidate Keys
Candidate keys are minimal super keys. i.e, it contains two or more attributes which uniquely
identifies an instance of an entity set. For ex: In the relation PERSON the two possible candidate keys
are Person_id & name (Assuming unique names in the table), Person_id may be chosen as the primary
key

4. Secondary Key
It is an attribute or combination of attributes that may not be a candidate key but that classifies
the entity set on a particular characteristics.

E-R Diagram
We can express the overall logical structure of a database using E-R model graphically with the help of an E-
R diagram.’

Components of E-R diagram


Symbol Meaning

4
Rectangles Represents entity

Double
Weak entity
Rectangle

Diamond Relationship

Double Identifying
Diamond relationship

Ellipses Attribute

Double
Multivalued attribute
Ellipses

Key Attribute

Composite Attribute

Derived Attribute

E1 E2 Total participation of
R E2

E1 E2 Cardinality ratio 1:N


R for E1:E2 in R

5
E-R diagram of COLLEGE Database

Reg_n Name Address Course_i Course_Nam


d e Durartio
o n

STUDENT
Op COURSE
ts

Taught
by
H Enroll
a ed ID
s
Dept_Name

DEPARTMENT Wor FACULTY Addr


ks
in

Guardian Dept_no

Nam Basic_sa
e l
Relationship

Nam Addr
e
Hea
d of

Date_from

6
Assignment:
An employee works for a department. If the employee is a manager then he/she manages the department. As
an employee the person works for the project and the various departments of a company control those
projects. An employee can have many dependents. Draw an E-R diagram for the above company. Try to find
out all possible entities and relationships among them.

Você também pode gostar