0% found this document useful (0 votes)
13 views25 pages

Dbms Notes Unit 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
13 views25 pages

Dbms Notes Unit 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 25

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.

Database Management System: DBMS is the combination of two words.


Database + Management System = DBMS

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.

Application of DBMS:-There are various applications of DBMS which are given


below.

1. Banking: - For maintaining customer information, accounts, loans and banking


transactions.
2. Universities:- For maintaining students records, course registration etc
3. Railway Reservation: - For checking the availability of reservation in different trains,
tickets etc.
4. Airlines: - For reservation and schedule information.
5. Telecommunication:- for keeping records of calls made ,generating monthly bills,etc

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 implementation cost is high compared to the file system


 Complexity: Database systems are complex to understand
 Performance: Database systems are generic, making them suitable for various applications.
However this feature affect their performance for some applications
Characteristics of Database Management System
 DBMS supports ACID properties.

 It stores any kind of Data.

 Automatically backup the data and supports recovery.

 It maintains Data Integrity.

 It controls Data Redundancy to a great extent.

 It enables the sharing of data with much ease.

 It supports Data Security and prevents restriction of unauthorized access.

DBMS vs. Flat File or Advantages of DBMS over file processing system

DBMS Flat File Management System

Multi-user access. It does not support multi-user access.

Design to fulfill the need for small and large businesses. It is only limited to smaller DBMS system.

Remove redundancy and Integrity. Redundancy and Integrity issues.

The problem of isolation is not found. Isolation problem is found.

Easy to implement complicated transactions. No support for complicated transactions.

Atomicity problems are not found. Atomicity problems are found.

Security of data in DBMS. Security of data is not good.

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.

Types of DBMS Architecture

There are three types of DBMS architecture:

1. Single tier architecture


2. Two tier architecture
3. Three tier architecture

. 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.

2-tier DBMS Architecture


2-tier DBMS architecture includes an Application layer between the user and the DBMS, which
is responsible to communicate the user's request to the database management system and then
send the response from the DBMS to the user.
An application interface known as ODBC (Open Database Connectivity) provides an API that
allows client side program to call the DBMS. Most DBMS vendors provide ODBC drivers for
their DBMS
3-tier DBMS Architecture
3-tier DBMS architecture is the most commonly used architecture for web applications. It is an
extension of the 2-tier architecture. In 3-tier architecture, an additional Presentation or GUI
Layer is added, which provides a graphical user interface for the End user to interact with the
DBMS. It is more appropriate for large application.

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.

In relational model 3 basic operations are used.


Selection
Projection
Join

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

There are two types of entity:

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

Strong entity weak entity

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)

Recursive Relationship:-When an Entity is related with itself it is known as Recursive Relationship.

Ternary Relationship:-Relationship of degree three is called Ternary relationship.

ER Diagrams Symbols, And Notations


EER Model: -Enhanced Entity Relationship Model contains all the features of the Entity
Relationship model. In addition to all that, it also contains features of Subclasses, Super classes,
Inheritance, Generalization, Specialization, Aggregration.

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.

Specialization is opposite to Generalization. It is a top-down approach in which one higher level


entity can be broken down into two lower level entities. In specialization, a higher level entity
may not have any lower-level entity sets, it's possible.
Aggregation is a process when relation between two entities is treated as a single entity.

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.

The major differences between schema and instance are as follows:

Database Schema Database Instance

It is the definition of the database, or it is defined as It is a snapshot of a database at a specific


the description of the database. moment.

It rarely changes. It changes frequently.

The value of the variable in a program at a


This corresponds to the variable declaration of a
point in time corresponds to an instance of
programming language.
the database schema.

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.

Data in instances can be changed using


Schema is same for whole database.
addition, deletion, updation.

It does not change very frequently. It changes very frequently


Data Independence:-The ability to modify a schema definition in one level without
affecting a schema definition in next higher level is called Data Independence. Data
independence is one of the most advantages of DBMS.

It is two type: -

1. Physical data independence


2. Logical data independence
1. Physical data independence:-The ability to modify a schema definition in physical
level without affecting a schema definition in conceptual level is called Physical data
independence.
2. Logical data independence:- The ability to modify a schema definition in logical
level without affecting a schema definition in external level is called logical data
independence

Database Languages in DBMS


Database languages are used to read, store and update the data in the database. Specific
languages are used to perform various operations of the database.

Types of Database Languages


1. DDL
2. DML
3. DCL
4. TCL
5. DQL

DDL(Data Definition Language)

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.

The commands used in DDL are:

Create: It is used to create a database or table.

Alter: It is used to make a change in the structure of a database.

Drop: It is used to completely delete a table from the database


Rename: It is used to rename a table.

Truncate: It is used to delete the entities inside the table while holding the structure of the table.

DML (Data Manipulation Language)

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.

The commands used in DML are:

Insert: It allows users to insert data into the database or tables.

Update: It is used to update or modify the existing data in database tables.

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(Data Control Language)

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.

The commands used in DCL are:

Grant: It is used to give access to security privileges to a specific database user.

Revoke: It is used to revoke the access from the user that is being granted by the grant
command.

TCL(Transaction Control Language)


It can be grouped into a logical transaction and is used to run the changes made by the DML
command in the database.

Commit: Transaction on the database is saved using Commit.

Rollback: The database gets restored to the original since the last commit.

DQL (Data Query Language)


DQL statements are used for performing queries on the data within schema objects.
DQL Command
Select : Used to retrieve data from the database

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.

Menu−based User Interface

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.

Natural Language Interface

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.

Speech Input and Output

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

OK Google, Siri on Apple, and Alexa is used in the form of speech.

Mapping Constraints: In a Database Management System, Mapping constraints are


implemented to determine the relationships between the entities. Mapping Constraints are also
known as the ‘Cardinality Ratio.’ In simple words we can say that Mapping
constraints defines how many entities can be related to another entity to a relationship. It is very
much useful for identifying relationships that are involved with more than one relationship.

There are four types of Cardinality Mapping in Database Management Systems:


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. 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:

Many to Many: Many to Many cardinalities is represented by a M: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 any number of entities of entity-set A.

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

Emp-SSN Emp-Num Emp-Name


123456789 226 Steve

999999321 227 Ajeet

888997212 228 Chaitanya

777778888 229 Robert

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:

 Two rows can't have the same primary key value


 It must for every row to have a unique value.
 The primary key field cannot be null.
 The value in a primary key column can never be modified or updated if any foreign key
refers to that 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.

Properties of Candidate key:

 It must contain unique values


 Candidate key may have multiple attributes
 Must not contain null values
 It should contain minimum fields to ensure uniqueness
 Uniquely identify each record in a table

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.

Properties of Super Key

 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.

Reduction of ER diagram to Table: -


The database can be represented using the notations, and these notations can be reduced to a
collection of tables.

Rules: -

Entity set with Simple attributes

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

Emp-Id Name Age Salary

Table schema: Employee (Emp-Id, Name, Age, Salary)

Entity Set with Composite Attributes

If there is any composite attribute divided into simple attributes and has to be included.

Emp-Id First_N Last_N Age Salary

Table schema: Employee (Emp-Id, First_N, Last_N, Age, Salary)

Entity Set with Multi Valued Attributes

Entity set with multi-valued attributes will require two tables in the relational model.
Emp-Id Name Age Salary

Emp-Id Dept

Derived attributes are not considered in the table.

Relationship Set to Table conversion

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.

Emp_Id Dept_Id Experience

You might also like