0% found this document useful (0 votes)
23 views

Nep dbms-1

Uploaded by

Heena Kousar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Nep dbms-1

Uploaded by

Heena Kousar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 267

DBMS

DATBASE
MANAGEMENT
SYSTEM
Introduction
• Data: It is the unorganised facts which need to be
compiled to form meaningful information
• Information: Once the data is processed and made
into a structured context, it is called information.
• Database :
A database is a collection of organized data which
can easily be created, updated, accessed, and
managed. Records are kept maintained in tables or
objects. A tuple (row) represents a single entry in a
table. DBMS manipulates data from the database in
the form of queries given by the user.
DBMS stands for Database Management
System. We can break it like this DBMS =
Database + Management System.
Database is a collection of data and
Management System is a set of programs
to store and retrieve those data.
Based on this we can define DBMS like
this: DBMS is a collection of inter-related
data and set of programs to store & access
those data in an easy and effective manner.
Definition of DBMS

DBMS stands for the database management system. It is a software


system designed for managing and organizing the data in a planned
manner. It is used for storing, fetching data, and running queries on
data.
A database management system is an intermediate software between
the end-user and the database that allows the manipulation and storage
of data.
OR
• A collection of information which is managed such
that it can be updated and easily accessed is called
a database. A software package which can be used
to manipulate, validate and retrieve this database is
called a Database Management System.
• For example, Airlines use this software package to
book tickets and confirm reservations which are
then managed to keep a track of the schedule.
The characteristics of Database approach are
as follows:
1. Data Organization and self-describing nature of
database system
2. Integrity of Data
3. Data Independence
4. Data Security
5. Data consistency with centralised management
system
6. Sharing of data
7. Query and report flexibility
8. Scalibility and performance of the database
1. Data Organization and self-describing nature of
database system
• The database approach stores data in a structured and
organized manner.
• It uses the database management system to create, design
and maintain data logically and consistently.
• The database approach also comes with the characteristic
of a self-describing nature of a database system.
• That is, the database not only contains the data and the
tables but a thorough description of the entire database in
the form of metadata.
• For example the database of any ecommerce company
contains data of its customers and vendors in the form of
tables which are linked with foreign keys.
2. Integrity of Data
• Data integrity means the accuracy and consistency of
data over its entire lifecycle.
• The data integrity through the use of various methods
such as data validation, data normalization, the use of
queries, and referential integrity.
• These techniques ensure that data is accurate,
consistent, and free from errors or duplicates.
• Data Integrity prevents human errors, transfer errors
and data verification errors.
• For example the database of any ecommerce company
maintains the accuracy and consistency of data inserted
in tables because of the property of data Integrity.
3. Data Independence
• Data independence is another characteristic of the database
approach.
• Data independence means that the database structure and
design are independent of the application programs that
use it.
• Any modifications to the database structure will not affect
the application programs and vice versa.
• This property makes modifying and updating the database
easier without disrupting the application software's
functioning.
• For example in the database of an online food ordering
company, the database can be modified without affecting
the consumer side of the website because of the
characteristic of data independence.
• There are two types of data independence in the
database approach:
• Physical data independence: With Physical data
independence, it is possible to switch the storage
device of the database without resulting in any
impact on the logical level.
• Logical data independence: With Logical data
independence, we can change the logical structure
of the database without the need to rewrite the
application programs.
4. Data Security
• A database management system provides various
security measures such as authentication, authorization,
and encryption to protect data from unauthorized access.
• This makes it easier to identify the user and control who
has access to data and what they can do with it, thus
making the data more secure.
• The database approach also provides a good backup and
data recovery feature.
• This is achieved with techniques like database backups,
replication, and transaction logs.
• For example the data of customers in the database of any
ecommerce company has a high backup facility and the
data is securely stored in the database.
5. Data consistency with centralized
management system
• All the data in the database approach is stored in a
single centralized location rather than in separate files.
• This characteristic of centralized data management
contributes to data consistency by storing data in a
standardized format.
• Also, the database is updated and manipulated from a
single location.
• The database stored at a centralized computer system
can be accessed through an internet connection.
• Thus coordination of data becomes a lot easier and
simpler here.
6. Sharing of data
• Here, data can be shared among multiple users and
applications simultaneously.
• It also reduces the need to store duplicate data in various
locations, which can lead to inconsistencies and errors.
• Data sharing with multiple users can occur with techniques
like concurrency and locking control.
• This enhances collaboration and efficiency.
• During locking locks specific data from being accessed by
any other user while it is being updated, concurrency control
handles the access to data by numerous users by applying the
strategy of time stamping and optimistic concurrency control.
• For example, in an online food ordering website multiple
users can add food to their cart and order food at the same
time allowing multiple users to access the same database.
7 Query and report flexibility
• The database approach also offers users query and report
flexibility, allowing them to fetch and analyze data
efficiently.
• Queries can be used to perform CRUD operations like
creating, reading, updating, and deleting actions or filtering
data according to the requirement.
• The flexibility of report means the database approach
offers tools to generate customized interactive reports in
formats like graphs, tables, and charts that analyze data
more easily.
• For example, you can read the data of employees with
salary greater than 10000 from a employees table using the
query:
8. Scalibility and performance of the
database
• Scalability refers to handling increasing or decreasing
amounts of data without affecting system performance.
• That is, the size of the database can be modified as per
the need.
• Techniques used by the database approach to provide
scalability are:-
1.) Indexing: Indexing is used to improve the searching
time of a query in a database. Usually, when a database is
scaled, it is divided into several partitions. With indexing,
each division can quickly fetch the data needed by it.
2.) Partitioning: This technique is used to divide a
more extensive database into smaller sections, also
known as partitions. Partitioning helps manage the
database traffic by distributing the load among
multiple partitions.

3.) Clustering: It is another technique used in


scaling where smaller partitions of data are clustered
together to improve the performance of the
database.
Database Users
Users may be divided into
• Those who actually use and control the database
content and those who design, develop and
maintain database applications called “Actors on
the scene”.
• Those who design and develop the DBMS
software and related tools, and the computer
systems operators called “Workers behind the
scene”.
Actors on the Scene
Here we will consider people who may be
called “Actors on the Scene”, whose jobs
involve the day-to-day use of a large database.
1. Database Administrators
2. Database Designers
3. End Users
4. System Analysts and Application
Programmers (Software Engineers)
1. Database Administrators
• Administrating the primary (database) and secondary (DBMS
and related software) is the responsibility of the database
administrator (DBA).
• Database Administrator (DBA) is the person who is
responsible for establishing the needs and monitoring the users
and security.
Responsibilities of a database administrator
• Carry out capacity planning
• Should have good communication with technical, operational
staff to ensure the security and integrity of the database.
• Have to write database documents including data standards.
• Must ensure whether storage and archiving procedures (selects
data from a source (one or more tables in a database) and
copies that data to a destination) work properly.
2. Database Designers
• Database Designers are responsible for identifying
the data to be stored in the database and for choosing
appropriate structures to represent and store this data.
• Database designers typically interact with each
potential group and user and develop a view of the
database that meets the data and processing
requirements of these groups.
• These professionals design and create the database
schema, tables, views, and queries. They work
closely with the DBAs to ensure that the database is
designed and implemented to meet the needs of the
organization.
3. End Users
End users are the people whose jobs require access to the
database for querying, updating, and generating reports; the
database primarily exists for their use. There are several
categories of end users:
– Casual end user: Occasionally access the database,
but they may need different information each time.
They are typically middle-or high-level managers.
– Naive or Parametric end user: Their main job
function revolves around constantly querying and
updating the database, using standard types of queries
and updates that have been carefully programmed and
tested. Bank tellers, Reservation Clerks for airlines,
hotels, etc are the example of Naive end users.
– Sophisticated end users: Sophisticated end
users include engineers, scientists, business
analysts, and others who thoroughly familiarize
themselves with the facilities of the DBMS so
as to implement their applications to meet their
complex requirements.
– Stand-alone users: They maintain the personal
databases by using ready-made program
packages that provide an easy-to-use menu or
graphics-based interfaces.
4. System Analysts and Application Programmers
(Software Engineers)
• System analysts determines the requirements of end
users, especially naive and parametric end users, and
develop specifications for canned transactions
(standard types of queries and updates which are
frequently used by Naive end users to constantly
querying and updating )that meet these requirements.
• Application programmers implement these
specifications as programs; then they test, debug,
document, and maintain these canned transactions.
Such analysts and programmers are called Software
Engineers.
Workers behind the Scene
1. DBMS system designers and implementers: design and
implement the DBMS modules and interfaces as a software
package. A DBMS is a very complex software system that
consists of many components, or modules, including
modules for implementing the catalog, query language
processing, interface processing, accessing and buffering
data, controlling concurrency, and handling data recovery
and security.
2. Tool developers: design and implement tools that facilitate
database modeling and design, database system design and
improved performance.
3. Operators and maintenance personnel (system
administration personnel): responsible for the actual
running and maintenance of the hardware and software
Advantages of using database approach
1. Redundancy problem can be solved.
2. Has a very high security level.
3. Presence of Data integrity.
4. Support multiple users.
5. Avoidance of inconsistency.
6. Shared data
7. Enforcement of standards
8. Any unauthorized access is restricted
9. Provide backup of data
10.Tunability
1. Redundancy problem can be solved.
• In the File System, duplicate data is created in
many places because all the programs have their
own files which create data redundancy resulting
in wastage of memory.
• In DBMS, all the files are integrated in a single
database. So there is no chance of duplicate data.
• For example: A student record in a library or
examination can contain duplicate values, but
when they are converted into a single database, all
the duplicate values are removed.
2. Has a very high security level.
• Data security level is high by protecting your
precious data from unauthorized access.
• Only authorized users should have the grant to
access the database.
3. Presence of Data integrity.
• Data integrity makes unification(combining things)
of so many files into a single file.
• DBMS allows data integrity which makes it easy
to decrease data duplicity Data integration and
reduces redundancy.
4. Support multiple users.
DBMS allows multiple users to access the same
database at a time without any conflicts.
5. Avoidance of inconsistency.
• DBMS controls data redundancy and also controls
data consistency.
• Data consistency is nothing but if you want to
update data in any files then all the files should not
be updated again.
• In DBMS, data is stored in a single database so
data becomes more consistent in comparison to
file processing systems.
6. Shared data
• Data can be shared between authorized users of the
database in DBMS.
• All the users have their own right to access the
database.
• Admin has complete access to the database.
• He has a right to assign users to access the database.
7. Enforcement of standards
• As DBMS have central control of the database.
• So, a DBA can ensure that all the applications follow
some standards such as format of data, document
standards etc.
• These standards help in data migrations or in
8. Any unauthorized access is restricted
Unauthorized persons are not allowed to access the
database because of security.
9. Provide backup of data
• Data loss is a big problem for all the organizations.
• In the file system users have to back up the files in
regular intervals which lead to waste of time and
resources.
• DBMS solves this problem of taking backup
automatically and recovery of the database.
10. Tunability
• Tuning means adjusting something to get a better
performance.
• Same in the case of DBMS, as it provides
tunability to improve performance.
• DBA adjusts databases to get effective results.
Disadvantages of DBMS
1. Complexity
2. Size
3. Performance
4. Higher impact of a failure
5. Cost of DBMS
1. Complexity
• The provision of the functionality that is expected
of a good DBMS makes the DBMS an extremely
complex piece of software.
• Database designers, developers, database
administrators and end-users must understand this
functionality to take full advantage of it.
• Failure to understand the system can lead to bad
design decisions, which leads to a serious
consequence for an organization.
2. Size
The functionality of DBMS makes use of a large
piece of software which occupies megabytes of disk
space.
3. Performance
Performance may not run as fast as desired.
4. Higher impact of a failure
The centralization of resources increases the
vulnerability(attacked) of the system because all
users and applications rely on the availability of
DBMS, the failure of any component can bring
operation to halt.
5. Cost of DBMS
• The cost of DBMS varies significantly depending
on the environment and functionality provided.
• There is also the recurrent annual maintenance
cost.
 History of Database Systems
 1950s and early 1960s:
 Data processing using magnetic tapes for storage
Tapes provided only sequential access
 Punched cards for input
 Late 1960s and 1970s:
 Hard disks allowed direct access to data
 Network and hierarchical data models in widespread use
 E.F Codd defines the relational data model
Would win the ACM Turing Award for this work
IBM Research begins System R prototype
UC Berkeley begins Ingres prototype
 High-performance (for the era) transaction processing
 1980s:
 Research relational prototypes evolve into commercial systems
SQL becomes industrial standard
 Parallel and distributed database systems
 Object-oriented database systems
 1990s:
 Large decision support and data-mining applications
 Large multi-terabyte data warehouses
 Emergence of Web commerce
 Early 2000s:
 XML and XQuery standards
 Automated database administration
 Later 2000s:
 Giant data storage systems
Google BigTable, Yahoo PNuts, Amazon, ..
When not to use a DBMS
 Main inhibitors (costs) of using a DBMS:
High initial investment and possible need for additional
hardware.
Overhead for providing generality, security,
concurrency control, recovery and integrity functions.
 When a DBMS may be unnecessary:
If the database and applications are simple, well
defined and not expected to change.
If access to data by multiple users is not required.
 When a DBMS may be infeasible:
In embedded systems where a general purpose DBMS
may not fit in available storage
 When no DBMS may suffice:
If there are stringent real-time requirements that
may not be met because of DBMS overhead
(e.g., telephone switching systems)
If the database system is not able to handle the
complexity of data because of modeling
limitations (e.g., in complex genome and protein
databases)
If the database users need special operations not
supported by the DBMS (e.g., GIS and location
based services).
UNIT 2
Data models
• Data models define how the logical structure of a database
is modeled.
• Data models define how data is connected to each other
and how they are processed and stored inside the system.
Or
A set of concepts to describe the structure of a database,
the operations for manipulating these structures, and
certain constraints that the database.
• Data Model Structure and Constraints:
 Constructs are used to define the database structure
 Constructs typically include elements (and their data types)
as well as groups of elements (e.g. entity, record, table), and
relationships among such groups.
Constraints specify some restrictions on valid
data; these constraints must be enforced at all
times
• Data Model Operations:
– These operations are used for specifying database
retrievals and updates by referring to the constructs of
the data model.
– Operations on the data model may include basic model
operations (e.g. generic insert, delete, update) and
user-defined operations (e.g. compute_student_gpa,
update_inventory)
Categories of Data Models
• Conceptual (high-level, semantic) data models:
– Provide concepts that are close to the way many users perceive
data.
– (Also called entity-based or object-based data models.)
• Physical (low-level, internal) data models:
– Provide concepts that describe details of how data is stored in
the computer.
– These are usually specified in an ad-hoc manner through
DBMS design and administration manuals
• Implementation (representational) data models:
– Provide concepts that fall between the above two, used by
many commercial DBMS implementations (e.g. relational data
models used in many commercial systems).
• Self-Describing Data Models:
– Combine the description of data with the data values. Examples
include XML, key-value stores and some NOSQL systems.
Schemas
• Database Schema:
– The description of a database.
– Includes descriptions of the database structure, data
types, and the constraints on the database.
• Schema Diagram:
– An illustrative display of (most aspects of) a database
schema.
• Schema Construct:
– A component of the schema or an object within the
schema, e.g., STUDENT, COURSE.

Schema is of three types: Physical schema, logical


schema and view schema.
Example of a Database Schema
• Database State or instances:
– The actual data stored in a database at a particular moment
in time.
– This includes the collection of all the data in the database.
– Also called database instance (or current state or occurrence
or snapshot).
– The term instance is also applied to individual database
components, e.g. record instance, table instance, entity
instance
or
• Instance or extension or database state is a collection of
information that stored in a database at a particular moment is
called an instance of the database.
• The Database instance refers to the information stored in the
database at a given point of time.
• Database State:
– Refers to the content of a database at a moment
in time.
• Initial Database State:
– Refers to the database state when it is initially
loaded into the system.
• Valid State:
– A state that satisfies the structure and constraints
of the database.
Database Schema vs. Database State
• Distinction
– The database schema changes very infrequently.
– The database state changes every time the database is
updated.

• Schema is also called intension.


• State is also called extension.
Example of a database state
Three-Schema Architecture or View of data
• Three levels Architecture Of DBMS:
1. External level
2. Conceptual level
3. Internal level
1. External level
• It is also called view level.
• The reason this level is called “view” is that several users can
view their desired data from this level which is internally
fetched from the database with the help of conceptual and
internal level mapping.
• This level includes a no. of user views or external schemas.
• This level is closest to the user.
• External view describes the segment of the database that is
required for a particular user group and hides the rest of the
database from that user group.
2. Conceptual level
• Conceptual level describes the structure of
the whole database for a group of users.
• It is also called the data model.
• Conceptual schema is a representation of the
entire content of the database.
• This schema contains all the information to
build relevant external records.
• It hides the internal details of physical
storage.
3. Internal Level
• The internal level has an internal schema that
describes the physical storage structure of the
database.
• The internal schema is also known as a
physical schema.
• It uses the physical data model.
• It is used to define how the data will be
stored in a block.
Data Independence
It is defined as the capacity to change the schema at one level of
a database system without having to change the schema at the
next higher level.
There are two types of data independence:
a) Logical data independence :
• Is the capacity to change the conceptual schema without having
to change external schemas or application programs.
• We may change the conceptual schema to expand the database
(by adding a record type or data item), to change constraints, or
to reduce the database (by removing a record type or data item).
• External schemas that refer only to the remaining data should
not be affected.
• Only the view definition and the mappings need to be changed
in a DBMS that supports logical data independence.
b) Physical data independence:
• Is the capacity to change the internal schema
without having to change the conceptual schema.
• Hence, the external schemas need not be changed
as well.
• Changes to the internal schema may be needed
because some physical files were reorganized— by
creating additional access structures—to improve
the performance of retrieval or update.
Logical Data independence Physical Data independence
is the capacity to change the is the capacity to change the
conceptual schema without having internal schema without having to
to change external schemas or change the conceptual schema.
application programs.

it is difficult to achieve logical it is easier to achieve logical data


data independence. independence.
We may change the conceptual Changes to the internal schema
schema to expand the database may be needed because some
(by adding a record type or data physical files were reorganized—
item), to change constraints, or to by creating additional access
reduce the database (by removing structures—to improve the
a record type or data item). performance of retrieval or
update.
Database Languages or SQL Commands -
DDL, DQL, DML, DCL and TCL
SQL Commands
• are like instructions to a table.
• It is used to interact with the database with some
operations.
• It is also used to perform specific tasks, functions,
and queries of data.
• SQL can perform various tasks like creating a
table, adding data to tables, dropping the table,
modifying the table, set permission for users.
These SQL commands are mainly
categorized into five categories:
1. DDL – Data Definition Language
2. DQL – Data Query Language
3. DML – Data Manipulation Language
4. DCL – Data Control Language
5. TCL – Transaction Control Language
DDL (Data Definition Language)
• The DDL stands for
Data Definition Language, Which is used for
define the database’s internal structure and
Pattern of the Database.
• Basically, The DDL is used for creating
tables, indexes, constraints, and schema in
the Database.
• By using DDL statements we can able to
create the architecture of the required
database.
List of DDL commands:
• Create It is used to create objects in the database
• Alter It is used for change or alter the structure of
the database objects
• Drop It is used for delete objects from the database
• Truncate It is used for remove all records from a
table
• Rename It is used to rename the object in database
• Comment It is used for comment on the data
dictionary.
Create
• It is one the command in DDL which is used
for creating objects in database means
creating Tables, Users, Triggers, functions
and other objects.
• Here I will show how to create a table by
using create command from DDL.
Syntax:
CREATE TABLE Students (column1 INT,
column2 VARCHAR(50), column3 INT);
Example:
Alter
• It is one the command in DDL which is used
for change or alter the structure of the
database or table.
• I already created students table with some
columns you can see in the above image.
• Now by using Alter command I add new
column that weight to the students table.
Syntax:
ALTER TABLE Students ADD column_name;
Example:
Drop
• This Drop command is used for delete objects
from the database.
• In this example I drop the students table
Syntax:
• DROP Table Table_name;
Example:
Truncate
• Truncate command is used for remove all records
from a table.
• Now I remove rows from the Student table.
Syntax:
• TRUNCATE TABLE table_name;
Example:
Rename
• It is used to rename the object in database.
• Now I rename the table from students to
ClassMembers.
• Below I provide the example for better
understanding.
Syntax:
ALTER TABLE Old_Table_Name RENAME TO
New_Table_Name;
Example:
Comment
• It is used for comment on the data dictionary.
• We have two different comments namely Single
line comment and Multi-line comments.
Single Line
• -- This is a single-line comment
Multi-line comment
• /*
This is a
multi-line comment
*/
DCL (Data Control Language)
• The DCL stands for Data Control Language means
these commands are used to retrieve the saved data
from database.
• And one more thing is the DCL execution is
Transactional that means It have roll back
parameters.
• we have two tasks under the Data Control
Language below I listed them
• Grant It is used for give user access to the
database
• Revoke It is used for to take back the access or
permissions from the user
Grant
• Basically The grant command is used for provide
database access to the new user.
• Here I create one user then I give the access to the
database.
Syntax:
• GRANT privileges
ON object
TO user_or_role [WITH GRANT OPTION];
Example:
• GRANT SELECT, INSERT ON students TO user;
Revoke
• The Revoke command is used to to take back
database access from the user. Now I provide
the example in the below
Syntax:
• REVOKE privileges ON object FROM
user_or_role;
Example:
• REVOKE ALL PRIVILEGES ON students
FROM user;
DML (Data Manipulation Language)
• The Data Manipulation Language is used
to Manipulate the data in the database by
using different commands.
• In this category we can able to perform
Insert new data into Table, Update
existing data in the Table, Delete Data
from the Table and other functions we
can perform on data by using these DML
commands
• Select It is used for select data from the Table
based on the requirements
• Insert It is sued for Inserting data into existing
table
• Update It is used for update data in the Table
based on the requirement
• Delete It is used for delete data from the Table
• Merge It is used for upsert operations
• Call It is used for call a structured query language
or Java sub program
• Lock Table It have ability to control the
concurrency
Select
• The Select command is used for select required
data based on conditions from a existing Table.
• Here I select all data from the ClassMembers
Table.
Syntax:
• SELECT * FROM Table_Name
• Example:
Insert
• The Insert command is used for inserting new data
into Table.
• Now I insert a new data into ClassMembers
Table.
• Below I provide the example.
Syntax:
• INSERT INTO Table_Name (Column 1, Column
2, Column 3, Column 4) VALUES (Value 1, Value
2,Value 3, Value 4);
Example:

Update
• The Update command is used for update
information In the Table.
• Now I will update name John Doe to Roman in
the ClassMemebers Table.
• Below I provide that Example you can update
any row or columns data.
Syntax:
• UPDATE Table_Name SET Name = 'New_Value'
WHERE Name = 'Ola_Value';
• Example:
Delete:
• The Delete command is used for delete data from
the Table. Here I delete Student Id with 2 from the
ClassMembers. Below I provide the Example for
your reference.
Syntax:
• DELETE FROM Table_Name WHERE Column =
Value;
Example:
Merge
• The Merge command is used for perform upsert
operation means It inserts rows that doesn’t exist and
updates rows that do.
Example:
MERGE INTO target_table AS target
USING source_table AS source
ON (target.id = source.id)
WHEN MATCHED THEN
UPDATE SET target.name = source.name
WHEN NOT MATCHED THEN
INSERT (id, name) VALUES (source.id,
source.name);
CALL
• The Call command is used for call the user defined
functions
Example:
CALL user_defined_function(parameter 1, parameter 2);
LOCK TABLE
• The lock table command is used for lock the table for
preventing access from the others for same Table
Syntax:
• LOCK TABLE your_table IN EXCLUSIVE MODE;
Example:
• LOCK TABLE ClassMembers IN EXCLUSIVE
MODE;
TCL ( Transaction Control Language )
• The TCL full form is Transaction Control Language
commands are used to run the changes made by the DML
commands And one more thing is TCL can be grouped into
a logical transaction.
• And We have two different commands in this category
below I listed them for reference.
Commit
It is used for save the transaction on the Database.
• And these very useful in banking sectors.
Rollback
• It is used for restore the database to original state from last
commit.
• This command also plays an important role in Banking
Sectors.
Commit
• The Commit command is used for save the
transaction in the database and changes are made
by the DML statements.
• Now I will provide the example below Here I used
ClassMembers Table.
• Here I inserted a new data into Table then I
commit It.
Syntax:
• Database Operation
Commit
Example:

ROLLBACK
• Rollback command is used for restore the database
to original state from last commit.
• Now I delete one row from the Table then again
rollback the previous database state.
Syntax:
• ROLLBACK;
Example:
DQL (Data Query Language)
• DQL statements are used for performing queries on
the data within schema objects.
• The purpose of the DQL Command is to get some
schema relation based on the query passed to it.
• We can define DQL as follows it is a component of
SQL statement that allows getting data from the
database and imposing order upon it.
• It includes the SELECT statement.
• This command allows getting the data out of the
database to perform operations with it.
List of DQL:
• SELECT: It is used to retrieve data from the database.
Interfaces
• 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.
Command-Line Interface (CLI)
• The earliest and most fundamental form of DBMS
interface is the command-line interface (CLI).
• Through the use of a command prompt, users may
communicate with the database by inputting
commands.
• Users can only access and modify the database
using particular commands and syntax.
• Today, programmers and database administrators
are the main users of CLI.
Graphical User Interface (GUI)
• The most prevalent kind of DBMS interface used
nowadays is the graphical user interface (GUI).
• Users may interact with the database using the user-
friendly interface's graphical menus and icons.
• GUIs are user-friendly and need little to no
programming experience.
• They are mostly utilized by non-programmers who are
end users.
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.
Web-Based Interface
• Users can access the database using a browser
using the web-based interface.
• Users can use online forms, buttons, and other
graphical components to interact with the database
using a web browser.
• Because they can be accessed from any location
with an internet connection, web-based interfaces
are common.
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.
Forms-Based Interface
• Using the forms-based interface, users may enter
data into the database using a graphical user
interface.
• Users can complete pre-made forms that provide
fields for particular categories of information, such
as name, address, and phone number.
• Applications for data entry frequently employ
forms-based interfaces.
Example
• Student entering his roll. no, branch in the form to
get the grade card.
Menu-Based Interface
• Users have access to a number of predefined
menus and choices when using the menu-based
interface to interact with the database.
• Users can choose the menu choice that reflects the
intended action, such as adding or removing data,
from the available options.
• 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.
Database System Environment or
Components of DBMS Environment
The term database system refers to an organization
of components that define and regulate the
collection, storage, management, and use of data
within a database environment.
These are:
• Hardware
• Software
• People
• Procedures
• Data
1] Hardware-
• It identifies all the system’s physical devices.

• The database system’s main and most easily


identified hardware component is the computer,
which might be a microprocessor, a minicomputer,
or a mainframe computer.
• It also include peripherals like keyboard, mice,
modems, printers, etc.
2]. Software
• This is the set of programs used to control and manage the
overall database.
• This includes the DBMS software itself, the operating system,
the network software being used to share the data among
users, and the application program used to access data in the
DBMS.
• The DBMS provides us with an easy-to-use interface to store,
access and update data.
• This software component is capable of understanding the
database access language and converts it into actual database
commands to execute or run them on the database.
• The software in DBMS environment includes operating
system, database management system, application programs,
support utility programs.
3]. Data-
• The main task of DBMS is to process the data.
• Here database are defined, constructed, and then data is
stored, retrieved, and updated to and form the database.
• It is the most important component of the database
management system.
• The database contains both the metadata(data about data)
and the actual(operational) data.
• DBMS exists to collect, store, process and access data, the
most important component. In a typical database , the user
saved data is present and meta data is stored.
• For example- when I store my name in a database, the DBMS
will store when the name was stored in the database, what is
the size of the name, is it stored as related data to some other
data, or is it independent, all this information is Metadata.
Centralized DBMS Architecture
• Architectures used mainframe computers to
provide the main processing for all functions of the
system, including user application programs and
user interface programs, as well as all the DBMS
functionality.
• As prices of hardware declined, most users
replaced their terminals with personal computers
(PCs) and workstations.
• At first, database systems used these computers in
the same way as they had used display terminals,
so that the DBMS itself was still a centralized
DBMS in which all the DBMS functionality,
application program execution, and user interface
processing were carried out on one machine.
• DBMS systems started to exploit the available
processing power at the user side, which led to
client/server DBMS architectures.
Centralized Architecture for DBMS
Client/Server Architecture:
• The client/server architecture was developed to deal with
computing environments in which a large number of PCs,
workstations, file servers, printers, database servers, Web
servers, and other equipment are connected via a network.
• The idea is to define specialized servers with specific
functionalities.
• The resources provided by specialized servers can be accessed
by many client machines.
• The client machines provide the user with the appropriate
interfaces to utilize these servers, as well as with local
processing power to run local applications.
• This concept can be carried over to software, with specialized
software-such as a DBMS or a CAD (computer-aided design)
package being stored on specific server machines and being
made accessible to multiple clients.
• The concept of client/server architecture assumes an
underlying framework that consists of many PCs and
workstations as well as a smaller number of mainframe
machines, connected via local area networks and other
types of computer networks.
• A client in this framework is typically a user machine that
provides user interface capabilities and local processing.
• When a client requires access to additional functionality-
such as database access-that does not exist at that
machine, it connects to a server that provides the needed
functionality.
• A server is a machine that can provide services to
the client machines, such as file access, printing,
or database access.
• In the general case, some machines install only
client software, others only server software, and
still others may include both client and server
software.
• However, it is more common that client and
server software usually run on separate machines.
• In client/server architecture, the user interface
programs and application programs can run on the
client side.
• When DBMS access is required, the program
establishes a connection to the DBMS (which is
on the server side); once the connection is created,
the client program can communicate with the
DBMS.
• A standard called Open Database Connectivity
(ODBC) provides an application programming
interface (API), which allows client-side
programs to call the DBMS, as long as both client
and server machines have the necessary software
installed.
• Most DBMS vendors provide ODBC drivers for
their systems.
Classification of DBMS
Database management systems can be
classified based on several criteria, such
as:-
1. The data model
2. User numbers
3. Database distribution
1. Classification Based on Data Model

Relational data model.

Hierarchical data models

Network data models

Object-oriented data models


2. Classification Based on User Numbers

A DBMS can be classification based on the


number of users it supports.

1. Single-user database system -supports one


user at a time

2. Multiuser database system- supports


multiple users concurrently.
3. Classification Based on Database Distribution
• There are four main distribution systems for
database systems and these, in turn, can be used to
classify the DBMS.

1].Centralized systems
• With a centralized database system, the DBMS
and database are stored at a single site that is used
by several other systems too.
• This is illustrated in following Figure.
Example of a centralized database system.

• In the early 1980s, many Canadian libraries


used the GEAC 8000 to convert their manual
card catalogues to machine-readable
centralized catalogue systems.
• Each book catalogue had a barcode field
similar to those on supermarket products.
2]. Distributed database system
• In a distributed database system, the actual
database and the DBMS software are distributed
from various sites that are connected by a
computer network, as shown in Figure.

Example of a distributed database system.


3] Homogeneous distributed database systems
• Homogeneous distributed database systems use
the same DBMS software from multiple sites.
• Data exchange between these various sites can be
handled easily.
• For example, library information systems by the
same vendor, such as Geac Computer
Corporation, use the same DBMS software which
allows easy data exchange between the various
Geac library sites.
4]. Heterogeneous distributed database systems
• In a heterogeneous distributed database system,
different sites might use different DBMS software,
but there is additional common software to support
data exchange between these sites.
• For example, the various library database systems
use the same machine-readable cataloguing
(MARC) format to support library record data
exchange.
UNIT 3
Data Modeling Using the Entity-
Relationship (ER) Model
Entity-Relationship (ER) model
• Popular high-level conceptual data
model
ER diagrams
• Diagrammatic notation associated
with the ER model
Unified Modeling Language (UML)
Using High-Level Conceptual
Data Models for Database Design
Requirements collection and analysis
 Database designers interview prospective
database users to understand and document
data requirements
 Result: data requirements
 Functional requirements of the application
Conceptual schema
 Conceptual design

 Description of data requirements

 Includes detailed descriptions of the entity


types, relationships, and constraints
 Transformed from high-level data model
into implementation data mode
Logical design or data model mapping
• Result is a database schema in implementation
data model of DBMS

Physical design phase


• Internal storage structures, file organizations,
indexes, access paths, and physical design
parameters for the database files specified
A Sample Database Application
 COMPANY

 Employees, departments, and projects

 Company is organized into departments

 Department controls a number of projects

 Employee: store each employee’s name, Social


Security number, address, salary, sex (gender),
and birth date
 Keep track of the dependents of each employee
Entity Types, Entity Sets,
Attributes, and Keys
 ER model describes data as:
 Entities
 Relationships
 Attributes
Entity
 An entity has certain properties which are
known as attributes.
Attributes represent the nature of each entity.
This is what makes entities distinguishable
because attributes define their characteristics.
For example, when considering employees
as an entity, their attributes would be their
Employer Identification Number, age, mobile
number, gender, name, etc.
In a DMBS, there are two types of entity—Strong
Entity and Weak Entity.
Strong Entity
• A strong entity typically has a primary key and is
independent—meaning they don’t rely on other
entities' existence.
• For example, a strong entity would be a
“customer” when going through a customer
database.
• The customer ID would be its primary key
attribute since it has a unique number and cannot
be replicated in the database.
Weak Entity
• A weak entity, on the other hand, is dependent on the
parent entity since it does not have a primary key.
• It basically has no meaningful attributes except for the
foreign key from the parent entity.
• For example, a weak entity would be an “order” in a
customer database because it is solely dependent on the
parent entity “customer” despite having a few attributes
such as order number, deliverables, etc.
Entity Type
• An Entity Type denotes a person or object
type in which the information is stored.
• It basically describes the type of information
and how it corresponds to one or many
related tables in DBMS.
• It refers to the category that a particular
entity belongs to.
Example :
• A table named student in a university database.
• A table named employee in a company database.
Entity Set :
• An entity set is a collection or set of all entities of a
particular entity type at any point in time.
• The type of all the entities should be the same.
Example :
• The collection of all the students from the
student table at a particular instant of time is
an example of an entity set.
• The collection of all the employees from the
employee table at a particular instant of time
is an example of an entity set.
Relation With Table :
Consider a table student as follows :
Table Name : Student
Student_ID Student_Name Student_Age Student_Gender

1 Avi 19 M

2 Ayush 23 M

3 Nikhil 21 M

4 Riya 16 F

Entity : Each row is an entity.


Example :

1 Avi 19 M
Entity Type :
Each entity belongs to the student type. Hence, the
type of entity here is a student.
Entity Set :
The complete data set of all entities is called entity
set. For the above table, the records with student id
1, 2, 3, 4 are the entity set.
Difference Table :
Entity Entity Type Entity Set
A thing in the real world with A category of a particular Set of all entities of a
independent existence entity particular entity type.

Any particular row (a The name of a relation


All rows of a relation (table)
record) in a relation(table) is (table) in RDBMS is an
in RDBMS is entity set
known as an entity. entity type
Attributes
• Attributes are properties or characteristics of an entity.
• Attributes are used to describe the entity.
• The attribute is nothing but a piece of data that gives more
information about the entity.
• Attributes are used to distinguish one entity from the other
entity.
• Attributes help to categorize the entity and the entity can be
easily retrieved and manipulate the entity.
• An entity with no attribute is of no use in the database.
Example
• Let’s take the student as an entity. Students will have multiple
attributes such as roll number, name, and class.
• These attributes are used to describe the student in more
• As shown in the figure, roll_no, name, and class
are the attributes of the entity Student.
• All three attributes give meaning to the entity.
The information about the student entity lies in
all 3 attributes.
Types Of Attribute
• There are 8 types of attributes in DBMS.
Simple Attribute.
Composite Attribute.
Single Valued Attribute.
Multivalued Attribute.
Key Attribute.
Derived Attribute.
Stored Attribute.
Complex Attribute.
1). Simple Attribute
• Simple attributes are those attributes that cannot be
divided into more attributes.
• Simple attributes state the simple information about the
entity such as name, roll_no, class, age, etc.
• Simple attributes are widely used for storing
information about the entity.
Example
• Here in the below example, Student has roll_no, class,
and name as attributes that cannot be divided into more
sub-attributes.
• These types of attributes are called simple attributes.
• Simple attributes are mainly used to create all other
types of attributes.
2). Composite Attribute
• When 2 or more than 2 simple attributes are combined to
make an attribute then that attribute is called
a Composite attribute.
• The composite attribute is made up of multiple attributes.
• After combining these attributes, the composed attributes
are formed.
• Complex attributes are used where data is complex and
needs to be stored in a complex structure.
Example
• Here if we look at the below example, address is
the attribute derived from the 3 simple attributes
i.e. City, State, and Street.
• To get the value of the address attribute, we have
first to know those city, state, and street attributes.
• This type of attribute is known as a composite
attribute.
3). Single Valued Attribute
• The attribute with only a single value is known as a single-
valued attribute.
• These attributes have a single value for each instance of a
given entity.
• Mostly these attributes are used to provide the unique
identity to the multiple instances of attributes.
• Example
• In the given example, we know that the DOB attribute will
have only one value. So we can say that the DOB attribute is
nothing but a single Valued attribute and it cannot have
multiple attributes.
• Here roll_no and name will also have mostly one value only.
• We can say that all 3 attributes of the student are single-
valued.
4). Multivalued Attribute
• An attribute which can have multiple values is
known as a multivalued attribute.
• Multivalued attributes have multiple values for the
single instance of an entity.
• Keu of entity is associated with multiple values.
• It does not have only one value. It is the opposite
of the single-valued attribute.
Example
• Here the student has an attribute named
phone_no.
• One student can have multiple phone_no, so
we can say that phone_no can have multiple
values.
• These types of attributes are known
as multi-valued attributes.
• Multi-valued attributes are used when more
than 1 entries for one attribute need to be
stored in the Database.
5). Key Attribute
• The attribute which has unique values for every
row in the table is known as a Key Attribute.
• The key attribute has a very crucial role in the
database.
• The key attribute is a distinct and unique
characteristic of the entity that can be used to
identify the entity uniquely.
Example
• For students, we can identify every student with
roll_no because each student will have a unique
roll_no.
• This indicates that roll_no will be a Key attribute
for the Student entity.
• All operations on the database can be performed
only using Key Attributes.
6). Derived Attribute
• The attribute that can be derived from the other attributes
and does not require to be already present in the database
is called a Derived Attribute.
• Derived attributes are not stored in the Database directly.
• It is calculated by using the stored attributes in the
database.
Example
• Here the student has multiple attributes including DOB
and age.
• It is observed that age can be calculated with the help of
the DOB attribute.
• So age is a derived attribute that is derived from an
attribute named DOB.
7). Stored Attribute
• If the data of the attribute remains constant for every
instance of entity then it is called a Stored Attribute.
• The value of the attribute present in the database does
not get updated and it remains constant once it is
stored.
• These attributes are used to store permanent
information about an entity which will remain constant
throughout the lifetime of the entity.
Example
• The student has 3 attributes as shown above. Her
name and DOB will remain the same throughout
his/her education.
• So the student has a fixed value attribute that will
never change in the future.
• These attributes are known as stored attributes.
8). Complex Attribute
• When multi-valued and composite attributes
together form an attribute then it is called
a Complex attribute.
• Complex attributes can have an unlimited number
of sub-attributes.
Example
• Here for the student, we created an attribute named
contact_info which further decomposed into
phone_no + Address.
• The address is a composite attribute which is
further divided into simple attributes and phone_no
is a multivalued attribute.
• This indicates that the contact_info attribute is
made from the multi-valued and composite
attribute.
• This type of attribute is known as the
Complex Attribute.
Keys
A key refers to an attribute/a set of attributes that
help us identify a row (or tuple) uniquely in a table
(or relation). A key is also used when we want to
establish relationships between the different
columns and tables of a relational database. The
individual values present in a key are commonly
referred to as key values.
Types of Keys in Database
Super Key

Candidate Key

Primary Key

Alternate Key

Unique Key

Foreign Key

Composite Key
Patients Table
Patient ID Patient Name Sex Age MedInsuranceNo AadharNo
01 Sheela F 23 Med0291 839292319012
02 Rehan M 21 Med8421 123456789012
03 Anay M 56 Med4203 848298469201
04 Mahira F 42 Med4792 724723021922
05 Nishant M 12 Med8419 47203831109
03 Anay M 56 Med4203 848298469201

Checkup Details Table


Patient ID AnnualCheckupMonth Fees
03 Feb2022 6700
04 Apr2022 8900
03 Feb2022 6700
04 Apr2022 8900
1) Super Key
• Super Key is a set of attributes that can uniquely identify a table.
• A single table can have multiple super keys.
• A candidate key, primary key and a unique key can be a super
key, but the reverse does not hold true.
Example:
• In our above example we have chosen the PatientID, MedInsuranceNo and
Aadhar No to uniquely identify tuples. So the super key set will be as
follows:
• {PatientID}
• {MedInsuranceNo}
• {AadharNo}
• {PatientID, MedInsuranceNo}
• {PatientID, AadharNo}
• {MedInsuranceNo, AadharNo}
• {PatientID, MedInsuranceNo, AadharNo}
2) Candidate Key
• Candidate Key is a set of attributes that can uniquely identify
a table.
• A single table can have multiple candidate keys.
• Out of all the chosen candidate keys, one of the keys is
selected as the primary key.
Example:
• PatientID, MedInsuranceNo, AadharNo can be chosen as the
candidate keys from the Patients table.
Rules for Candidate Key
• Unique values must be present in all columns, chosen as
candidate key
• A single table can have multiple candidate keys
• Null values can be present in the column chosen as candidate
Candidate Key Operations
• In this section understand the various operations of
candidate keys.
• Apply Candidate Key while creating table
• Alter a Candidate Key of a table
• Drop a Candidate Key of a table
Apply Candidate Key while creating table
CREATE TABLE Patients ( PatientID INT
UNIQUE, PatientName VARCHAR(255), Sex
VARCHAR(255), Age VARCHAR(255),
MedInsuranceNo VARCHAR(255) UNIQUE,
AadharNo INT UNIQUE, );
3) Primary Key
• Primary Key is a set of attributes that can uniquely
identify a table.
• A single table can have only one primary key.
• Out of all the chosen candidate keys, one of the
keys is selected as the primary key.
Example:
• PatientID, MedInsuranceNo, AadharNo are chosen
as the candidate keys from the Patients table.
• Either of them can be chosen as a Primary key.
Rules for Primary Key
• Unique values must be present in all columns, chosen as
primary key
• A single table can have only one primary key
• No NULL value must be present in the column chosen as
primary key
• A new row cannot be inserted with an existing primary key
Primary Key Operations
• In this section of the article let us understand the various
operations of primary keys.
• Apply Primary Key while creating table
• Apply Primary Key on multiple columns
• Alter a Primary Key of a table
• Drop a Primary Key of a table
Apply Primary Key while creating table
• CREATE TABLE Patients ( PatientID INT NOT
NULL PRIMARY KEY, PatientName
VARCHAR(255) NOT NULL, Sex
VARCHAR(255), Age VARCHAR(255),
MedInsuranceNo VARCHAR(255, AadharNo
INT );
4) Alternate Key
• As the name suggests, all the candidate keys
which are not selected as primary keys are known
as the Alternate Key.
Example:
• If the PatientID is selected as the Primary Key, then
the MedInsuranceNo and the AadharNo are known
as the alternate keys.
Rules for Alternate Key
• Unique values must be present in all columns,
chosen as alternate key
• The alternate key is a part of candidate key but is
not connected to primary key
• In case a table contains a single candidate key then
it will be chosen as the primary key. In that case
there won’t be any alternate key.
• It is defined by the UNIQUE keyword
Apply Alternate Key while creating table
• CREATE TABLE Patients ( PatientID INT
PRIMARY KEY, PatientName
VARCHAR(255), Sex VARCHAR(255), Age
VARCHAR(255), MedInsuranceNo
VARCHAR(255) UNIQUE, AadharNo INT );
5) Unique Key
• The Unique key is quite similar to primary keys in
a database.
• The only difference is that the unique keys allow a
single NULL value in the column and must not
have any duplicate values.
Example:
• MedInsuranceNo can be considered as a unique
key.
Apply Unique Key while creating table
• CREATE TABLE Patients ( PatientID INT,
PatientName VARCHAR(255), Sex
VARCHAR(255), Age VARCHAR(255),
MedInsuranceNo VARCHAR(255), AadharNo
INT, UNIQUE (MedInsuranceNo) );
6) Foreign Key
• Primary Key is a set of attributes that can take
values referenced to the values of another table.
Example:
• PatientID in the CheckupDetails table is referred
to the PatientID in the Patients table.
Rules for Foreign Key
• Relationship between both the tables is known as
referential integrity.
• A single table can have multiple foreign keys
• A foreign key can have NULL values.
• You can duplicate foreign keys
• The table consisting of the foreign key is known
as the CHILD table and the table that is referred
by the foreign key is called the parent table.
Foreign Key Operations
• In this section of the article let us understand the
various operations of foreign keys.
• Apply Foreign Key while creating table
• Apply Foreign Key on multiple columns
• Alter a Foreign Key of a table
• Drop a Foreign Key of a table
Apply Foreign Key while creating table
• CREATE TABLE CheckupDetails ( PatientID INT
NOT NULL, AnnualCheckUpMonth
VARCHAR(255), Price INT, PRIMARY KEY
(PatientID), FOREIGN KEY (PatientID)
REFERENCES Patients(PatientID) );
7) Composite Key
• As the name suggests a composite key is a
combination of multiple columns that can uniquely
identify tuples.
Example:
• PaitentID and AnnualCheckupMonth can be
considered together as a composite key.
Apply Composite Key on multiple columns
• CREATE TABLE Patients ( PatientID INT,
PatientName VARCHAR(255), Sex
VARCHAR(255), Age VARCHAR(255),
MedInsuranceNo VARCHAR(255), AadharNo INT,
PRIMARY KEY (PatientID, MedInsuranceNo) );

You might also like