0% found this document useful (0 votes)
48 views62 pages

Database Notes

enochian lang

Uploaded by

pillylinox04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views62 pages

Database Notes

enochian lang

Uploaded by

pillylinox04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 62

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

What is a File System?


File system is a method of organizing the files with a hard
disk or other medium of storage. File system arranges
the files and helps in retrieving the files, when required.
It is compatible with different file types, such as mp3,
doc, txt, mp4,etc and these are also grouped into
directories
Database Management System
•Database management system is a 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 and a lot
more.
•It provides protection and security to the database. In
the case of multiple users, it also maintains data
consistency.
DBMS allows users the following tasks:
•Data Definition: It is used for creation, modification, and
removal of definition that defines the organization of data
in the database.
•Data Updation: It is used for the insertion, modification,
and deletion of the actual data in the database.
•Data Retrieval: It is used to retrieve the data from the
database which can be used by applications for various
purposes.
•User Administration: It is used for registering and
monitoring users, maintain data integrity, enforcing data
security, dealing with concurrency control, monitoring
performance and recovering information corrupted by
unexpected failure.
Characteristics of DBMS
•It uses a digital repository established on a server to store
and manage the information.
•It can provide a clear and logical view of the process that
manipulates data.
•DBMS contains automatic backup and recovery procedures.
•It contains ACID properties which maintain data in a
healthy state in case of failure.
•It can reduce the complex relationship between data.
•It is used to support manipulation and processing of data.
•It is used to provide security of data.
•It can view the database from different viewpoints
according to the requirements of the user.
Advantages of DBMS
•Controls database redundancy: It can control data redundancy
because it stores all the data in one single database file and that
recorded data is placed in the database.
•Data sharing: In DBMS, the authorized users of an organization can
share the data among multiple users.
•Easily Maintenance: It can be easily maintainable due to the
centralized nature of the database system.
•Reduce time: It reduces development time and maintenance
need.
•Backup: It provides backup and recovery subsystems which create
automatic backup of data from hardware and software failures and
restores the data if required.
•multiple user interface: It provides different types of user
interfaces like graphical user interfaces, application program
interfaces
Disadvantages of DBMS
•Cost of Hardware and Software: It requires a high
speed of data processor and large memory size to run
DBMS software.
•Size: It occupies a large space of disks and large
memory to run them efficiently.
•Complexity: Database system creates additional
complexity and requirements.
•Higher impact of failure: Failure is highly impacted
the database because in most of the organization, all
the data stored in a single database and if the
database is damaged due to electric failure or
database corruption then the data may be lost forever.
What is the Difference between File System and
DBMS?
The file system is a collection of data and for any
management with it, the user has to write the
procedures, while DBMS is a collection of data and user
need not write the procedures for handling the database.
Learn about what is the difference between a file system
and DBMS from the table given.
Difference between File System and DBMS

File System Database Management System

Used to manage and organize the files A software to store and retrieve the
stored in the hard disk of the computer user’s data
Redundant data is present No presence of Redundant data

Query processing is not so efficient Query processing is efficient

Data consistency is low Due to the process of normalisation, the


data consistency is high

Less complex, does not support More complexity in managing the data,
complicated transactions easier to implement complicated
transactions

Less security Supports more security mechanisms

Less expensive in comparison to DBMS Higher cost


Types of Databases
1) Centralized Database
It is the type of database that stores data at a centralized database system. It
comforts the users to access the stored data from different locations through
several applications.
These applications contain the authentication process to let users access data
securely. An example of a Centralized database can be Central Library that
carries a central database of each library in a college/university.

Advantages of Centralized Database


•It has decreased the risk of data management, i.e., manipulation
of data will not affect the core data.
•Data consistency is maintained as it manages data in a central
repository.
•It provides better data quality, which enables organizations to
establish data standards.
•It is less costly because fewer vendors are required to handle the
data sets.
2) Distributed Database
Unlike a centralized database system, in distributed systems, data
is distributed among different database systems of an
organization. These database systems are connected via
communication links. Such links help the end-users to access the
data easily. Examples of the Distributed database are Apache
Cassandra, HBase, Ignite, etc.
Homogeneous DDB:
Those database systems which execute on the same operating
system and use the same application process and carry the same
hardware devices.
Heterogeneous DDB:
Those database systems which execute on different operating
systems under different application procedures, and carries
different hardware devices.
Advantages of Distributed Database
•Modular development is possible in a distributed database,
i.e., the system can be expanded by including new computers
and connecting them to the distributed system.
•One server failure will not affect the entire data set .
3) Relational Database
This database is based on the relational data model, which stores
data in the form of rows(tuple) and columns(attributes), and
together forms a table(relation).
A relational database uses SQL for storing, manipulating, as well as
maintaining the data. E.F. Codd invented the database in 1970.
Each table in the database carries a key that makes the data
unique from others.
Examples of Relational databases are MySQL, Microsoft SQL
Server, Oracle, etc.
4) NoSQL Database
Non-SQL/Not Only SQL is a type of database that is used for
storing a wide range of data sets. It is not a relational database as
it stores data not only in tabular form but in several different ways.
It came into existence when the demand for building modern
applications increased. Thus, NoSQL presented a wide variety of
database technologies in response to the demands.
Advantages of NoSQL Database
•It enables good productivity in the application development as it
is not required to store data in a structured format.
•It is a better option for managing and handling large data sets.
•It provides high scalability.
•Users can quickly access data from the database through key-
value.
5) Cloud Database
•A type of database where data is stored in a virtual
environment and executes over the cloud computing
platform.
•It provides users with various cloud computing services
(SaaS, PaaS, IaaS, etc.) for accessing the database.
•There are numerous cloud platforms, but the best options
are:
Amazon Web Services(AWS)
Microsoft Azure
Kamatera
PhonixNAP
ScienceSoft
Google Cloud SQL, etc.
6) Object-oriented Databases
The type of database that uses the object-based data model
approach for storing data in the database system.
The data is represented and stored as objects which are similar to
the objects used in the object-oriented programming language.
7) Hierarchical Databases
It is the type of database that stores data in the form of parent-
children relationship nodes. Here, it organizes data in a tree-like
structure.
8) Network Databases
•It is the database that typically follows the network data model.
Here, the representation of data is in the form of nodes connected
via links between them.
•Unlike the hierarchical database, it allows each record to have
multiple children and parent nodes to form a generalized graph
structure.
9) Personal Database
•Collecting and storing data on the user's system defines a
Personal Database. This database is basically designed for a single
user.
10) Operational Database
The type of database which creates and updates the database in
real-time.
It is basically designed for executing and handling the daily data
operations in several businesses.
For example, An organization uses operational databases for
managing per day transactions.
11) Enterprise Database
Large organizations or enterprises use this database for managing
a massive amount of data.
It helps organizations to increase and improve their efficiency.
Such a database allows simultaneous access to users.
DBMS Architecture
The DBMS design depends upon its architecture.
The basic client/server architecture is used to deal
with a large number of PCs, web servers,
database servers and other components that are
connected with networks.
The client/server architecture consists of many
PCs and a workstation which are connected via
the network.
DBMS architecture depends upon how users are
connected to the database to get their request
done.
Types of DBMS Architecture
1-Tier Architecture
•In this architecture, the database is directly
available to the user.
•It means the user can directly sit on the DBMS
and uses it.
Any changes done here will directly be done on
the database itself. It doesn't provide a handy tool
for end users.
The 1-Tier architecture is used for development of
the local application, where programmers can
directly communicate with the database for the
quick response.
2-Tier Architecture
The 2-Tier architecture is same as basic client-server. In
the two-tier architecture, applications on the client
end can directly communicate with the database at the
server side. For this interaction, API's
like: ODBC, JDBC are used.
The user interfaces and application programs are run
on the client-side.
The server side is responsible to provide the
functionalities like: query processing and transaction
management.
To communicate with the DBMS, client-side application
establishes a connection with the server side.
Fig: 2-tier Architecture
3-Tier Architecture
The 3-Tier architecture contains another layer
between the client and server. In this architecture,
client can't directly communicate with the server.
The application on the client-end interacts with an
application server which further communicates with
the database system.
End user has no idea about the existence of the
database beyond the application server. The database
also has no idea about any other user beyond the
application.
The 3-Tier architecture is used in case of large web
application.
Fig: 3-tier Architecture
Data Models
Data Model is the modeling of the data
description, data semantics, and consistency
constraints of the data.
It provides the conceptual tools for describing the
design of a database at each level of data
abstraction.
Therefore, there are following four data models
used for understanding the structure of the
database:
The relational data model
•Is a way to organize data in tables, using rows and
columns to structure data across multiple tables:
Tables: Each table stores information in rows and
columns.
Columns: Columns, also known as attributes, specify the
data type.
Rows: Rows, also known as records or tuples, contain the
value of the data type specified by the column.
Keys: Each table has a primary key, which is a unique
identifier for each row.
Foreign keys: Rows can be used to create relationships
between tables using foreign keys, which are references
to the primary key of another table
•A relational database consists of a collection of tables,
each of which is assigned a unique name. Consider a
relation STUDENT with attributes ROLL_NO, NAME,
ADDRESS, PHONE, and AGE shown in the table.
Table Student
ROLL_NO NAME ADDRESS PHONE AGE

1 RAM DELHI 9455123451 18

2 RAMESH GURGAON 9652431543 18

3 SUJIT ROHTAK 9156253131 20

4 SURESH DELHI 18
Important Terminologies
•Attribute:
Attributes are the properties that define an entity.
e.g.; ROLL_NO, NAME, ADDRESS
•Relation Schema:
A relation schema defines the structure of the relation and
represents the name of the relation with its attributes. e.g.;
STUDENT (ROLL_NO, NAME, ADDRESS, PHONE, and AGE) is the
relation schema for STUDENT. If a schema has more than 1
relation, it is called Relational Schema.
•Tuple:
Each row in the relation is known as a tuple. The above relation
contains 4 tuples, one of which is shown as:

1 RAM DELHI 9455123451 18


•Relation Instance:
The set of tuples of a relation at a particular instance of time is
called a relation instance. Table 1 shows the relation instance of
STUDENT at a particular time. It can change whenever there is an
insertion, deletion, or update in the database.
•Degree:
The number of attributes in the relation is known as the degree of
the relation. The STUDENT relation defined above has degree 5.
•Cardinality:
The number of tuples in a relation is known as cardinality.
The STUDENT relation defined above has cardinality 4.
•Column:
The column represents the set of values for a particular attribute.
The column ROLL_NO is extracted from the relation STUDENT.
•NULL Values:
The value which is not known or unavailable is called a NULL value.
It is represented by blank space. e.g.; PHONE of STUDENT having
ROLL_NO 4 is NULL.
•Relation Key:
These are basically the keys that are used to identify the rows
uniquely or also help in identifying tables.
Cardinality in DBMS
•Cardinality represents the number of times an entity of
an entity set participates in a relationship set.
•Or we can say that the cardinality of a relationship is the
number of tuples (rows) in a relationship.
•It is a fundamental concept that helps define how data
in different tables connect and how many unique entries
exist in a particular column.
What is Mapping Cardinality?
In a database, the mapping cardinality or cardinality ratio
means to denote the number of entities to which another
entity can be linked through a certain relation set. Mapping
cardinality is most useful in describing binary relation sets,
although it can contribute to the description of relation sets
containing more than two entity sets.
Types of cardinality in between tables are:
One-to-One
One-to-Many
Many-to-One
Many-to-Many
Entity-Relationship Data Model
•The Entity Relational Model is a model for identifying
entities to be represented in the database and
representation of how those entities are related.
•The ER data model specifies enterprise schema that
represents the overall logical structure of a database
graphically.
•The Entity Relationship Diagram explains the
relationship among the entities present in the database.
ER models are used to model real-world objects like a
person, a car, or a company and the relation between
these real-world objects.
•In short, the ER Diagram is the structural format of the
database.
Why Use ER Diagrams In DBMS?
•ER diagrams represent the E-R model in a database,
making them easy to convert into relations (tables).
•ER diagrams provide the purpose of real-world modeling
of objects which makes them intently useful.
•ER diagrams require no technical knowledge and no
hardware support.
•These diagrams are very easy to understand and easy to
create even for a naive user.
•It gives a standard solution for visualizing the data
logically.
Symbols Used in ER Model
ER Model is used to model the logical view of the system
from a data perspective which consists of these symbols:
•Rectangles: Rectangles represent Entities in the ER
Model.
•Ellipses: Ellipses represent Attributes in the ER Model.
•Diamond: Diamonds represent Relationships among
Entities.
•Lines: Lines represent attributes to entities and entity
sets with other relationship types.
•Double Ellipse: Double Ellipses represent Multi-Valued
Attributes.
•Double Rectangle: Double Rectangle represents a Weak
Entity.
Components of ER Diagram
ER Model consists of Entities, Attributes, and Relationships among
Entities in a Database System.
What is Entity?
An Entity may be an object with a physical existence – a particular
person, car, house, or employee – or it may be an object with a
conceptual existence – a company, a job, or a university course.

Types of Entity
There are two types of entity:
1. Strong Entity
A Strong Entity is a type of entity that has a key Attribute. Strong
Entity does not depend on other Entity in the Schema. It has a
primary key, that helps in identifying it uniquely, and it is represented
by a rectangle.
2. Weak Entity
•An Entity type has a key attribute that uniquely
identifies each entity in the entity set. But some entity
type exists for which key attributes can’t be defined.
These are called Weak Entity types .
For Example, A company may store the information of
dependents (Parents, Children, Spouse) of an Employee.
But the dependents can’t exist without the employee.
•So Dependent will be a Weak Entity Type and Employee
will be Identifying Entity type for Dependent, which
means it is Strong Entity Type .
•A weak entity type is represented by a Double
Rectangle.
What is Attributes?
•Attributes are the properties that define the entity type.
For example, Roll_No, Name, DOB, Age, Address, and
Mobile_No are the attributes that define entity type
Student. In ER diagram, the attribute is represented by an
oval.
Types of Attributes
1. Key Attribute
The attribute which uniquely identifies each entity in the
entity set is called the key attribute. For example,
Roll_No will be unique for each student. In ER diagram,
the key attribute is represented by an oval with
underlying lines.
2. Composite Attribute
An attribute composed of many other attributes is called
a composite attribute. For example, the Address attribute
of the student Entity type consists of Street, City, State,
and Country. In ER diagram, the composite attribute is
represented by an oval comprising of ovals.
3. Multivalued Attribute
An attribute consisting of more than one value for a given
entity. For example, Phone_No (can be more than one for
a given student). In ER diagram, a multivalued attribute is
represented by a double oval.
4. Derived Attribute
An attribute that can be derived from other
attributes of the entity type is known as a derived
attribute. e.g.; Age (can be derived from DOB). In
ER diagram, the derived attribute is represented
by a dashed oval.
3) Object-based Data Model:
An extension of the ER model with notions of
functions, encapsulation, and object identity, as
well. This model supports a rich type system that
includes structured and collection types. Thus, in
1980s, various database systems following the
object-oriented approach were developed. Here,
the objects are nothing but the data carrying its
properties.
4) Semistructured Data Model:
This type of data model is different from the other three
data models (explained above).
The semistructured data model allows the data
specifications at places where the individual data items
of the same type may have different attributes sets.
The Extensible Markup Language, also known as XML, is
widely used for representing the semistructured data.
Although XML was initially designed for including the
markup information to the text document, it gains
importance because of its application in the exchange of
data.
Database Language
Database language refers to the specific types of commands or
instructions used to communicate with a database. It helps users
or applications to create, manage, update, and retrieve data from
a database. database language is like a set of tools that help you
talk to and work with the data stored in a database.
Types of Database Languages in DBMS
1. Data Definition Language
2. Data Manipulation Language
3. Data Control Language
4. Transactional Control Language
1. DDL (Data Definition Language)
The DDL stands for Data Definition Language, Which is used to define
the database's internal structure and Pattern of the Database.
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.
Database commands used in DDL
Create: It is used to create objects in the database
Alter: It is used to change or alter the structure of the database
objects
Drop: It is used to delete objects from the database
Truncate: It is used to remove all records from a table
Rename: It is used to rename the object in the database
Comment: It is used for comments on the data dictionary.
Create Command
It is one of the commands in DDL that is used for creating objects
the 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:
CREATE TABLE Students(Student_ID INT PRIMARY KEY,NAME
VARCHAR(50),AGE INT);
2.DCL (Data Control Language)
The DCL stands for Data Control Language means these commands
are used to retrieve the saved data from the database. And one
more thing is the DCL execution is Transactional which means It
has rollback parameters.
we have two tasks under the Data Control Language below I listed
them
Grant: It is used to give user access to the database
Revoke: It is used to take back access or permissions from the user
Grant Command
The GRANT command in a Database Management System (DBMS)
is used to provide specific permissions or privileges to users or
roles. This command allows administrators to control access to
database objects, ensuring that only authorized users can perform
certain actions, such as selecting, inserting, updating, or deleting
data.
Syntax
GRANT privileges
ON object
TO user_or_role [WITH GRANT OPTION];
Example
GRANT SELECT, INSERT ON students TO user;
Revoke Command
The REVOKE command in a Database Management System
(DBMS) is used to remove previously granted permissions or
privileges from users or roles. This command is essential for
managing access control, ensuring that users do not have more
privileges than necessary to perform their tasks.
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 to select data from the Table based on the
requirements
Insert: It is used for Inserting data into an existing table
Update: It is used to update data in the Table based on the
requirement
Delete: It is used to delete data from the Table
Merge: It is used for upsert operations
Call: It is used to call a structured query language or Java sub-
program
Lock Table: It can control the concurrency
Select Command
The SELECT command in SQL (Structured Query Language) is used
to retrieve data from one or more tables in a database. It is one of
the most commonly used commands in SQL, allowing users to
specify exactly what data they want to see and how they want it
organized.
Syntax
SELECT * FROM Table_Name
Example:
Select*from students table;
Insert Command
The INSERT command in SQL (Structured Query Language) is used
to add new records or rows to a table in a database. This
command is essential for populating a database with data and can
be used to insert data into all or specific columns of a table.
Syntax
INSERT INTO Table_Name (Column 1, Column 2, Column 3, Column
4) VALUES (Value 1, Value 2,Value 3, Value 4);
Example
INSERT INTO Students
table(STUDENT_ID,NAME,AGE,SEX)VALUES(101,JOHNSON,22,MAL
E);
4. TCL ( Transaction Control Language )
The TCL full form is Transaction Control Language commands are
used to run the changes made by the DML commands one more
thing is TCL can be grouped into a logical transaction. We have two
different commands in this category I listed them for reference.
Commit: It is used to save the transaction on the Database. These
are very useful in the banking sector.
Rollback: It is used to restore the database to its original state
from the last commit. This command also plays an important role
in Banking Sectors.
Commit Command
The Commit command is used to 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 new data into the Table then I committed It.
Syntax
Database Operation
Commit
ROLLBACK Command
The rollback command is used to restore the database to its
original state from the last commit. Here I provide the example
and in this, I already commit what you can see above, Now I delete
one row from the Table and then again roll back the previous
database state.
Syntax
ROLLBACK;
ACID Properties in DBMS
DBMS is the management of data that should remain
integrated when any changes are done in it. It is because
if the integrity of the data is affected, whole data will get
disturbed and corrupted.
Therefore, to maintain the integrity of the data, there are
four properties described in the database management
system, which are known as the ACID properties.
The ACID properties are meant for the transaction that
goes through a different group of tasks, and there we
come to see the role of the ACID properties.
ACID Properties
1) Atomicity
The term atomicity defines that the data remains atomic. It means if
any operation is performed on the data, either it should be
performed or executed completely or should not be executed at all.
It further means that the operation should not break in between or
execute partially. In the case of executing operations on the
transaction, the operation should be completely executed and not
partially.
Example:
Consider transaction from Account A to Account B
If the credit and debit process done successful then Atomicity is
complete
Thus, when the amount loses atomicity, then in the bank systems,
this becomes a huge issue, and so the atomicity is the main focus
in the bank systems.
2) Consistency
The word consistency means that the value should remain
preserved always. In DBMS, the integrity of the data should be
maintained, which means if a change in the database is made, it
should remain preserved always. In the case of transactions, the
integrity of the data is very essential so that the database remains
consistent before and after the transaction. The data should
always be correct.
Example
Consider three accounts A,B and C in which A
debits to B and C, when debit and credit both
become successful then the process is consistent.
3) Isolation
The term 'isolation' means separation. In DBMS, Isolation is the
property of a database where no data should affect the other one and
may occur concurrently. In short, the operation on one database
should begin when the operation on the first database gets complete.
It means if two operations are being performed on two different
databases, they may not affect the value of one another. In the case of
transactions, when two or more transactions occur simultaneously,
the consistency should remain maintained. Any changes that occur in
any particular transaction will not be seen by other transactions until
the change is not committed in the memory.
Example: If two operations are concurrently running on two different
accounts, then the value of both accounts should not get affected. The
value should remain persistent.
As you can see in the below diagram, account A is making T1 and T2
transactions to account B and C, but both are executing independently
without affecting each other. It is known as Isolation.
4) Durability
Durability ensures the permanency of something. In DBMS, the
term durability ensures that the data after the successful
execution of the operation becomes permanent in the database.
The durability of the data should be so perfect that even if the
system fails or leads to a crash, the database still survives.
However, if gets lost, it becomes the responsibility of the
recovery manager for ensuring the durability of the database.
For committing the values, the COMMIT command must be used
every time we make changes.
Therefore, the ACID property of DBMS plays a vital role in
maintaining the consistency and availability of data in the
database.
Thus, it was a precise introduction of ACID properties in DBMS.
We have discussed these properties in the transaction section
also.
THANK YOU

You might also like