Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

Intro SQL

Uploaded by

shyilisnice
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Intro SQL

Uploaded by

shyilisnice
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

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:

 Entity integrity: It specifies that there should be no duplicate rows in a table.


 Domain integrity: It enforces valid entries for a given column by restricting the type, the
format, or the range of values.
 Referential integrity: It specifies that rows cannot be deleted, which are used by other
records.
 User-defined integrity: It enforces some specific business rules that are defined by users.
These rules are different from entity, domain or referential integrity.
THE QUERIES TO DEAL WITH
RELATIONAL DATABASE ARE
 Data Definition Language: (DDL) It is used to define the structure of the database. e.g;
CREATE TABLE, ADD COLUMN, DROP COLUMN and so on.

 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

 DML (DATA MANIPULATION LANGUAGE)


 DDL (DATA DEFINITION LANGUAGE)
 DCL (DATA CONTROL LANGUAGE)
 TCL (TRANSACTION CONTROL LANGUAGE)
SQL DATA TYPES
Data types are used to represent the nature of the data that can be stored in
the database table. For example, in a particular column of a table, if we want to
store a string type of data then we will have to declare a string data type of this
column.

 Data types mainly classified into three categories for every database.

 String Data types


 Numeric Data types
 Date and time Data types
DATA TYPES IN ORACLE DATABASES
Oracle String data types
It is used to store character data within the predefined length. It can be
CHAR(size) stored up to 2000 bytes.

It is used to store national character data within the predefined length. It


NCHAR(size) can be stored up to 2000 bytes.

It is used to store variable string data within the predefined length. It can
VARCHAR2(size) be stored up to 4000 byte.

It is the same as VARCHAR2(size). You can also use VARCHAR(size), but it


VARCHAR(SIZE) is suggested to use VARCHAR2(size)

It is used to store Unicode string data within the predefined length. We


NVARCHAR2(size) have to must specify the size of NVARCHAR2 data type. It can be stored up
to 4000 bytes.
NUMERIC DATA TYPES
It contains precision p and scale s. The precision p can range from
NUMBER(p, s)
1 to 38, and the scale s can range from -84 to 127.

It is a subtype of the NUMBER data type. The precision p can range


FLOAT(p)
from 1 to 126.

It is used for binary precision( 32-bit). It requires 5 bytes,


BINARY_FLOAT
including length byte.

It is used for double binary precision (64-bit). It requires 9 bytes,


BINARY_DOUBLE
including length byte.
DATE AND TIME DATA TYPES

It is used to store a valid date-time format with a fixed length. Its


DATE
range varies from January 1, 4712 BC to December 31, 9999 AD.

It is used to store the valid date in YYYY-MM-DD with time


TIMESTAMP
hh:mm:ss format.
LARGE OBJECT DATA TYPES (LOB TYPES)
It is used to specify unstructured binary data. Its range goes up to 2 32-1 bytes
BLOB
or 4 GB.
It is used to store binary data in an external file. Its range goes up to 2 32-1
BFILE
bytes or 4 GB.
It is used for single-byte character data. Its range goes up to 2 32-1 bytes or 4
CLOB
GB.

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

any built-in SQL function or user-defined function can be used as an expression


SQL OPERATORS
SQL statements generally contain some reserved words or characters that
are used to perform operations such as comparison and arithmetical
operations etc. These reserved words or characters are known as operators.

 Generally there are three types of operators in SQL:

1.SQL Arithmetic Operators


2.SQL Comparison Operators
3.SQL Logical Operators
SQL ARITHMETIC OPERATORS:
Operators Descriptions Examples

+ 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 multiply both operand's values a*b will give 5000

/ It divides left hand operand by right hand operand b/a will give 2

It divides left hand operand by right hand operand and


% b%a will give 0
returns reminder
SQL COMPARISON OPERATORS:
Operator Description Example

Examine both operands value that are equal or


= (a=b) is not true
not,if yes condition become true.

This is used to check the value of both operands


!= (a!=b) is true
equal or not,if not condition become true.

Examines the operand's value equal or not, if


<> (a<>b) is true
values are not equal condition is true

Examine the left operand value is greater than


> (a>b) is not true
right Operand, if yes condition becomes true
SQL COMPARISON OPERATORS:

Examines that the value of left operand is greater than or


>= equal to the value of right operand or not,if yes condition (a>=b) is not true
become true

Examines that the value of left operand is less than or


<= equal to the value of right operand or not, if yes condition (a<=b) is true
becomes true

Examines that the left operand value is not less than the
!< (a!<="" td="">
right operand value

Examines that the value of left operand is not greater than


!> (a!>b) is true
the value of right operand
SQL LOGICAL OPERATORS:
Operator Description

ALL this is used to compare a value to all values in another value set.

this operator allows the existence of multiple conditions in an SQL


AND
statement.

this operator is used to compare the value in list according to the


ANY
condition.

this operator is used to search for values, that are within a set of
BETWEEN
values

IN this operator is used to compare a value to that specified list value


SQL LOGICAL OPERATORS:
NOT the NOT operator reverse the meaning of any logical operator

OR this operator is used to combine multiple conditions in SQL statements

the EXISTS operator is used to search for the presence of a row in a


EXISTS
specified table

this operator is used to compare a value to similar values using


LIKE
wildcard operator
WHAT IS SQL*PLUS
SQL * Plus is a tool that allows you to interact directly with the
Oracle database.
SQL * Plus is an Oracle command line utility that allows users to
interactively execute SQL and PL/SQL commands.
SQL * Plus enables you to manipulate blocks of SQL and PL / SQL
formatting the query results, to copy data between tables and to
execute SQL and PL / SQL.
OPERATIONS YOU CAN PERFORM IN SQL * PLUS

 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

SQL 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.

 Is an interface specifies the Oracle system for


 Is based on the ANSI SQL standard.
executing SQL statements.

 Process the data and defines the objects from the  Not permit the processing of information in the
database. database.

 Supports the "-" as the character still commands


 Does not have a continuation character.
written on several lines.

 The instructions cannot be abbreviated.  Commands may be abbreviated.

 Use the functions to perform formatting.  Use the commands for formatting data.

 The end of a command is ";"  Requires no end character of a command.

You might also like