0% found this document useful (0 votes)
489 views9 pages

Unit 4

SQL is a standard language used to create and manipulate databases. It allows users to define, manipulate, and retrieve data stored in databases. SQL became a standard in 1986 by ANSI and 1987 by ISO. There are several types of SQL commands including DDL, DML, DQL, TCL, and DCL. SQL provides advantages like high speed data retrieval, well defined standards, and no coding required. Database backups are essential to restore data after damage or deletion and help in disaster recovery.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
489 views9 pages

Unit 4

SQL is a standard language used to create and manipulate databases. It allows users to define, manipulate, and retrieve data stored in databases. SQL became a standard in 1986 by ANSI and 1987 by ISO. There are several types of SQL commands including DDL, DML, DQL, TCL, and DCL. SQL provides advantages like high speed data retrieval, well defined standards, and no coding required. Database backups are essential to restore data after damage or deletion and help in disaster recovery.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1.What is SQL?

SQL stands for Structured Query Language. SQL lets you access and manipulate


databases. SQL became a standard of the American National Standards Institute (ANSI) in
1986, and of the International Organization for Standardization (ISO) in 1987.
2.Give the types of SQL commands.
 Data Definition Language (DDL)
 Data Manipulation Language (DML)
 Data Query Language (DQL)
 Transaction Control Language (TCL)
 Data Control Language (DCL)
 3.Define Table.
 In relational databases, and flat file databases, a table is a set of data elements (values) using a model of vertical columns
(identifiable by name) and horizontal rows, the cell being the unit where a row and column intersect. A table has a specified number of
columns, but can have any number of rows.
 4.Define Queries.
 A query is an inquiry into the database using the SELECT statement. A query is used to extract data from the database in a
readable format according to the user's request. For instance, if you have an employee table, you might issue a SQL statement that returns
the employee who is paid the most
 5.What is meant by sub queries?
 A subquery can return a set of rows or just one row to its parent query. A scalarsubquery is a query that returns exactly one
value: a single row, with a single column. Scalar subqueries can be used in most places in a SQL statement where you could use an
expression or a literal value.

6.List out the characteristics of SQL.


7.What is the importance of backups?
Backups help to restore computer devices during the process of disaster recovery and restore data after files have undergone damage or
deletion. Database backupsare essential for protection against data loss that can completely disrupt business operations.

SQL is a language to operate databases; it includes database creation,


deletion, fetching rows, modifying rows, etc. SQL is an ANSI (American
National Standards Institute) standard language, but there are many
different versions of the SQL language.

What is SQL?
SQL is Structured Query Language, which is a computer language for
storing, manipulating and retrieving data stored in a relational database.
SQL is the standard language for Relational Database System. All the
Relational Database Management Systems (RDMS) like MySQL, MS Access,
Oracle, Sybase, Informix, Postgres and SQL Server use SQL as their
standard database language.
Also, they are using different dialects, such as −

 MS SQL Server using T-SQL,


 Oracle using PL/SQL,
 MS Access version of SQL is called JET SQL (native format) etc.
Why SQL?
SQL is widely popular because it offers the following advantages −
 Allows users to access data in the relational database management
systems.
 Allows users to describe the data.
 Allows users to define the data in a database and manipulate that
data.
 Allows to embed within other languages using SQL modules, libraries
& pre-compilers.
 Allows users to create and drop databases and tables.
 Allows users to create view, stored procedure, functions in a database.
 Allows users to set permissions on tables, procedures and views.

A Brief History of SQL


 1970 − Dr. Edgar F. "Ted" Codd of IBM is known as the father of
relational databases. He described a relational model for databases.
 1974 − Structured Query Language appeared.
 1978 − IBM worked to develop Codd's ideas and released a product
named System/R.
 1986 − IBM developed the first prototype of relational database and
standardized by ANSI. The first relational database was released by
Relational Software which later came to be known as Oracle.

SQL Process
When you are executing an SQL command for any RDBMS, the system
determines the best way to carry out your request and SQL engine figures
out how to interpret the task.
There are various components included in this process.
These components are −

 Query Dispatcher
 Optimization Engines
 Classic Query Engine
 SQL Query Engine, etc.
A classic query engine handles all the non-SQL queries, but a SQL query
engine won't handle logical files.
Following is a simple diagram showing the SQL Architecture −
SQL Commands
The standard SQL commands to interact with relational databases are
CREATE, SELECT, INSERT, UPDATE, DELETE and DROP. These commands
can be classified into the following groups based on their nature −

DDL - Data Definition Language


Sr.No Command & Description
.

CREATE

1 Creates a new table, a view


of a table, or other object
in the database.

ALTER
Modifies an existing
2
database object, such as a
table.
DROP
Deletes an entire table, a
3
view of a table or other
objects in the database.

DML - Data Manipulation Language


Sr.No Command & Description
.

SELECT
1 Retrieves certain records
from one or more tables.

INSERT
2
Creates a record.

UPDATE
3
Modifies records.

DELETE
4
Deletes records.

DCL - Data Control Language


Sr.No Command & Description
.

GRANT
1
Gives a privilege to user.

REVOKE
2 Takes back privileges
granted from user.

Characteristics of SQL:

* SQL is an ANSI and ISO standard computer language 


for creating and manipulating databases.
* SQL allows the user to create, update, delete, and 
retrieve data from a database.
*SQL is very simple and easy to learn.
*SQL works with database programs like DB2, Oracle, 
MS Access, Sybase, MS SQL Sever etc

Advantages of SQL:

* High Speed: 
SQL Queries can be used to retrieve large amounts of
records from a database quickly and efficiently.
* Well Defined Standards Exist:
SQL databases use long-established standard,
which is being adopted by ANSI & ISO. Non-SQL
databases do not adhere to any clear standard.
* No Coding Required:
Using standard SQL it is easier to manage database 
systems without having to write substantial amount 
of code.
* Emergence of ORDBMS:
Previously SQL databases were synonymous with 
relational database. With the emergence of Object
Oriented DBMS, object storage capabilities are
extended to relational databases.

Disadvantages of SQL:

* Difficulty in Interfacing:
Interfacing an SQL database is more complex than
adding a few lines of code.
* More Features Implemented in Proprietary way:
Although SQL databases conform to ANSI & ISO 
standards, some databases go for proprietary
extensions to standard SQL to ensure vendor lock-in.

RECOVERY TECHNIQUES:
Crash Recovery
DBMS is a highly complex system with hundreds of transactions being
executed every second. The durability and robustness of a DBMS depends
on its complex architecture and its underlying hardware and system
software. If it fails or crashes amid transactions, it is expected that the
system would follow some sort of algorithm or techniques to recover lost
data.

Failure Classification
To see where the problem has occurred, we generalize a failure into various
categories, as follows −

Transaction failure
A transaction has to abort when it fails to execute or when it reaches a
point from where it can’t go any further. This is called transaction failure
where only a few transactions or processes are hurt.
Reasons for a transaction failure could be −
 Logical errors − Where a transaction cannot complete because it has
some code error or any internal error condition.
 System errors − Where the database system itself terminates an
active transaction because the DBMS is not able to execute it, or it
has to stop because of some system condition. For example, in case
of deadlock or resource unavailability, the system aborts an active
transaction.

System Crash
There are problems − external to the system − that may cause the system
to stop abruptly and cause the system to crash. For example, interruptions
in power supply may cause the failure of underlying hardware or software
failure.
Examples may include operating system errors.

Disk Failure
In early days of technology evolution, it was a common problem where
hard-disk drives or storage drives used to fail frequently.
Disk failures include formation of bad sectors, unreachability to the disk,
disk head crash or any other failure, which destroys all or a part of disk
storage.

Storage Structure
We have already described the storage system. In brief, the storage
structure can be divided into two categories −
 Volatile storage − As the name suggests, a volatile storage cannot
survive system crashes. Volatile storage devices are placed very close
to the CPU; normally they are embedded onto the chipset itself. For
example, main memory and cache memory are examples of volatile
storage. They are fast but can store only a small amount of
information.
 Non-volatile storage − These memories are made to survive system
crashes. They are huge in data storage capacity, but slower in
accessibility. Examples may include hard-disks, magnetic tapes, flash
memory, and non-volatile (battery backed up) RAM.

Recovery and Atomicity


When a system crashes, it may have several transactions being executed
and various files opened for them to modify the data items. Transactions
are made of various operations, which are atomic in nature. But according
to ACID properties of DBMS, atomicity of transactions as a whole must be
maintained, that is, either all the operations are executed or none.
When a DBMS recovers from a crash, it should maintain the following −
 It should check the states of all the transactions, which were being
executed.
 A transaction may be in the middle of some operation; the DBMS must
ensure the atomicity of the transaction in this case.
 It should check whether the transaction can be completed now or it
needs to be rolled back.
 No transactions would be allowed to leave the DBMS in an inconsistent
state.
There are two types of techniques, which can help a DBMS in recovering as
well as maintaining the atomicity of a transaction −
 Maintaining the logs of each transaction, and writing them onto some
stable storage before actually modifying the database.
 Maintaining shadow paging, where the changes are done on a volatile
memory, and later, the actual database is updated.

Log-based Recovery
Log is a sequence of records, which maintains the records of actions
performed by a transaction. It is important that the logs are written prior to
the actual modification and stored on a stable storage media, which is
failsafe.
Log-based recovery works as follows −
 The log file is kept on a stable storage media.
 When a transaction enters the system and starts execution, it writes a
log about it.
<Tn, Start>
 When the transaction modifies an item X, it write logs as follows −
<Tn, X, V1, V2>
It reads Tn has changed the value of X, from V1 to V2.

 When the transaction finishes, it logs −


<Tn, commit>
The database can be modified using two approaches −
 Deferred database modification − All logs are written on to the
stable storage and the database is updated when a transaction
commits.
 Immediate database modification − Each log follows an actual
database modification. That is, the database is modified immediately
after every operation.

Recovery with Concurrent Transactions


When more than one transaction are being executed in parallel, the logs are
interleaved. At the time of recovery, it would become hard for the recovery
system to backtrack all logs, and then start recovering. To ease this
situation, most modern DBMS use the concept of 'checkpoints'.

Checkpoint
Keeping and maintaining logs in real time and in real environment may fill
out all the memory space available in the system. As time passes, the log
file may grow too big to be handled at all. Checkpoint is a mechanism
where all the previous logs are removed from the system and stored
permanently in a storage disk. Checkpoint declares a point before which the
DBMS was in consistent state, and all the transactions were committed.

Recovery
When a system with concurrent transactions crashes and recovers, it
behaves in the following manner −
 The recovery system reads the logs backwards from the end to the
last checkpoint.
 It maintains two lists, an undo-list and a redo-list.
 If the recovery system sees a log with <T n, Start> and <Tn, Commit>
or just <Tn, Commit>, it puts the transaction in the redo-list.
 If the recovery system sees a log with <T n, Start> but no commit or
abort log found, it puts the transaction in undo-list.
All the transactions in the undo-list are then undone and their logs are
removed. All the transactions in the redo-list and their previous logs are
removed and then redone before saving their logs.

You might also like