UNIT 2 Dbms Notes
UNIT 2 Dbms Notes
Data modelling - data modelling is the process of creating a data model for the
data to be stored in a database. This data model is a conceptual representation of
Data objects, the associations between different data objects, and the rules. Data
modelling helps in the visual representation of data and enforces business rules,
regulatory compliances, and government policies on the data. Data Models
ensure consistency in naming conventions, default values, semantics, security
while ensuring quality of the data.
Data Model
The Data Model is defined as an abstract model that organizes data description,
data semantics, and consistency constraints of data. The data model emphasizes
on what data is needed and how it should be organized instead of what
operations will be performed on data. Data Model is like an architect's building
plan, which helps to build conceptual models and set a relationship between
data items.
1. Conceptual Data Model: This Data Model defines WHAT the system
contains. This model is typically created by Business stakeholders and
Data Architects. The purpose is to organize, scope and define business
concepts and rules.
2. Logical Data Model: Defines HOW the system should be implemented
regardless of the DBMS. This model is typically created by Data
Architects and Business Analysts. The purpose is to developed technical
map of rules and data structures.
3. Physical Data Model: This Data Model describes HOW the system will
be implemented using a specific DBMS system. This model is typically
created by DBA and developers. The purpose is actual implementation of
the database.
Entities
Attributes
Relationships
ENTITY
An entity can be place, person, object, event or a concept, which stores data in
the database. The characteristics of entities are must have an attribute, and a
unique key. Every entity is made up of some 'attributes' which represent that
entity.
Examples of entities:
Entity set:
An entity set is a group of similar kind of entities. It may contain entities with
attribute sharing similar values. Entities are represented by their properties,
which also called attributes. All attributes have their separate values. For
example, a student entity may have a name, age, class, as attributes.
Strong Entity
Weak entity
The connecting line of the strong entity The line connecting the weak entity set
set with the relationship is single. for identifying relationship is double.
Attributes
For example, a lecture might have attributes: time, date, duration, place, etc.
For example, The entity ‘Student’ has properties like Name, Address,
Roll_no, Mobile_no, Age, DOB, Class, Section, etc. So, when we make an E-
R diagram then Name, Address, Roll_no, Mobile_no, Age, DOB, Section and
Class are represented as the attributes of the entity type ‘Student’.
In the above example, we see that we have used various modified oval
symbols to represent the E-R diagram. Various symbols represent various
types of the attribute. The text of one attribute(Roll_no) is underlined, the
other attribute(Email) is written in double oval, etc. We will understand all this
as we go through this blog and learn about various types of attributes and how
they are represented in the E-R diagram.
Simple Attribute
Composite Attribute
For example, Name of a student can be further divided into first name, middle
name and last name. The composite attribute name is also represented by oval
as well as the other attributes are also represented by oval and we connect the
all the further divided attributes with the composite attribute. In the table, we
will have three columns i.e. First_name, Middle_name, and Last_name. There
is no such column called "Name".
Single-valued Attribute
This attribute has only one value. It is represented by a simple oval. Some
simple attribute can also be a single-valued attribute. For example, the Section
of ‘Student’ is a simple attribute as it can’t be further divided. Also, it is a
single-valued attribute because a student can't study in more than one section.
For example, Section of a Student.
Multivalued Attribute
This attribute has more than one value. It is represented by a double oval.
Some Composite keys can also be a multivalued attribute. For example, the
address attribute of a student can further be divided into ‘Locality’, ‘Town’
and ‘PIN’. So, we call it a composite attribute. Also, the address of a student
can have more than one value. A Student can have more than one Address i.e
Permanent Address and Temporary Address. So, it can also be called a
multivalued attribute.
For example, A student can have more than one e-mail address.
Derived Attribute
This classification is made on the basis that if the attribute is just stored in the
database or can be derived from some other attribute.
The value of this attribute should be provided by the user. This attribute is
stored and can be used for finding the value of other attributes. It cannot be
derived from any other attribute. It is also represented by an oval. For
Example, The Date of Birth of ‘Student’ has to be provided by the student.
The value of this attribute is derived from some other attributes. We know the
value of some other attribute(stored attribute)and from stored attribute, we are
deriving the value of this attribute(derived attribute). This is done mainly
because the value for such attribute keeps on changing. It is represented by a
dashed oval.
For example, The value of age attribute is derived from the DOB(date of
birth) attribute.
Key Attribute
Example: We have Roll_no as the key attribute of the ‘Student’ because two
students can never has same roll number.
Non-Key Attribute
All the other attributes other than the key attribute are the non-key attributes.
Two or more entities can have the same value for this attribute. For example,
the Class attribute would have the same value for all those students who are
studying in the same class.
Example: Class, Section, Age, Name etc, are the non-key attributes.
Relationship
Entities take part in relationships. We can often identify relationships with verbs
or verb phrases.
For example:
One-to-One Relationships
One-to-Many Relationships
May to One Relationships
Many-to-Many Relationships
When a single instance of an entity is associated with more than one instances
of another entity then it is called one to many relationship. For example – a
customer can place many orders but a order cannot be placed by many
customers.
When more than one instances of an entity is associated with a single instance
of another entity then it is called many to one relationship. For example – many
students can study in a single college but a student cannot study in many
colleges at the same time.
When more than one instances of an entity is associated with more than one
instances of another entity then it is called many to many relationship. For
example, a can be assigned to many projects and a project can be assigned to
many students.
Participation Constraints
Total Participation − Each 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 lines.
For example, If we have two entity type ‘Customer’ and ‘Account’ and they
are linked using the primary key and foreign key. We can say that the degree
of relationship is 2 because here two entities are taking part in the relationship.
Based on the number of entity types that are connected we have the following
degree of relationships:
Unary
Binary
Ternary
N-ary
Unary (degree 1)
A unary relationship exists when both the participating entity type are the
same. When such a relationship is present we say that the degree of
relationship is 1.
So, here we get the answer to our first question which was asked in the
introduction section. Yes, there can be only one entity type in a relationship
and the minimum degree of a relationship can be one.
Binary (degree 2)
A binary relationship exists when exactly two entity type participates. When
such a relationship is present we say that the degree is 2. This is the most
common degree of relationship. It is easy to deal with such relationship as
these can be easily converted into relational tables.
For example, We have two entity type ‘Customer’ and ‘Account’ where each
‘Customer’ has an ‘Account’ which stores the account details of the
‘Customer’. Since we have two entity types participating we call it a binary
relationship. Also, one ‘Customer’ can have many ‘Account’ but each
‘Account’ should belong to only one ‘Customer’. We can say that it is a one-
to-many binary relationship
Ternary(degree 3)
A ternary relationship exists when exactly three entity type participates. When
such a relationship is present we say that the degree is 3. As the number of
entity increases in the relationship, it becomes complex to convert them into
relational tables.
N-ary (n degree)
An N-ary relationship exists when ‘n’ number of entities are participating. So,
any number of entities can participate in a relationship. There is no limitation
to the maximum number of entities that can participate. But, relations with a
higher degree are not common. This is because the conversion of higher
degree relations to relational tables gets complex. We are making an E-R
model because it can be easily be converted into any other model for
implementing the database. But, this benefit is not available if we use higher
degree relations. So, binary relations are more popular and widely used.
Though we can make a relationship with any number of entity types but we
don't do that.
3 types of models
Hierarchical Model
Network Model
Relational Model
Herarchical model
In hierarchical model, data is organised into tree-like structure with one one-
to-many relationship between two different types of data, for example, one
department can have many courses, many professors and of-course many
students.
Relational Model
Keys in DBMS
Here are some reasons for using sql key in the DBMS system.
There are mainly seven different types of Keys in DBMS and each key has it’s
different functionality:
record is called a surrogate key. These kind of key are unique because
they are created when you don't have any natural primary key.
record is called a surrogate key. These kind of key are unique because
they are created when you don't have any natural primary key.
Example:
Example:
In this table, StudID, Roll No, Email are qualified to become a primary key. But
since StudID is the primary key, Roll No, Email becomes the alternative key.
Example: In the given table Stud ID, Roll No, and email are candidate keys
which help us to uniquely identify the student record in the table.
Example:
DeptCode DeptName
001 Science
002 English
005 Computer
In this key in dbms example, we have two table, teach and department in a
school. However, there is no way to see which search work in which
department.
In this table, adding the foreign key in Deptcode to the Teacher name, we can
create a relationship between the two tables.
COMPOUND KEY has two or more attributes that allow you to uniquely
recognize a specific record. It is possible that each column may not be unique
by itself within the database. However, when combined with the other column
or columns the combination of composite keys become unique. The purpose of
the compound key in database is to uniquely identify each record in the table.
Example:
In this example, OrderNo and ProductID can't be a primary key as it does not
uniquely identify a record. However, a compound key of Order ID and Product
ID could be used as it uniquely identified each record.
The difference between compound and the composite key is that any part of the
compound key can be a foreign key, but the composite key may or maybe not a
part of the foreign key.
Above, given example, shown shift timings of the different employee. In this
example, a surrogate key is needed to uniquely identify each employee.
1. Super key – i)set of attributes which can uniquely identify a tuple. ii) A
super key may have additional attributes that are not needed for unique
identification.
Erpid
Prn no.
Erpid + prn no
Erpid + prnno. + name - trivial sk
Erpid + name
Prn no. + name
2. Candidate key – i) is a minimal super key. Ii) no additional attribute is
required
Erpid
Prn no.
Erpid + prn no
Erpid + name
Erpid + prn no
Erpid + name
It adds no meaning to the data but serves the sole purpose of identifying
rows uniquely in a table.
For eg: In this below table noth student name and city are not uniquely
defines the the row so now we have to add Sno. To uniquely identify the
row. Therefore, Sno.is a surrogate key.