Está en la página 1de 10


SQL fully abbreviated as Structured Query Language can be defined as a domain-specific language
used to manage the relational databases and performs different operations on the data stored in
them. It has been designed for the purpose of data management that is kept in a Relational Database
Management System (RDBMS), or for the processing of stream data in a Relational Data Stream
Management System (RDSMS).

SQL is used by all the relational database management systems like Oracle, Informix, Posgres,
SQL server, MySQL, MS Access, and Sybase as their standard database language.

The SQL programming language was originally developed on the basis of tuple relational
calculus and relational algebra. The major components of this language include the following:

 Data definition language

 Data manipulation language
 Data Control Language.

The areas within which SQL programming language can be used include data insertion, update,
query, and delete, data access control, and modification and creation of schema. Even though
SQL programming language is regarded as a declarative language to a great extent, but it also
consists of some procedural elements.

History of SQL
Raymond F. Boyce and Donald D. Chamberlin started the initial development of SQL at IBM in
the beginning of the 1970s. The early version of the language, which was referred to as SEQUEL
(short form for Structured English Query Language), was developed for the purpose of
manipulating and retrieving the data that was stored on System R, which was quasi-relational
and original database management system of IBM.

This system was developed by a group of individuals at San Jose Research Laboratory of IBM
during the era of 1970s. The name of this version was later changed from SEQUEL to SQL. This
is because the name “SEQUEL” was already trademarked by Hawker Siddeley, which was an
aircraft company based in the United Kingdom.

Relational Software, Inc., which is now famous as Oracle Corporation, realized the abilities of
the concepts and ideas presented by Boyce, and Codd, Chamberlin. As a result, the company
began working on the development of its own RDBMS, which was based on SQL, at the end of

The company had an aim of selling this system to the Central Intelligence Agency, U.S. Navy,
and other prominent agencies of U.S. government. The first implementation of SQL, which was
available commercially, was released by Relational Software, Inc. in June 1979. It was named
Oracle Version 2 (V2) and it operate on VAX computers. IBM conducted various tests of SQL at
customer sites so as to identify the degree of practicality and usefulness of this system. The
company that started developing products, such as SQL/DS, DB2, and System/38, for
commercial purposes. These products were based on the prototype of system R.

Applications of SQL (Structured Query Language)

Have a look at some main SQL applications:

 Data Integration Scripts: The main application of SQL is to write data integration scripts by the
database administrators and developers.

 Analytical Queries: The data analysts use structured query language for setting and running
analytical queries on a regular basis.

 Retrieve Information: Another popular application of this language is to retrieve the subsets of
information within a database for analytics applications and transaction processing. The most
commonly used SQL elements are select, insert, update, add, delete, create, truncate and alter.

 Other Important Applications: The SQL is used for modification of the index structures and
database table. Additionally, the users can add, update and delete the rows of the data by using
this language.

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.

 High Performance.
 High Availability.
 Scalability and Flexibility
 Robust Transactional Support.
 High Security.
 Comprehensive Application Development.
 Management Ease.
 Open Source.
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:







The commands can be classified into the following groups based on their nature:

1.3.1DDL - Data Definition Language

1) CREATE TABLE: The create table command is used to create tables.


name TEXT,

2) ALTER TABLE: The alter table command is used to modify the structure of a table. This is
slightly limited, as your database will not let you alter a table if the existing data would cause a
conflict. Changing a string to an integer, for example. In those instances, fix the data first, then
modify the table. Here’s an example:
ALTER TABLE people ADD height integer;

3) DROP TABLE: Think of this as delete, but rather than deleting a single record, it removes
every single record along with the table. Here’s how you use it:

DROP TABLE people;

1.3.2 DML - Data Manipulation Language

1) SELECT: As its name implies, select is used to select data from a database. Here’s the
simplest usage:

SELECT * FROM table;

There are two parts to this. The first part (SELECT *) specifies which columns you would like
to select. The asterisk indicates that you wish to select all the columns in the table. The second
part (FROM table) tells your database engine where you would like to retrieve this data from.
Replace “table” with the name of your database table.

You can explicitly state which columns you would like to retrieve, like this:
SELECT age, name FROM people;

This query retrieves the “age” and “name” columns from the “people” table. Being this explicit
can be slightly tedious if you have a lot of data, but doing so will reduce problems in the future,
along with making your SQL easier to understand by any future programmers.

If you want to select an additional piece of data, but it’s not stored in any of your tables, you can
do that like this:

SELECT age, '1234' FROM people;

2) INSERT: You now know all about retrieving data from a database, but what about inserting
it? This is where the insert command comes in. Here’s an example:

INSERT INTO people(name, age) VALUES('Joe', 102);

You have to specify the table name (people), and the columns you wish to use (name and age).
The “VALUES” syntax is then used to provide the values to insert. These have to be in the same
order as the columns which were previously specified.

3) UPDATE : After inserting some data, it’s only natural to need to change specific rows. Here’s
the update command syntax:

UPDATE people SET name = 'Joe', age = 101;

You have to specify the table you wish to change, and then use the “SET” syntax to specify the
columns and their new values. This example is good, but it will update every single record —
something that’s not always desirable!

4) UPSERT: Upsert is a strange sounding word, but it is an incredibly useful command. Say
you have a constraint on your table, and you’ve specified that you only ever want records with
unique names — you don’t want to store two rows with the same name, for example. If you tried
to insert multiple values of ‘Joe’, your database engine would throw an error and refuse to do it
(quite rightly). An UPSERT allows you to update a record if it already exists. This is incredibly
useful! Without this command, you would have to write a lot of logic to first check if a record
exists, insert if it does not, otherwise retrieve the correct primary key and then update.

Unfortunately, upserts are implemented differently in different database engines. PostgreSQL

has only recently gained this ability, whereas MySQL has had it for quite a while. Here’s the
MySQL syntax for reference:

INSERT INTO people(name, age)

VALUES('Joe', 101)

5) DELETE: Delete is used to remove records entirely — it can be quite damaging if abused!
The basic syntax is very easy to use:

Like most of the other commands, this will delete everything! You need to use a where to restrict
it to a slightly more sane number of rows — ideally one:

DELETE FROM people WHERE name = 'Joe';

6) ORDER: The order command is used to sort the results returned. It’s another easy one to use.
Simply append it to the end of your statement:

SELECT name, age FROM people ORDER BY age DESC;

7) JOIN: The join command is used to join related data stored in one or more tables. You join
the second table to the first table, and specify how the data is connected. Here’s a basic example:

SELECT age, name, height FROM people LEFT JOIN heights USING (name);

8) UNION: Union is a great command. It allows you to append rows to each other. Unlike joins
which append matching columns, union can append unrelated rows provided they have the same
number and name of columns. Here’s how you use it:

SELECT age, name FROM customers

SELECT age, name FROM staff;

1.3.3 DCL - Data Control Language

GRANT Gives a privilege to user.
REVOKE Takes back privileges granted from user.

SQL Constraints
Constraints are the rules enforced on data columns on a table. These are used to limit the type of
data that can go into a table. This ensures the accuracy and reliability of the data in the database.
Constraints can either be column level or table level. Column level constraints are applied only to
one column whereas, table level constraints are applied to the entire table. Following are some of
the most commonly used constraints available in SQL
Following are some of the most commonly used constraints available in SQL:
 NOT NULL Constraint: Ensures that a column cannot have a NULL value.
 DEFAULT Constraint: Provides a default value for a column when none is specified.
 UNIQUE Constraint: Ensures that all the values in a column are different.
 PRIMARY Key: Uniquely identifies each row/record in a database table.
 FOREIGN Key: Uniquely identifies a row/record in any another database table.
 CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy
 certain conditions.
 INDEX: Used to create and retrieve data from the database very quickly.

What is an Operator in SQL?

An operator is a reserved word or a character used primarily in an SQL statement's WHERE clause
to perform operation(s), such as comparisons and arithmetic operations. These Operators are used
to specify conditions in an SQL statement and to serve as conjunctions for multiple conditions in
a statement.
 Arithmetic operators
 Comparison operators
 Logical operators
 Operators used to negate conditions
+ Addition - Adds values on a + b will
either side of the operator. give 30
- Subtraction - Subtracts right a - b will
hand operand from left hand give -10
* Multiplication - Multiplies a * b will
values on either side of the give 200
/ Division - Divides left hand b / a will
operand by right hand give 2
% Modulus - Divides left hand b % a will
operand by right hand give 0
and returns remainder.
offers six categories of data types for your use which are listed below –
5.1 Exact Numeric Data Types
Bigint 9,223,372,036,854,775,808 9,223,372,036,854,775,807
Int -2,147,483,648 2,147,483,647
smallint -32,768 32,767
Tinyint 0 255
Bit 0 1
decimal -10^38 +1 10^38 -1
numeric -10^38 +1 10^38 -1
Money -922,337,203,685,477.5808 +922,337,203,685,477.5807
Smallmoney -214,748.3648 +214,748.3647

5.2 Date and Time Data Types

datetime Jan 1, 1753 Dec 31, 9999
smalldatetime Jan 1, 1900 Jun 6, 2079

Note − Here, datetime has 3.33 milliseconds accuracy where as smalldatetime has 1minute accuracy

5.3 Character Strings Data Types

char Maximum length of 8,000 characters.( Fixed
length non-Unicode data)
varchar Maximum of 8,000 characters.(Variable-length
non-Unicode data)
text Variable-length non-Unicode data with a
maximum length of 2,147,483,647 characters.


There are numerous advantages of Structured Query Language and some of them are mentioned
 No coding needed: It is very easy to manage the database systems without any need to write
the substantial amount of code by using the standard SQL.

 Well defined standards: Long established are used by the SQL databases that is being used by
ISO and ANSI. There are no standards adhered by the non-SQL databases.

 Portability: SQL can be used in the program in PCs, servers, laptops, and even some of the
mobile phones.

 Interactive Language: This domain language can be used for communicating with the databases
and receive answers to the complex questions in seconds.

 Multiple data views: With the help of SQL language, the users can make different views of
database structure and databases for the different users.
 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.
 * Emergence of ORDBMS: Previously SQL databases were synonymous with relational database.
With the emergence of ObjectOriented DBMS, object storage capabilities areextended to
relational databases.

Disadvantages of SQL

Along with some benefits, the Structured query language also has some certain disadvantages:

 Difficult Interface: SQL has a complex interface that makes it difficult for some users to access it.

 Partial Control: The programmers who use SQL doesn’t have a full control over the database
because of the hidden business rules.

 Implementation: Some of the databases go to the proprietary extensions to standard SQL for
ensuring the vendor lock-in.

 Cost: The operating cost of some SQL versions makes it difficult for some programmers to access

Over the years, SQL has become one of the most widely used database languages in the world. It
has become a standard for the International Organization for Standardization and American
National Stands Institute

i) SQL Queries can be used to retrieve large amounts of records from a database quickly and

ii) SQL is used to view the data without storing the data into the object.

iii) SQL joins two or more tables and show it as one object to user.

iv) SQL databases use long-established standard, which is being adopted by ANSI & ISO.
Non-SQL databases do not adhere to any clear standard.

v) Using standard SQL it is easier to manage database systems without having to write
substantial amount of code.

vi) SQL restricts the access of a table so that nobody can insert the rows into the table.