Intro SQL
Intro SQL
By :- PAYAL M. THAKRAR
WHAT IS SQL……
Structured Query Language or SQL is a standard Database language which is used to create,
maintain and retrieve the relational database. It is particularly used to work with structured
data where there is relations associated within the data itself.
• SQL stands for Structured Query Language.
• It is designed for managing data in a relational database management system (RDBMS).
• It is pronounced as S-Q-L or sometime See-Qwell.
• SQL is a database language, it is used for database creation, deletion, fetching rows, and
modifying rows, etc.
• SQL is based on relational algebra and tuple relational calculus.
WHY SQL IS REQUIRED
SQL is required:
To create new databases, tables and views
To insert records in a database
To update records in a database
To delete records from a database
To retrieve data from a database
WHAT SQL DOES
With SQL, we can query our database in several ways, using English-like statements.
With SQL, a user can access data from a relational database management system.
It allows the user to describe the data.
It allows the user to define the data in the database and manipulate it when needed.
It allows the user to create and drop database and table.
It allows the user to create a view, stored procedure, function in a database.
It allows the user to set permission on tables, procedures, and views.
DATA INTEGRITY
There are the following categories of data integrity exist with each RDBMS:
Data Manipulation Language: (DML) It is used to manipulate data in the relations. e.g.;
INSERT, DELETE, UPDATE and so on.
Data Query Language: (DQL)It is used to extract the data from the relations. e.g.; SELECT
SQL SYNTAX
SQL follows some unique set of rules and guidelines called syntax. Here, we are
providing all the basic SQL syntax :-
SQL is not case sensitive. Generally SQL keywords are written in uppercase.
SQL statements are dependent on text lines. We can place a single SQL
statement on one or multiple text lines.
You can perform most of the action in a database with SQL statements.
SQL depends on relational algebra and tuple relational calculus.
SQL STATEMENT
SQL statements are started with any of the SQL
commands/keywords like SELECT, INSERT, UPDATE, DELETE, ALTER,
DROP etc. and the statement ends with a semicolon (;).
Semicolon is used to separate SQL statements. It is a standard way
to separate SQL statements in a database system in which more
than one SQL statements are used in the same call.
TYPES OF SQL STATEMENTS
SQL statements are categorized into four different type of statements, which are
Data types mainly classified into three categories for every database.
It is used to store variable string data within the predefined length. It can
VARCHAR2(size) be stored up to 4000 byte.
It is used to specify single byte or fixed length multibyte national character set
NCLOB
(NCHAR) data. Its range is up to 232-1 bytes or 4 GB.
It is used to specify variable length raw binary data. Its range is up to 2000
RAW(size)
bytes per row. Its maximum size must be specified.
It is used to specify variable length raw binary data. Its range up to 2 31-1 bytes
LONG RAW
or 2 GB, per row.
SQL EXPRESSIONS
An expression is a combination of one or more values, operators, and SQL functions that
evaluate to a value. An expression generally assumes the datatype of its components.
CASE expression
CASE { simple_case_expression
| searched_case_expression
}
[ else_clause ]
END
Compound expression
{ (expr)
| { + | - | PRIOR } expr
| expr { * | / | + | - | || } expr
}
Note: The double vertical bars are part of the syntax
(indicating concatenation) rather than BNF notation.
CURSOR expression
{ (expr)
| { + | - | PRIOR } expr
| expr { * | / | + | - | || } expr
}
Note: The double vertical bars are part of the syntax
(indicating concatenation) rather than BNF notation.
CURSOR expression
CURSOR (subquery)
DATETIME expression
datetime_value_expr AT
{ LOCAL
| TIME ZONE { ' [ + | - ] hh:mm'
| DBTIMEZONE
| 'time_zone_name'
| expr
}
}
Function expression
+ It is used to add containing values of both operands a+b will give 150
- It subtracts right hand operand from left hand operand a-b will give -50
/ It divides left hand operand by right hand operand b/a will give 2
Examines that the left operand value is not less than the
!< (a!<="" td="">
right operand value
ALL this is used to compare a value to all values in another value set.
this operator is used to search for values, that are within a set of
BETWEEN
values
edit, save, load and execute SQL commands and PL/SQL blocks;
list tables structures;
access and transfer data between databases;
implementation of functions for database managing: the users administration,
namespaces table, operations management of archiving and recovery.
SQL * PLUS COMMANDS
ACCEPT - used to read a variable input
DEF (DEFINE) - allow you to declare a variable
DESC (DESCRIBE) - lists the attributes of objects
EDIT - opens an editor
EXIT or QUIT - disconnects the user and SQL * Plus session
GET - searches for a file in SQL
HOST - running an operating system command
LIST - shows the last command executed
PROMPT - displays a text
RUN - lists and runs the command (/)
SAVE - save buffer command into a SQL script file
SET - change environment variables specific to SQL * Plus
SHOW - displays the environment variables settings in SQL * Plus
SPOOL - copies the output of a command to a file
START - run a SQL script
SQL v/s SQL*Plus
It is a language of communication with your Oracle Recognize SQL statements and their transfer to your
server for accessing data. Oracle server.
Process the data and defines the objects from the Not permit the processing of information in the
database. database.
Use the functions to perform formatting. Use the commands for formatting data.