Chapter 4 - Structured Query Language - (SQL)
Chapter 4 - Structured Query Language - (SQL)
SQL
● SQL stands for Structured Query Language. It is used for storing and managing data in a
● It is a standard language for Relational Database System. It enables a user to create, read,
● All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server use SQL as their
● SQL allows users to query the database in a number of ways, using English-like statements.
Rules:
SQL follows the following rules:
● Structure query language is not case sensitive. Generally, keywords of SQL are written in
uppercase.
● Statements of SQL are dependent on text lines. We can use a single SQL statement on one or
● Using SQL statements, you can perform most of the actions in a database.
Characteristics of SQL
● SQL is easy to learn.
● SQL is used to define the data in the database and manipulate it when needed.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Subject : DBMS Class : SE SEM: IV Dr.Anirudh Mangore
Chapter : 4
Structured Query Language (SQL)
-----------------------------------------------------------------------------------------------------------------------------------------
SQL process:
● When an SQL command is executing for any RDBMS, then the system figure out the best way to
carry out the request and the SQL engine determines that how to interpret the task.
● In the process, various components are included. These components can be optimization
● All the non-SQL queries are handled by the classic query engine, but SQL query engine won't
-----------------------------------------------------------------------------------------------------------------------------------------------------
Subject : DBMS Class : SE SEM: IV Dr.Anirudh Mangore
Chapter : 4
Structured Query Language (SQL)
-----------------------------------------------------------------------------------------------------------------------------------------
Advantages of SQL
There are the following advantages of SQL:
High speed
Using the SQL queries, the user can quickly and efficiently retrieve a large amount of records from a
database.
No coding needed
In the standard SQL, it is very easy to manage the database system. It doesn't require a substantial
amount of code to manage the database system.
Portability
SQL can be used in laptop, PCs, server and even some mobile phones.
Interactive language
SQL is a domain language used to communicate with the database. It is also used to receive answers
to the complex questions in seconds.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Subject : DBMS Class : SE SEM: IV Dr.Anirudh Mangore
Chapter : 4
Structured Query Language (SQL)
-----------------------------------------------------------------------------------------------------------------------------------------
SQL Datatype
● SQL Datatype is used to define the values that a column can contain.
● Every column is required to have a name and data type in the database table.
Datatype of SQL:
1. Binary Datatypes
There are Three types of binary Datatypes which are given below:
binary It has a maximum length of 8000 bytes. It contains fixed-length binary data.
varbinary It has a maximum length of 8000 bytes. It contains variable-length binary data.
image It has a maximum length of 2,147,483,647 bytes. It contains variable-length binary data.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Subject : DBMS Class : SE SEM: IV Dr.Anirudh Mangore
Chapter : 4
Structured Query Language (SQL)
-----------------------------------------------------------------------------------------------------------------------------------------
2. Approximate Numeric Datatype :
The subtypes are given below:
float -1.79E + 308 1.79E + 308 It is used to specify a floating-point value e.g. 6.2, 2.9 etc.
Data Description
type
char It has a maximum length of 8000 characters. It contains Fixed-length non-unicode characters.
varchar It has a maximum length of 8000 characters. It contains variable-length non-unicode characters.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Subject : DBMS Class : SE SEM: IV Dr.Anirudh Mangore
Chapter : 4
Structured Query Language (SQL)
-----------------------------------------------------------------------------------------------------------------------------------------
5. Date and time Datatypes
The subtypes are given below:
Datatype Description
timestamp It stores the year, month, day, hour, minute, and the second value.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Subject : DBMS Class : SE SEM: IV Dr.Anirudh Mangore
Chapter : 4
Structured Query Language (SQL)
-----------------------------------------------------------------------------------------------------------------------------------------
SQL Operator
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.
There are various types of SQL operator:
- It is used to subtract the right-hand operand from the left-hand operand. a-b will give 10
* It is used to multiply the value of both operands. a*b will give 200
/ It is used to divide the left-hand operand by the right-hand operand. a/b will give 2
% It is used to divide the left-hand operand by the right-hand operand and a%b will give 0
returns reminder.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Subject : DBMS Class : SE SEM: IV Dr.Anirudh Mangore
Chapter : 4
Structured Query Language (SQL)
-----------------------------------------------------------------------------------------------------------------------------------------
SQL Comparison Operators:
Let's assume 'variable a' and 'variable b'. Here, 'a' contains 20 and 'b' contains 10.
= It checks if two operands values are equal or not, if the values are (a=b) is not true
queal then condition becomes true.
!= It checks if two operands values are equal or not, if values are not (a!=b) is true
equal, then condition becomes true.
<> It checks if two operands values are equal or not, if values are not (a<>b) is true
equal then condition becomes true.
> It checks if the left operand value is greater than right operand value, (a>b) is not true
if yes then condition becomes true.
< It checks if the left operand value is less than right operand value, if (a<b) is true
yes then condition becomes true.
>= It checks if the left operand value is greater than or equal to the right (a>=b) is not true
operand value, if yes then condition becomes true.
<= It checks if the left operand value is less than or equal to the right (a<=b) is true
operand value, if yes then condition becomes true.
!< It checks if the left operand value is not less than the right operand (a!=b) is not true
value, if yes then condition becomes true.
!> It checks if the left operand value is not greater than the right operand (a!>b) is true
value, if yes then condition becomes true.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Subject : DBMS Class : SE SEM: IV Dr.Anirudh Mangore
Chapter : 4
Structured Query Language (SQL)
-----------------------------------------------------------------------------------------------------------------------------------------
SQL Logical Operators
There is the list of logical operator used in SQL:
Operator Description
BETWEEN It is used to search for values that are within a set of values.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Subject : DBMS Class : SE SEM: IV Dr.Anirudh Mangore