Dbms Notes Unit 1
Dbms Notes Unit 1
Introduction
What is Data?
Data is nothing but raw facts and figure is known as data. Generally it's raw and unprocessed.
Data becomes information when it is processed, turning it into something meaningful.
Database
The database is a collection of inter-related data which is used to retrieve, insert and delete the
data efficiently. It is also used to organize the data in the form of a table, schema, views, and
reports, etc. For example: The college Database organizes the data about the admin, staff,
students and faculty etc. Using the database, you can easily retrieve, insert, and delete the
information.
A Database is a collection of related data organized in a way that data can be easily accessed,
managed and updated. Database can be software based or hardware based, on purpose storing
data.
A database is a collection of related information stored, so that it is available to many users for
different purpose.
On the other hand management system is a collection of programs that enables users to create
and maintain the database.
DBMS is a collection of inter-related data and set of programs to access those data. DBMS can also
define as an interface between the application program and the operating system to access or manipulate
the database.
Database management system is software which is used to manage the database. For
example: MySQL, Oracle, etc are a very popular commercial database which is used in different
applications. DBMS provides an interface to perform various operations like database creation,
storing data in it, updating data, creating a table in the database. It provides protection and
security to the database.
Goal of DBMS:-
The primary goal of DBMS is to provide a way to store and retrieve database information that is
both convenient and efficient.
Advantages of DBMS:-There are various Advantages of DBMS which are given below.
1. Reducing Data Redundancy: - Data Redundancy refers to the duplication of data. Data
Redundancy occurs when the same data are stored unnecessarily at different places. Data
Redundancy is reduced or eliminated in DBMS because all data are stored at a
centralized location rather than being created by individual users and for each
application.
2. Sharing of Data: -An advantage of the database management approach is, the DBMS
helps to create an environment in which end users have better access to more and better-
managed data.
3. Data Security:-DBMS systems provide a strong framework to protect data privacy and
security. DBMS ensures that only authorized users have access to data and there is a
mechanism to define access privileges.
4. Data Searching:-Searching and retrieving of data is very easy in DBMS systems. In
DBMS, we can write small queries to search for multiple information at a time from the
data from DB servers.
5. Better interaction with users: - As compared to traditional database system ,a DBMS
provide better service to the users.
6. Maintenance of Data integrity:-Data integrity refers to ensuring that the data in
database is accurate.
Disadvantages of DBMS:
DBMS vs. Flat File or Advantages of DBMS over file processing system
Design to fulfill the need for small and large businesses. It is only limited to smaller DBMS system.
Functions of DBMS
• Data Definition: The DBMS provides functions to define the structure of the data in
the application. These include defining and modifying the record structure, the type and
size of fields and the various constraints to be satisfied by the data in each field.
• Data Manipulation: Once the data structure is defined, data needs to be inserted,
modified or deleted. These functions which perform these operations are part of DBMS.
• Data Security & Integrity: The DBMS contains modules which handle the security
and integrity of data in the application.
• Data Recovery and Concurrency: Recovery of the data after system failure and
concurrent access of records by multiple users is also handled by DBMS.
• Data Dictionary Maintenance: Maintaining the data dictionary which contains the
data definition of the application is also one of the functions of DBMS.
• Performance: Optimizing the performance of the queries is one of the important
functions of DBMS.
Database Architecture
Three level or client server architecture of dbms:-Database management
systems architecture will help us understand the components of database system and the relation
among them.
. 1. Single tier architecture:-. Single -tier DBMS architecture also exist, this is when the
database is directly available to the user for using it to store data. Generally such a setup is used
for local application development, where programmers communicate directly with the database
for quick response.
DATA MODEL: - Data model is a conceptual tool for describing data, data relationship
and its consistency constraints. A Data models is simply a diagram that displays a set of tables
and relationship between them. Data models define how data is connected to each other and how
they are processed and stored inside the system. Data models are the process of creating a model
to represent the way the data of the application is going to be stored.
Types of Data Models in DBMS: - There are several different Database model types
which are given below.
1. Hierarchical Model
2. Network Model
3. Relational Model
4. Object-oriented Model
5. Entity-relationship Model
6. Extended Entity-relationship Model
Hierarchical Model: -
The hierarchical data model is one of the oldest data models, developed in the 1950s by IBM.
In this data model, the data is organized in a hierarchical tree-like structure. This data model
can be easily visualized because each record in DBMS has one parent and many children
(possibly 0). In hierarchical database model hierarchy starts from the Root data, and expands
like a tree, adding child nodes to the parent nodes. 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).
The above-given image represents the data model of the Vehicle database, vehicle are
classified into two types Viz. two-wheelers and four-wheelers and then they are further
classified.
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. This database model uses
many-to-many data relationships.
The network model expands on the hierarchical model by providing multiple paths among
segments. By supporting multiple path this model eliminates some of the drawback of
hierarchical model. The main drawback of network model is that it can be quite complicated to
maintain all the links.
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.
The main drawback of this model is that it cannot store unstructured data.
Object-oriented Model: -
The relational model has been successfully in a wide variety of application area however it
doesn’t support the distribution of one database across number of server due to this reason
object-oriented model was developed. In this model data is stored in the form of object and also
stored unstructured data. The behaviour 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. It can easily support complex data
structures, with relationships. It also supports features like Inheritance, Encapsulation, etc.
ER Model: -
An Entity–relationship model (ER model) describes the structure of a database with the help of
a diagram, which is known as Entity Relationship Diagram (ER Diagram). The ER or (Entity
Relational Model) is a high-level conceptual data model diagram. Entity-Relation model is based
on the notion of real-world entities and the relationship between them. E-R Models are defined to
represent the relationships into pictorial form to make it easier for different stakeholders to
understand.
This model is good to design a database, which can then be turned into tables in relational model
The entity relationship (E-R) model consists of a collection of basic objects, called entities and of
relationships among these entities. These three basic objects are also called the component of ER
Diagram.
Entity
An entity can be real world object, either animate or inanimate, that can be easily identifiable.
For example, in a school database, students, teachers, classes and courses offered can be
considered as entities. Entities are represented by means of rectangles.
Students
1. Strong entity
2. Weak entity
1. Strong entity:-The Strong Entity is the one whose existence does not depend on the
existence of any other entity in a schema. It is denoted by a single rectangle. A strong entity
always has the primary key in the set of attributes that describes the strong entity. It indicates
that each entity in a strong entity set can be uniquely identified.
2. Weak entity:-An entity that cannot be uniquely identified by its own attributes
and relies on the relationship with other entity is called weak entity. The weak
entity is represented by a double rectangle. For example – a bank account cannot
be uniquely identified without knowing the bank to which the account belongs, so
bank account is a weak entity..
Bank
Account
Relationship
A relationship is an association among several entities. For example an employee works at a
department, a student enrolls in a course. Here, works at and enrollsare called relationship.
Relationships are represented by diamond-shaped box.
There are three types of relationship that exist between Entities.
1. Binary Relationship
2. Recursive Relationship
3. Ternary Relationship
Binary Relationship:-Binary Relationship means relation between two Entities. This is further
divided into 4 types.
1. One to one(1:1)
2. One to many(1:m)
3. Many to one(m:1)
4. Many to many(m:m)
Super class
Super class is an entity that can be divided into further subtype.A superclass is the class from
which many subclasses can be created.The superclass is also known as the parent class or base
class.
For example − consider Shape super class.
Subclasses
A subclass is a class derived from the super class. It inherits the properties of the super class and
also contains attributes of its own.
On the above figure Triangle, square, circle is sub class of shapes.
Inheritance
Inheritance is basically the process of basing a class on another class i.e. to build a class on an
existing class. The new class contains all the features and functionalities of the old class in
addition to its own.
Generalization is a bottom-up approach in which two lower level entities combine to form a
higher level entity. In generalization, the higher level entity can also combine with other lower
level entities to make further higher level entity. It's more like Super class and Subclass system,
but the only difference is the approach, which is bottom-up. Hence, entities are combined to form
a more generalized entity, in other words, sub-classes are combined to form a super-class.
For example, saving and Current account type’s entities can be generalized and an entity with
name Account can be created, which covers both.
In the diagram above, the relationship between Center and Course together, is acting as an
Entity, which is in relationship with another entity Visitor. Now in real world, if a Visitor or a
Student visits a Coaching Center, he/she will never enquire about the center only or just about
the course, rather he/she will ask enquire about both
Schema in DBMS
The overall design of the database is called database schema. Schema will not be changed
frequently. It is the logical structure of a database. It does not show the data in the database.
Schema is further divided into three types. These three are as follows.
1. Logical schema.
2. View schema.
3. Physical schema.
1. Physical schema:
In the physical schema, the database is designed at the physical level. At this level, the schema
describes how the data block is stored and how the storage is managed.
2. Logical schema:
In the logical schema, the database is designed at a logical level. At this level, the programmer
and data administrator perform their work. Also, at this level, a certain amount of data is stored
in a structured way. But the internal implementation data are hidden in the physical layer for the
security proposed.
3. View schema:
In view schema, the database is designed at the view level. This schema describes the user
interaction with the database system.
Advantages of Schema
1. Consistency: Guarantees proper storage of data in order to allow easy access and
expandability.
2. Structure: Helps in easy arrangement of the data base in an organized manner and
hence makes it easy to comprehend.
3. Data Integrity: Puts in place restrictions that ensure the data’s maintaining of its
accuracy and subsequent reliability.
Disadvantages of Schema
1. Rigidity: Schemas, defined, may be rigid for alteration, and may take a huge amount of
effort in order to alter the scheme.
2. Complexity: Developing a schema may be difficult or time consuming in case of large
databases.
DBMS Instance
“In DBMS, the data is stored in a particular moment of time, that moment of time is called an
instance of data in the database.” The database schema defines the attributes of the database in
the particular DBMS. The value of the particular attribute at a particular moment in time is
known as an instance of the DBMS.
Defines the basic structure of the database, i.e., how It is the set of Information stored at a
the data will be stored in the database. particular time.
It is two type: -
Data Definition Language (DDL) is used for describing structures or patterns and its relationship
in a database. It is also used to define the database schema, tables, index, Constraints, etc. It can
also be used to store information like the number of tables, names, columns, indexes, etc. The
commands only affect the database structure and not the data.
Truncate: It is used to delete the entities inside the table while holding the structure of the table.
DML is used to manipulate the data present in the table or database. We can easily perform
operations such as store, modify, update, and delete on the database.
Delete: It is used to delete records from the database tables. Also, it can be used with a WHERE
clause to delete a particular row from the table.
DCL works to deal with SQL commands that are used to permit a user to access, modify and
work on a database. it is used to access stored data. It gives access, revokes access, and changes
the permission to the owner of the database as per the requirement.
Revoke: It is used to revoke the access from the user that is being granted by the grant
command.
Rollback: The database gets restored to the original since the last commit.
DBMS INTERFACE
An interface is a program that allows users to input queries into a database without writing the
code in the query language. An interface can be used to manipulate the database for adding,
deleting, updating, or viewing the data.
Types of Interface
Form−based Interface
A form is displayed to each user by the form−based interface. The user fills in the details and
submits the form to make a new entry into the database. It can also be done when the user only
fills in some details and the system will help by retrieving the rest of the details from the
database. The form−based interface is built for the naive user(inexperienced user) which deals
with a limited number of operations. Many DBMS have specification language which helps the
programmer define such forms.
Example
Student entering his roll. no, branch in the form to get the grade card.
In this interface, the user was provided with a list of options (called a menu) through which the
user forms a request. The user doesn’t need to memorize the command and syntax and the query
is composed step by step by picking options from a menu. Pull−down menu interfaces are mostly
used in web−based user interfaces and are often used in browsing interfaces by which the
database content can be looked through.
Example
In a shopping website, categories are selected from the menu, brands are selected from the menu
of brands, and budget ranges are applied from the menu of budget range.
GUI (Graphical User Interface)
Users are provided a schema of diagrammatic form by which query can be specified through
manipulating the diagram. GUI utilizes both menu and form in several cases. Schema Diagram's
specific parts are selected using devices used by GUI.
Example
You liked a video on Instagram by tapping with your finger, and the color changes to red. The
visual graphic gets changed due to user action.
A natural language interface contains its unique schema more like the high−level conceptual
schema. It also has a directory of important words. It generates a query based on the
interpretation of important words in the input by the user and if the interpretation is successful,
then it displays the result to the user.
Example
A user googled the fastest car in India, and now the natural language interface will look for the
important words i. e. fastest, car, India, and show the result accordingly.
The users query the interface with speech and get the answer in speech. The input is detected
using predefined words and conversions are done into speech to provide the output. Nowadays, it
has become the most common type of interface.
Example
One to One: One to One cardinality is represented by a 1:1 symbol. An entity of entity-set A can
be associated with at most one entity of entity-set B and an entity in entity-set B can be
associated with at most one entity of entity-set A.
Example:
One to Many: One to Many cardinalities is represented by a 1:M symbol. An entity of entity-set
A can be associated with any number of entities of entity-set B and an entity in entity-set B can
be associated with at most one entity of entity-set A.
Example:
Many to One: Many to One cardinality is represented by a M:1 symbol. An entity of entity-set
A can be associated with at most one entity of entity-set B and an entity in entity-set B can be
associated with any number of entities of entity-set A.
Example:
Example:
KEYS:
In a DBMS key is an attribute or set of an attribute which helps you to identify a row(tuple) in a
relation(table). They allow you to find the relation between two tables. Keys help you uniquely
identify a row in a table by a combination of one or more columns in that table. Keys play an
important role in the relational database. It is used to uniquely identify any record or row of data
from the table. It is also used to establish and identify relationships between tables .
Types of keys:
Primary Key
Candidate Key
Super Key
Foreign Key
Alternate Key
Unique Key
Primary Key
A primary is a column in a table that uniquely identifies tuples (rows) in that table. A column in
a table which helps us to uniquely identifies every row in that table is called a primary key. A
Primary key is selected from a set of candidate keys. This is done by database admin or database
designer. We can say that either {Emp_SSN} or {Emp_Number} can be chosen as a primary key
for the table Employee.
Rules for defining Primary key:
Candidate key: -
A combination of one or more field whose value uniquely identifies a record in a table, that is no
two record in a table can have the same value.
As I mentioned in the beginning, a candidate key is a minimal super key with no redundant
attributes. The following two set of super keys are chosen from the above sets as there are no
redundant attributes in these sets.
{Emp_SSN}
{Emp_Number}
Only these two sets are candidate keys as all other sets are having redundant attributes that are
not necessary for unique identification.
Super key: -
Super key is an attribute set that can uniquely identify a tuple. A super key is a superset of a
candidate key. A super key is a set of one or more attributes (columns), which can uniquely
identify a row in a table.
Adding zero or more attributes to the candidate key generates the super key.
A candidate key is a super key but vice versa is not true.
Super Key values may also be NULL.
All of the following sets of super key are able to uniquely identify a row of the employee table.
{Emp_SSN}
{Emp_Number}
{Emp_SSN, Emp_Number}
{Emp_SSN, Emp_Name}
{Emp_SSN, Emp_Number, Emp_Name}
{Emp_Number, Emp_Name}
Foreign key:-
Foreign keys are the column of the table used to point to the primary key of another table.
Foreign keys is a column that creates a relationship between two tables. The purpose of foreign
keys is to maintain data integrity and allow navigation between two different instances of an
entity. It acts as a cross-reference between two tables as it references the primary key of another
table.
Alternate key: -
The candidate key other than the primary key is called an alternate key.
Unique Key:-
A unique key is an attribute in the table which is unique. It can be used to identify a row,
unique key is just like a primary key but only difference is that it can accept NULL
values, whereas the primary key does not.
Rules: -
The Entity set becomes the table and the attributes of the Entity set becomes the table attributes.
The key attribute of the entity set becomes the primary key of the table.
Employee
If there is any composite attribute divided into simple attributes and has to be included.
Entity set with multi-valued attributes will require two tables in the relational model.
Emp-Id Name Age Salary
Emp-Id Dept
While converting the relationship set to a table, the primary attributes of the two-entity set
becomes the table attributes and if the relationship set has any attribute that also becomes the
attribute of the table.