Structured Query Language
Structured Query Language
Components of SQL
Security is the priority, and DCL commands like GRANT and REVOKE control access
permissions, ensuring that only authorized users enter the gates.
This is the directing body, TCL commands COMMIT and ROLLBACK manage the
flow of transactions, ensuring data integrity.
SQL Commands
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.
WHERE condition
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
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.
• Subqueries allow you to use the results of another query in the outer
query.
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.
• MIN and MAX return the lowest and highest values in a particular column,
respectively.
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
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
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.
What is Recovery?
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.
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.
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.
2. Key-value stores: These databases store data as key-value pairs, and are
optimized for simple and fast read/write operations.
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.
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.