DBMS-1 unit notes
DBMS-1 unit notes
Data is nothing but facts and statistics stored or free flowing over a
network, generally it's raw and unprocessed. For example: When
you visit any website, they might store you IP address, that is data,
in return they might add a cookie in your browser, marking you that
you visited the website, that is data, your name, it's data, your age,
it's data.
What is a Database?
A Database is a collection of related data organised in a way that
data can be easily accessed, managed and updated. Database can
be software based or hardware based, with one sole purpose,
storing data.
During early computer days, data was collected and stored on tapes,
which were mostly write-only, which means once data is stored on it,
it can never be read again. They were slow and bulky, and soon
computer scientists realised that they needed a better solution to
this problem.
Larry Ellison, the co-founder of Oracle was amongst the first few,
who realised the need for a software based Database Management
System.
What is DBMS?
MySql
Oracle
SQL Server
IBM DB2
PostgreSQL
1. Data stored into Tables: Data is never directly stored into the
database. Data is stored into tables, created inside the
database. DBMS also allows to have relationships between
tables which makes the data more meaningful and connected.
You can easily understand what type of data is stored where
by looking at all the tables created in a database.
Advantages of DBMS
Disadvantages of DBMS
It's Complexity
Components of DBMS
The database management system can be divided into five major
components, they are:
1. Hardware
2. Software
3. Data
4. Procedures
Data is that resource, for which DBMS was designed. The motive
behind the creation of DBMS was to store and utilise data.
User can create new databases, tables, insert data, fetch stored
data, update data and delete the data using the access language.
Users
DBMS Architecture
A Database Management system is not always directly available for
users and applications to access and store data in it. A Database
Management system can be centralised(all the data stored at one
location), decentralised(multiple copies of database at different
locations) or hierarchical, depending upon its architecture.
For the end user, the GUI layer is the Database System, and the end
user has no idea about the application layer and the DBMS system.
If you have used MySQL, then you must have seen PHP MyAdmin, it
is the best example of a 3-tier DBMS architecture.
As per your application's requirement, you can use a database model to define
your database.
The database model sets the rule, relationships, constraints, etc. to define
how data is stored in the database.
It's like creating a blueprint of your Database.
There are different types of Database models and each one has its own set of
features.
You can define how you want to structure the application data using a
database model.
In this tutorial you will learn about the 7 database model that are popularly used.
1. Hierarchical Model
2. Network Model
3. Entity-relationship Model
4. Relational Model
5. Object-oriented Model
6. NoSQL Model
7. Graph Model
Let's learn about the different types of database models along with their main
features and when should you use them.
1. Hierarchical Model
The hierarchical database model organizes data into a tree-like structure, with
a single root, to which all the other data is linked.
The hierarchy starts from the Root data, and expands like a tree,
adding child nodes to the parent nodes.
In this model, a child node will only have a single parent node.
This model efficiently describes many real-world relationships like the index
of a book, etc.
IBM's Information Management System (IMS) is based on this model.
Data is organized into a tree-like structure with a one-to-many
relationship between two different types of data, for example,
one department can have many courses, many teachers, and of course
many students (like shown in the diagram below).
Here are a few points to mark the advantages and disadvantages of the Hierarchical
database model:
2. Network Model
The Network Model is an extension of the Hierarchical model.
In this model, data is organized more like a graph, and allowed to have more
than one parent node.
In the network database model, data is more related as more relationships
are established in this database model.
Also, as the data is more related, hence accessing the data is also
easier and fast.
This database model uses many-to-many data relationships.
Integrated Data Store (IDS) is based on this database model.
This was the most widely used database model before Relational Model was
introduced.
The implementation of the Network model is complex, and it's very difficult to
maintain it.
The Network model is difficult to modify also.
You may want to explore this if you are developing some social networking
applications, although the Graph Database model is new and is far better than
the Network Database model.
4. Relational Model
In this model, data is organized in two-dimensional tables and the relationship
is maintained by storing a common field.
This model was introduced by E.F Codd in 1970, and since then it has been
the most widely used database model.
The basic structure of data in the relational model is tables. All the
information related to a particular type is stored in rows of that table.
Hence, tables are also known as relations in the relational model.
You can design tables, normalize them to reduce data redundancy,
and use Structured Query language or SQL to access data from the tables.
Some of the most popular databases are based on this database model. For
example, Oracle, MySQL, etc.
5. Object-oriented Model
In this model, data is stored in the form of objects.
The behavior of the object-oriented database model is just like object-oriented
programming.
A very popular example of an Object Database management system
or ODBMS is MongoDB which is also a NoSQL database.
This database model is not mature enough as compared to the relational
database model.
Advantages of the Object-oriented Model
6. NoSQL Model
The NoSQL database model supports an unstructured style of storing data.
Data is stored as documents.
The documents look more like JSON strings or Key-value based object
representations.
It provides a flexible schema.
It does provide features like indexing, relationships between data, etc.
The support for data querying is limited in the NoSQL database model.
This database model is well-suited for Big data applications, real-time
analytics, CMS (Content Management systems), etc.
Advantages of the NoSQL Model
7. Graph Model
The Graph database model is based on more real-world like relationships.
Data is represented using Nodes or entities.
The nodes are related using edges.
The popular database Neo4j is based on the Graph database model.
If your application has simple data requirements, then you should not use the
graph database model.
In modern applications like social networks, recommendation systems, etc.
the graph database model is well-suited.
Advantages of the Graph Model
There is one more feature that should be kept in mind i.e. the data
independence. While changing the data schema at one level of the
database must not modify the data schema at the next level. In this section,
we will discuss the view of data in DBMS with data abstraction, data
independence, data schema in detail.
Three-Schema Architecture:
The main objective of this architecture is to have an effective separation
between the user interface and the physical database. So, the user never
has to be concerned regarding the internal storage of the database and it
has a simplified interaction with the database system.
The physical or the internal level schema describes how the data is stored
in the hardware. It also describes how the data can be accessed. The
physical level shows the data abstraction at the lowest level and it
has complex data structures. Only the database administrator operates at
this level.
It is a level above the physical level. Here, the data is stored in the form of
the entity set, entities, their data types, the relationship among the entity
sets, user operations performed to retrieve or modify the data and
certain constraints on the data. Well adding constraints to the view of data
adds the security. As users are restricted to access some particular parts
of the database.
In the figure above you can clearly distinguish between the three levels of
abstraction. To understand it more clearly let us take an example:
Now, the entity sets Student, Lecturer, Department, Course will be stored in
the storage as the consecutive blocks of the memory location. This is
the physical or internal level and is hidden from the programmers but the
database administrator is it aware of it.
At the logical level, the programmers define the entity sets and relationship
among these entity sets using a programming language like SQL. So, the
programmers work at the logical level and even the database administrator
also operates at this level.
At the view level, the users have the set of applications which they use to
retrieve the data they are interested in.
Data Independence
Data independence defines the extent to which the data schema can be
changed at one level without modifying the data schema at the next level.
Data independence can be classified as shown below:
Well, the changes to data schema at the logical level are made either
to enlarge or reduce the database by adding or deleting more entities,
entity sets, or changing the constraints on data.
What is schema?
Whenever we talk about the database the developers have to deal with the
definition of database and the data in the database.
Key Takeaways:
View of data in DBMS describes the abstraction of data at three-level
i.e. physical level, logical level, view level.
The physical level of abstraction defines how data is stored in the storage
and also reveals its access path.
Abstraction at the logical level describes what data would be stored in the
database? what would be the relation between the data? and
the constraints applied to the data.
The view level or external level of abstraction describes
the application which the users use to retrieve the information from the
database.
Data independence explains the extent to which data at a certain level can
be modified without disturbing the data next higher levels.
An instance is the retrieval of information from the database at a certain
point of time. An instance in a database keeps on changing with time.
Schema is the overall design of the entire database. Schema of the
database is not changed frequently.
So that’s all about the view of data in the database which help us to
understand the database from users, developers and database
administrator aspects.
File System
Example:
Oracle, MySQL, MS SQL server.
DBMS
It has a comparatively
It is less expensive than
higher cost than a file
DBMS.
Cost system.
In DBMS data
independence exists,
mainly of two types:
There is no data
1) Logical Data
independence.
Independence.
Data 2)Physical Data
Independence Independence.
Data Independence
o Data independence can be explained using the three-schema architecture.
o Data independence refers characteristic of being able to modify the schema at one
level of the database system without altering the schema at the next higher level.
The main differences between DBMS and RDBMS are given below:
No. DBMS RDBMS
1) DBMS applications store data as file. RDBMS applications store data in a tabular form.
2) In DBMS, data is generally stored in In RDBMS, the tables have an identifier called primary ke
either a hierarchical form or a and the data values are stored in the form of tables.
navigational form.
4) DBMS does not apply any security with RDBMS defines the integrity constraint for the purpos
regards to data manipulation. of ACID (Atomocity, Consistency, Isolation and Durability
property.
5) DBMS uses file system to store data, in RDBMS, data values are stored in the form of tables, s
so there will be no relation between a relationship between these data values will be stored i
the tables. the form of a table as well.
6) DBMS has to provide some uniform RDBMS system supports a tabular structure of the dat
methods to access the stored and a relationship between them to access the store
information. information.
8) DBMS is meant to be for small RDBMS is designed to handle large amount of data.
organization and deal with small data. supports multiple users.
it supports single user.
After observing the differences between DBMS and RDBMS, you can say that RDBMS
is an extension of DBMS. There are many software products in the market today who
are compatible for both DBMS and RDBMS. Means today a RDBMS application is
DBMS application and vice-versa.
Notation of ER diagram
Database can be represented using the notations. In ER diagram, many notations are
used to express the cardinality. These notations are as follows:
Fig: Notations of ER diagram
Component of ER Diagram
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can
be represented as rectangles.
a. Weak Entity
Backward Skip 10sPlay VideoForward Skip 10s
An entity that depends on another entity called a weak entity. The weak entity doesn't
contain any key attribute of its own. The weak entity is represented by a double
rectangle.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to
represent an attribute.
For example, id, age, contact number, name, etc. can be attributes of a student.
a. Key Attribute
c. Multivalued Attribute
An attribute can have more than one value. These attributes are known as a
multivalued attribute. The double oval is used to represent multivalued attribute.
For example, a student can have more than one phone number.
d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute.
It can be represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another
attribute like Date of birth.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus
is used to represent the relationship.
Types of relationship are as follows:
a. One-to-One Relationship
ADVERTISEMENT
ADVERTISEMENT
When only one instance of an entity is associated with the relationship, then it is
known as one to one relationship.
For example, A female can marry to one male, and a male can marry to one female.
ADVERTISEMENT
ADVERTISEMENT
b. One-to-many relationship
When only one instance of the entity on the left, and more than one instance of an
entity on the right associates with the relationship then this is known as a one-to-
many relationship.
For example, Scientist can invent many inventions, but the invention is done by the
only specific scientist.
c. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an
entity on the right associates with the relationship then it is known as a many-to-one
relationship.
For example, Student enrolls for only one course, but a course can have many
students.
ADVERTISEMENT
ADVERTISEMENT
d. Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of
an entity on the right associates with the relationship then it is known as a many-to-
many relationship.
For example, Employee can assign by many projects and project can have many
employees.
Notation of ER diagram
Database can be represented using the notations. In ER diagram, many notations are
used to express the cardinality. These notations are as follows:
Fig: Notations of ER diagram
Cardinality
Cardinality means how the entities are arranged to each other or what is the
relationship structure between entities in a relationship set. In a Database
Management System, Cardinality represents a number that denotes how many times
an entity is participating with another entity in a relationship set. The Cardinality of
DBMS is a very important attribute in representing the structure of a Database. In a
table, the number of rows or tuples represents the Cardinality.
Cardinality Ratio
Cardinality ratio is also called Cardinality Mapping, which represents the mapping of
one entity set to another entity set in a relationship set. We generally take the
example of a binary relationship set where two entities are mapped to each other.
ADVERTISEMENT
ADVERTISEMENT
1. One to one
2. Many to one
3. One to many
4. Many to many
One to One
One to one cardinality is represented by a 1:1 symbol. In this, there is at most one
relationship from one entity to another entity. There are a lot of examples of one-to-
one cardinality in real life databases.
For example, one student can have only one student id, and one student id can
belong to only one student. So, the relationship mapping between student and
student id will be one to one cardinality mapping.
Another example is the relationship between the director of the school and the
school because one school can have a maximum of one director, and one director
can belong to only one school.
Note: it is not necessary that there would be a mapping for all entities in an entity set in
one-to-one cardinality. Some entities cannot participate in the mapping.
One to one Cardinality is the subset of Many to one Cardinality. It can be represented
by M:1.
For example, there are multiple patients in a hospital who are served by a single
doctor, so the relationship between patients and doctors can be represented by
Many to one Cardinality.
It is represented by M: N or N: M.
One to one cardinality, One to many cardinalities, and Many to one cardinality is the
subset of the many to many cardinalities.
For Example, in a college, multiple students can work on a single project, and a
single student can also work on multiple projects. So, the relationship between the
project and the student can be represented by many to many cardinalities.
o We can combine relational tables with many involved tables if the Cardinality is one-
to-many or many-to-one.
o One entity can be combined with a relation table if it has a one-to-one relationship
and total participation, and two entities can be combined with their relation to form a
single table if both of them have total participation.
o We cannot mix any two tables if the Cardinality is many-to-many.
Let’s take an example. As you can see we have a composite attribute Name and this
composite attribute has two simple attributes First_N and Last_N. While converting
this ER to table we have not used the composite attribute itself in the table instead
we have used the simple attributes of this composite attribute as table’s attributes.
3. Strong Entity Set With Multi Valued Attributes
Entity set with multi-valued attributes will require two tables in the relational model.
We will understand this conversion with the help of a diagram. Let’s take the same
example that we have seen above, here we have added a new multi-valued
attribute Dept. An employee can work in multiple department so we have
this Dept attribute marked as multi-valued. Whenever we have a multi-valued attribute,
there needs to be more than one table to represent the ER diagram. As you can see
we have created two tables to represent this ER.
4. Relationship Set to Table conversion
While converting the relationship set to a table, the primary attributes of the two
entity sets becomes the table attributes and if the relationship set has any attribute
that also becomes the attribute of the table.
In the following example, we have two entity sets Employee and Department. These
entity sets are associated to each other using the Works relationship set. To convert
this relationship set Works to the table, we take the primary attributes of each entity
set, these are Emp_Id and Dept_Id and all the attributes of the relationship set and
form a table.
DBMS Specialization
Specialization is a process in which an entity is divided into sub-entities. You
can think of it as a reverse process of generalization, in generalization two
entities combine together to form a new higher level entity. Specialization is a
top-down process.
The idea behind Specialization is to find the subsets of entities that have few
distinguish attributes. For example – Consider an entity employee which can
be further classified as sub-entities Technician, Engineer & Accountant
because these sub entities have some distinguish attributes.
Specialization Example
In the above diagram, we can see that we have a higher level entity “Employee”
which we have divided in sub entities “Technician”, “Engineer” & “Accountant”.
All of these are just an employee of a company, however their role is
completely different and they have few different attributes. Just for the
example, I have shown that Technician handles service requests, Engineer
works on a project and Accountant handles the credit & debit details. All of
these three employee types have few attributes common such as name &
salary which we had left associated with the parent entity “Employee” as
shown in the above diagram.
BMS Aggregration
Aggregation is a process in which a single entity alone is not able to make
sense in a relationship so the relationship of two entities acts as one entity. I
know it sounds confusing but don’t worry the example we will take, will clear
all the doubts.
Aggregration Example
In real world, we know that a manager not only manages the employee
working under them but he has to manage the project as well. In such
scenario if entity “Manager” makes a “manages” relationship with either
“Employee” or “Project” entity alone then it will not make any sense because
he has to manage both. In these cases the relationship of two entities acts as
one entity. In our example, the relationship “Works-On” between “Employee” &
“Project” acts as one entity that has a relationship “Manages” with the entity
“Manager”.
In the database, every entity set or relationship set can be represented in tabular
form.
In the STUDENT table, Age is the derived attribute. It can be calculated at any point
of time by calculating the difference between current date and Date of Birth.
Using these rules, you can convert the ER diagram to tables and columns and assign
the mapping between the tables. Table structure for the given ER diagram is as
below: