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

Structured Query Language

The document discusses SQL, a powerful database management and manipulation tool that allows users to interact with databases through standardized operations like data retrieval and updating. It describes SQL components like DDL, DML, DCL and TCL and commands like SELECT, INSERT, UPDATE and DELETE. It also discusses database concepts like joins, subqueries, data aggregation and database backup and recovery.

Uploaded by

Jawad Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Structured Query Language

The document discusses SQL, a powerful database management and manipulation tool that allows users to interact with databases through standardized operations like data retrieval and updating. It describes SQL components like DDL, DML, DCL and TCL and commands like SELECT, INSERT, UPDATE and DELETE. It also discusses database concepts like joins, subqueries, data aggregation and database backup and recovery.

Uploaded by

Jawad Ahmad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Database System

Structured Query Language

SQL, or Structured Query Language, is a powerful database management and


manipulation tool. It allows users to effortlessly interact with databases by
providing a standardized language for operations such as data retrieval and
updating. SQL's ease of use and adaptability make it an essential tool for anybody
working with databases.

SQL, or Structured Query Language, is the language used to interface with


relational databases. It is the bonding agent that allows software applications to
efficiently handle and retrieve data. SQL, in essence, allows you to interface with
databases by writing queries that execute various activities such as retrieving,
updating, and removing data.

Components of SQL

The components of the SQL can be likened together to create a powerful


application.

• Data Definition Language (DDL):

It is the architect of the database, DDL commands include CREATE, ALTER,


and DROP, shaping the structure of your data.

• Data Manipulation Language (DML):

Visualize DML as the construction crew; it handles the operations


like SELECT, INSERT, UPDATE, and DELETE, structuring the content within your
database.

• Data Control Language (DCL):

Security is the priority, and DCL commands like GRANT and REVOKE control access
permissions, ensuring that only authorized users enter the gates.

• Transaction Control Language (TCL):


Database System

This is the directing body, TCL commands COMMIT and ROLLBACK manage the
flow of transactions, ensuring data integrity.

Understanding these components enables you to use SQL with expertise,


maximizing the potential to successfully organize, query, and preserve your data.

SQL Commands

SQL commands are the foundation of database management, allowing users to


easily interact with and alter data. Structured Query Language (SQL) makes it
easier to retrieve, update, and manage data in databases.

SELECT commands, which serve as SQL's vision, are used to retrieve data.
The INSERT, UPDATE, and DELETE instructions serve as the hands, of updating
data entries. JOIN commands join tables together, forming associations that
improve data retrieval.

Consider SQL to be a chef in a kitchen: SELECT is for selecting


ingredients, INSERT is for adding new things to the menu, UPDATE is for revising
recipes, and DELETE is for deleting undesired dishes. The INDEX commands
organize the kitchen for efficiency, while the GROUP BY and ORDER BY commands
organize the final presentation.

The SELECT Statement

SELECT Column or Columns

FROM table or tables

WHERE condition

GROUP BY field or fields

ORDER BY Sort order

Types of SQL Databases

There are many popular RDBMS available to work with. Some of the most popular
RDBMS are listed below −
Database System

• MySQL

• MS SQL Server

• ORACLE

• MS ACCESS

• PostgreSQL

• SQLite

SQL Join and Subquery

A join is a query that combines records from two or more tables. A join will be
performed whenever multiple tables appear in the FROM clause of the query. The
select list of the query can select any columns from any of these tables. If join
condition is omitted or invalid then a Cartesian product is formed. If any two of
these tables have a column name in common, then must qualify these columns
throughout the query with table or table alias names to avoid ambiguity. Most
join queries contain at least one join condition, either in the FROM clause or in
the WHERE clause.
Advantages Of Joins:
• The advantage of a join includes that it executes faster.
• The retrieval time of the query using joins almost always will be faster than
that of a subquery.
• By using joins, you can minimize the calculation burden on the database
i.e., instead of multiple queries using one join query. This means you can
make better use of the database’s abilities to search through, filter, sort,
etc.
Disadvantages Of Joins:
Database System

• Disadvantage of using joins includes that they are not as easy to read as
subqueries.

• More joins in a query means the database server has to do more work,
which means that it is more time consuming process to retrieve data

Subquery
A Subquery or Inner query or Nested query is a query within SQL query and
embedded within the WHERE clause. A Subquery is a SELECT statement that is
embedded in a clause of another SQL statement. They can be very useful to select
rows from a table with a condition that depends on the data in the same or
another table. A Subquery is used to return data that will be used in the main
query as a condition to further restrict the data to be retrieved. The subquery can
be placed in the following SQL clauses they are WHERE clause, HAVING clause,
FROM clause.

Advantages Of Subquery:

• Subqueries divide the complex query into isolated parts so that a complex
query can be broken down into a series of logical steps.

• It is easy to understand and code maintenance is also at ease.

• Subqueries allow you to use the results of another query in the outer
query.

• In some cases, subqueries can replace complex joins and unions.

Disadvantages of Subquery:

• The optimizer is more mature for MYSQL for joins than for subqueries, so in
many cases a statement that uses a subquery can be executed more
efficiently if you rewrite it as join.

• We cannot modify a table and select from the same table within a subquery
in the same SQL statement.

How to Group and Aggregate Data Using SQL?


Database System

There can be many columns in a database table, so sometimes it can become


difficult and time taking to find the same type of data in these columns. The
GROUP BY statement groups the identical rows present in the columns of a
table. GROUP BY statement in conjunction with SQL aggregate functions (COUNT
(), MAX(), MIN(), SUM(), AVG() etc.) help us to analyze the data efficiently.

• COUNT counts how many rows are in a particular column.

• SUM adds together all the values in a particular column.

• MIN and MAX return the lowest and highest values in a particular column,
respectively.

• AVG calculates the average of a group of selected values.

Database Backup Recovery


Backup and Recovery both terms are data protection terminology. An efficient
backup and recovery system is critical for any firm to secure its precious data.
However, backup and recovery are distinct techniques, backup stores a copy of
the complete database onto storage media. In contrast, recovery is the
process of retrieving lost data from backup storage mediums.

Backup
Backup refers to the storage of a replication of the original data that may be
utilized in the event of data loss. Backup is considered one of the best data
security methods, and organizations should secure their important data by
utilizing the backup process. Backup can be accomplished by storing a backup
copy of the original data on storage devices or in a database.

The frequency of backup creation might vary depending on the importance of the
data. For example, if the data is particularly valuable, it must be backed up
daily. Monthly and quarterly backups are the same as daily backups but are only
performed on the last day of the month or quarter.
Database System

Nowadays, backups are created in the cloud due to technological advancements


because it offers highly feasible storage and simple management. There are
numerous backup types available, including complete backup, incremental
backup, local backup, mirror backup, and others.

Types of Data Backup

There are mainly three types of data backup, full, incremental, and differential
backup.

1. Full Backup

It is a simple and full backup procedure that copies all of your data to another
media set, including a tape, disk, or CD. As a result, a complete copy of all your
data is provided on a single media set. It takes a longer time to complete and
takes much storage space.

2. Incremental Backup

Incremental backups take up less space and time than differential and full
backups, but they are the most time-consuming technique for restoring a full
system. They're ideal for backing up data that hasn't changed in a long time.
However, there is no method to predict how much space you would use for future
backups.

3. Differential Backup

Differential backups are a combination of executing complete backups and


incremental backups on a regular basis. Differential backups are similar to
incremental backups in that they store data about changes to a database or
server. These backups make it simple to recover a whole copy of a database or
server from a single file. These backups are ideal for swiftly restoring databases
and servers without rebuilding everything.

These backups are very useful because they allow you to recover a database or
server swiftly. You don't have to generate a completely new version of it. Instead,
Database System

you apply the most recent code changes, restore a differential backup, and have a
working copy of the database or server.

Features of Backup

There are various features of Backup. Some of the backup features are as follows:

1. It is generally a data replica that is utilized to restore the actual data in the
case of data loss/damage.

2. It makes the process of data recovery simple and easy.

3. It is commonly utilized in manufacturing environments.

4. It provides data security to the users.

5. It is a cost-effective process to retrieve the data.

What is Recovery?

A database recovery system is an essential component of a Database


Management System that assures data consistency even after a system failure.
The process of restoring lost data is referred to as recovery. Even if the data was
backed up, it could still be recovered by employing various recovery procedures.
When a database fails, there is a risk of data loss. Therefore, the recovery
procedure aids in improving the database's reliability. Moreover, if any of the
transactions fails in the process of some activities, data recovery becomes a
critical task and the only option to save the lost data.

In this case, the failure could be any type, including system failure, concurrency
control enforcement, transaction errors, exception conditions, disk failure, and
disasters. Any event that results in downtime would require recovery. There are
various recovery processes, including Steal/no-steal and force/no-force policies,
shadowing, caching, before and after images of the data item, UNDO, REDO
recovery, etc.

Features of recovery
Database System

There are various features of Backup. Some of the backup features are as follows:

1. It is a process for restoring lost, damaged, or corrupted data to its original state.
2. The process of recovering is expensive.
3. When there is a failure, it refers to recovering the lost data.
4. It increases the database's reliability.
5. It is rarely utilized in production environments.

Difference Between Backup and recovery


There are various key differences between Backup and Recovery. Some of the key
differences between the Backup and Recovery are as follows:

1. A backup is a replication of data that is utilized to recover the original data


in the event of a data loss. In contrast, recovery is the process of restoring
inaccessible, damaged, lost, corrupted, or formatted data to its original
state.
2. A backup is a data replication. On the other hand, recovery is the process of
storing the database.
3. Taking backups does not determine their duration or systematic use. On
the other hand, recovery techniques are extremely beneficial. There are
various recovery options, including image-based backup, continuous
replication or snapshot, etc.
4. The use of backup production is quite prevalent. In contrast, recovery
production is extremely rare.
5. Backup necessitates additional storage space. On the other hand, Recovery
does not require additional external storage space because restoring is
done internally.

Indexing in Databases
Indexing improves database performance by minimizing the number of disc
visits required to fulfill a query. It is a data structure technique used to locate
and quickly access data in databases. Several database fields are used to
generate indexes. The main key or candidate key of the table is duplicated in
Database System

the first column, which is the Search key. To speed up data retrieval, the values
are also kept in sorted order. It should be highlighted that sorting the data is not
required. The second column is the Data Reference or Pointer which contains a
set of pointers holding the address of the disk block where that particular key
value can be found.

Attributes of Indexing
• Access Types: This refers to the type of access such as value-based search,
range access, etc.

• Access Time: It refers to the time needed to find a particular data element
or set of elements.

• Insertion Time: It refers to the time taken to find the appropriate space and
insert new data.

• Deletion Time: Time taken to find an item and delete it as well as update
the index structure.

• Space Overhead: It refers to the additional space required by the index.


Database System

NoSQL System
NoSQL is a type of database management system (DBMS) that is designed to
handle and store large volumes of unstructured and semi-structured data. Unlike
traditional relational databases that use tables with pre-defined schemas to store
data, NoSQL databases use flexible data models that can adapt to changes in data
structures and are capable of scaling horizontally to handle growing amounts of
data.

The term NoSQL originally referred to “non-SQL” or “non-relational” databases,


but the term has since evolved to mean “not only SQL,” as NoSQL databases have
expanded to include a wide range of different database architectures and data
models.

NoSQL databases are generally classified into four main categories:

1. Document databases: These databases store data as semi-structured


documents, such as JSON or XML, and can be queried using document-
oriented query languages.

2. Key-value stores: These databases store data as key-value pairs, and are
optimized for simple and fast read/write operations.

3. Column-family stores: These databases store data as column families,


which are sets of columns that are treated as a single entity. They are
optimized for fast and efficient querying of large amounts of data.

4. Graph databases: These databases store data as nodes and edges, and are
designed to handle complex relationships between data.

NoSQL databases are often used in applications where there is a high volume of
data that needs to be processed and analyzed in real-time, such as social media
analytics, e-commerce, and gaming. They can also be used for other applications,
such as content management systems, document management, and customer
relationship management.
Database System

However, NoSQL databases may not be suitable for all applications, as they may
not provide the same level of data consistency and transactional guarantees as
traditional relational databases. It is important to carefully evaluate the specific
needs of an application when choosing a database management system.

Key Features of NoSQL:

1. Dynamic schema: NoSQL databases do not have a fixed schema and can
accommodate changing data structures without the need for migrations or
schema alterations.

2. Horizontal scalability: NoSQL databases are designed to scale out by adding


more nodes to a database cluster, making them well-suited for handling
large amounts of data and high levels of traffic.

3. Document-based: Some NoSQL databases, such as MongoDB, use a


document-based data model, where data is stored in a scalessemi-
structured format, such as JSON or BSON.

4. Key-value-based: Other NoSQL databases, such as Redis, use a key-value


data model, where data is stored as a collection of key-value pairs.

5. Column-based: Some NoSQL databases, such as Cassandra, use a column-


based data model, where data is organized into columns instead of rows.

6. Distributed and high availability: NoSQL databases are often designed to


be highly available and to automatically handle node failures and data
replication across multiple nodes in a database cluster.

7. Flexibility: NoSQL databases allow developers to store and retrieve data in


a flexible and dynamic manner, with support for multiple data types and
changing data structures.

8. Performance: NoSQL databases are optimized for high performance and


can handle a high volume of reads and writes, making them suitable for big
data and real-time applications.
Database System

You might also like