SQL JOINS
Miss Bhagyasri G. Patel
Assistant Professor
Comp. Sci. & Engg. Dept
RNGPIT, Bardoli
SQL JOIN
 A JOIN clause is used to combine rows from two or more tables, based on a
related column between them.
SQL JOIN
 Different Types of SQL JOINs
 Here are the different types of the JOINs in SQL:
 (INNER) JOIN: Returns records that have matching values in both tables
 LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records
from the right table
 RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records
from the left table
 FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table
SQL JOIN
SQL INNER JOIN KEYWORD
 The INNER JOIN keyword selects records that have matching values in both tables.
 INNER JOIN Syntax
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
SQL INNER JOIN
ORDER TABLE
CUSTOMER TABLE
Notice that the "CustomerID" column in
the "Orders" table refers to the
"CustomerID" in the "Customers" table.
The relationship between the two tables
above is the "CustomerID" column.
SQL INNER JOIN
 we can create the following SQL statement (that contains an INNER JOIN), that
selects records that have matching values in both tables:
 SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
JOIN THREE TABLES
 The following SQL statement selects all orders with customer and shipper information:
 SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName
FROM ((Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID)
INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID);
SQL LEFT JOIN KEYWORD
 The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the
right table (table2). The result is NULL from the right side, if there is no match.
 Syntax:
 SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
SQL LEFT JOIN KEYWORD
 SQL LEFT JOIN Example
 The following SQL statement will select all customers, and any orders they might have:
 SELECT Customers.CustomerName, Orders.OrderID, Orders.OrderDate
FROM Orders
LEFT JOIN Customers ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
OrderId CustomerName OrderDate
10308 Ana Trujillo Emparedados y helados 1996-09-18
10309 1996-09-19
10310 1996-09-20
SQL RIGHT JOIN KEYWORD
 The RIGHT JOIN keyword returns all records from the right table (table2), and the matched records from the
left table (table1). The result is NULL from the left side, when there is no match.
 Syntax:
 SELECT column_name(s) FROM table1
 RIGHT JOIN table2
 ON table1.column_name = table2.column_name;
SQL RIGHT JOIN KEYWORD
Customers table:
 ORDER Table:
SQL RIGHT JOIN KEYWORD
 SQL RIGHT JOIN Example
 The following SQL statement will return all employees, and any orders they might have placed:
 SELECT Customers.CustomerName, Orders.OrderID, Orders.OrderDate
FROM Orders
RIGHT JOIN Customers ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
OrderId CustomerName OrderDate
Alfreds Futterkiste
10308 Ana Trujillo Emparedados y helados 1996-09-18
Antonio Moreno Taquería
SQL FULL OUTER JOIN KEYWORD
 The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table
records.
 SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;
SQL FULL OUTER JOIN KEYWORD
 The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table records.
 SELECT Customers.CustomerName, Orders.OrderID, Orders.OrderDate
FROM Orders
FULL OUTER JOIN Customers ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
OrderId CustomerName OrderDate
Alfreds Futterkiste
10308 Ana Trujillo Emparedados y helados 1996-09-18
Antonio Moreno Taquería
10309 1996-09-19
10310 1996-09-20
SQL SELF JOIN
 A self JOIN is a regular join, but the table is joined with itself.
 SYNTAX:
 T1 and T2 are different table aliases for the same table.
 SELECT column_name(s)
 FROM table1 T1, table1 T2
 WHERE condition;
SQL SELF JOIN EXAMPLE
 The following SQL statement matches customers that are from the same city:
 SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City
 FROM Customers A, Customers B WHERE A.CustomerID <> B.CustomerID
 AND A.City = B.City ORDER BY A.City;
SQL SELF JOIN
 CUSTOMERS TABLE:
select * from table T1, table2 T2 where T1.column_name1 = T2.column_name2
SQL EQUI-JOIN
 An equi-join is used to match two columns from two tables using explicit operator =:
Example:
Unit_9.pptx
FUNCTIONS
 Functions are very powerful feature of SQL used to manipulate data items .
 SQL functions are built into oracle database and are operated for use in various
appropriate SQL statements.
 If you call a SQL function with a null argument, then the SQL function automatically
returns null. The only SQL functions that do not necessarily follow this behavior
are CONCAT, NVL, REPLACE, and REGEXP_REPLACE.
 Functions are similar to operators in that they manipulate data items and return a
result.
SQL FUNCTION
Functions
Arg 1
arg2
Arg n
Resullt
value
Function performs
action
ADVANTAGES OF FUNCTION
 Function can be used to perform complex calculations on data.
 Functions can modify individual data items
 Function can very easily manipulate output for groups of rows. Function can
manipulate character as well as numeric type of data.
 function can alter date formats for display
TYPES OF FUNCTION
 There are two types of function:
1) Single row functions
2) Multiple row functions
SINGLE ROW FUNCTION
 These function operate on single rows only and return one value for each
row, column name or an expression. Single-row functions can be used in
SELECT. WHERE and ORDER by clauses.
 Syntax of using a single-row function is
 function_name [(arg1, arg2,…..)]
 Where, function_name is the name of the function. arg1,arg2 is any
argument to be used by the function. This can be represented by a user-
supplied constant value, variable value, column name or an expression.
TYPES OF SINGLE ROW FUNCTIONS
There are different types of single row function:
 Character functions
 Number functions/arithmatic functions
 Date functions
 conversion functions
 General functions
 Aggregate functions
TYPES OF SINGLE ROW FUNCTIONS
STRING/CHARACTER FUNCTION
 1.LOWER:- returns char, with all letters in lowercase
Syntax:-lower(char)
e.g. select lower(‘IVAN BAYROSS’)”Lower” from dual;
Output=ivan bayross
2.INITCAP:- returns a string with the first letter of each word in upper case.
Syntax:- initcap(char)
e.g. select initcap(‘IVAN BAYROSS’)”Title case” from dual;
Output=Ivan Bayross
 3.UPPER:- returns char, with all letters in uppercase.
syntax:- upper(char)
e.g. select upper(‘ivan bayross’)”capitalized” from dual;
Output= IVAN BAYROSS
STRING/CHARACTER FUNCTION
4.SUBSTR:-returns a portion of characters beginning at character m, and going up to character n. if
n is omitted the result returned is up to the last character in the string. The first position of char is 1.
Syntax:- substr(<string>,<start_position>,[<length>])
 Where string is source string
 start_position is the position for extraction. The first position in the string is always 1.
 Length is the number of character is extract.
e.g. select substr(“secure”,3,4) ”Substring” from dual;
Output= cure
STRING/CHARACTER FUNCTION
5.ASCII:-returns the number code that represents the specified character. If more
than one character is entered, the function will return the value for the first character
and ignore all the characters after the first.
syntax:-ascii(character)
e.g. select ascii(‘a’) “Ascii 1”, ascii(‘A’)”ascii 2”, ascii(‘cure’)”ascii “ from dual;
ouput= 97 65 99
STRING/CHARACTER FUNCTION
 6.COMPOSE:- return a unicode string. It can be a char, ncahr, nvchar2, clob or nclob.
Syntax:-compose(<single>)
Below it is a listing of unistring values that can be combined with other characters in compose
function.
unistring value resulting character
UNISTR(‘0300’) grave accent(‘)
UNISTR(‘0301’) acute accent(`)
UNISTR(‘0302’) circumflex(^)
UNISTR(‘0303’) tilde(~)
UNISTR(‘0308’) umlauted(“)
STRING/CHARACTER FUNCTION
 7.DECOMPOSE:- accept a string and returns as unicode string.
Syntax:-decompose(<single>)
8. LENGTH:- returns a length of a word.
Syntax:- length(word)
e.g. select length(‘sharanam’) “length” from dual;
Output= 8
STRING/CHARACTER FUNCTION
 9.LTRIM:- returns characters from the left of char with initial characters removed upto the first
character not in set.
Syntax:-ltrim(char[,set])
e.g. select ltrim(‘nisha’,’n’)”ltrim” from dual;
Output= isha
10. RTRIM:- returns char, with final characters removed after the last character not in set. ‘set’ is
optional, it defaults to spaces.
Syntax:- rtim(char[,set])
e.g. select rtrim(‘sunila’,’a’)”rtrim” from dual;
Output= sunil
STRING/CHARACTER FUNCTION
 11. TRIM:- remove all specified character either from beginning or the ending of a string.
Syntax:- trim([leading|trailing|both[<trim_character> from]]<string>)
e.g. select trim(‘ hansel ‘)”trim both side” from dual;
Output=hansel
e.g. select trim(leading ‘x’ from ‘xxxhanselxxx’)”remove prefixes” from dual;
Output= hanselxxx
e.g. select trim(both ‘x’ from ‘xxxhanselxxx’) from dual;
Output=hansel
STRING/CHARACTER FUNCTION
 12.LPAD:- returns char1, left-papped to length n with the sequence of character specified in char2.
Syntax:- lpad(‘char1,n[,char2])
E.g. select lpad(‘page1’,10,’*’)”lpad” from dual;
Output=*****page1
13. RPAD:- returns char1, right papped to length n with the character specified in char2.
Syntax:- rpad(char1,n[,char2])
e.g. select rpad(ivan,10,’x’)”rpad” from dual;
Output=ivanxxxxxx
STRING/CHARACTER FUNCTION
 14. VSIZE:- returns the number of bytes in the internal representation of an expression.
Syntax:- vsize(<expression>)
e.g. select vsize(‘sct on the net’)”size” from dual;
Output= 14
 15. INSTR:- returns a location of a substring in a string.
Syntax:- instr(<string1>,<string2>, [<start_position >], [<nth_appearance>])
e.g. select instr(‘sct on the net’,’t’), instr(‘sct on the net’,’t’,1,2) from dual;
Output= 3 8
STRING/CHARACTER FUNCTION
NUMERIC FUNCTIONS
• 1. ABS:- returns the absolute value of ‘n’.
syntax:- ABS(-15)
e.g. Select ABS(-15) “absolute” from dual;
• 2.POWER:- returns m raised to the nth power. n must be an integer else an error is returned.
syntax:-power(m,n)
e.g. Select power(3,2)”raised” from dual;
 3.Round:-returns n, rounded to m places to the right of the decimal point. If m is omitted, n is
rounded to 0 places, m can be negative to round off digits to the left of the decimal point. m must be an
integer
syntax:-round(n,[m])
e.g. select round(15.91,1) from dual;
output=15.2
4.SQRT:- returns square root of n.
syntax:-sqrt(n)
e.g. select sqrt(25) from dual;
output=5
NUMERIC FUNCTIONS
 5.EXP:-returns e raised t the nth power where e=2.71828183
syntax:- exp(n)
E.g. select exp(5) from dual;
Output=148.413159
 6.EXTRACT:-returns a value extracted from a date or an integer value. A date can be used only to extract
year, month and day, while a timestamp with a time zone data type can be used only to extract timezone_hour and
timezone_minute.
E.g. select extract(year from date ‘2004-07-02’)”year”, extract(month from sysdate)”month” from dual;
Output=2004 7
NUMERIC FUNCTIONS
• 7. GREATEST :- returns a greatest value in a list of expressions.
Syntax:-greatest(expr1,expr2,expr3…expr n)
e.g.:- select greatest(4,5,17)”num”, greatest(‘4’,’5’,’17’)”text” from dual;
output= 17 5
• 8.LEAST:- returns the least value in a list of expressions.
Syntax:- least(expr1,expr2,…..,exprn);
e.g. select least(4,5,17)”num”, least(‘4’,’5’,’17’)”text” from dual;
Output= 4 17
NUMERIC FUNCTIONS
• 9.MOD :-returns the remainder of a first number divided by second number passed a parameter. If the second
number is zero the result of the same as the first number
Syntax:-mod(m,n)
e.g. select mod(15,7)”mod1”, mod(15.7,7)”mod2” from dual;
Output= 1 1.7
• 10.TRUNC:- returns a number truncated to a certain no. of decimal places. The decimal place value is must be an
integer.
Syntax:- trunc(no,[decimal_places])
e.g. select trunc(125.815,1)”trunc1”, trunc(125.815,-2)”trunc2” from dual;
Output= 125.8 100
NUMERIC FUNCTIONS
11. FLOOR:- return a largest integer value that is equal to less than a number.
Syntax:-floor(n)
e.g. select floor(24.8)”flr1”, floor(13.15)”flr2” from dual;
Output=24 13
12.CEIL:-return the smallest integer value that is greater than or equal to a number.
Syntax:-ceil(n)
e.g. select ceil(24.8)”ceil”, ceil(13.15)”ceil2” from dual;
Output= 25 14
NUMERIC FUNCTIONS
CONVERSION FUNCTIONS
 These are functions that help us to convert a value in one form to another form. For
example: a null value into an actual value, or a value from one datatype to another
datatype . Few of the conversion functions available in oracle are:
 TO_CHAR(d,f)
This function converts the date ’d’ to character format ‘f’.
Example:
SELECT SYSDATE, TO_CHAR(SYSDATE,’DAY’) FROM DUAL;
OUTPUT:
SYSDATE TO _CHAR(S
-------------- ------------- ----------------------------------------
03-SEP-13 TUESDAY
 TO_DATE(char,f)
This function converts the character string
representing date into a date format according to
‘f’ format specified. If no format is specified, then
the default format is DD-MON-YY.
Example:
SELECT SYSDATE, TO_DATE(‘JAN2007’,’MONYYYY’)
FROM DUAL;
Output:
SYSDATE TO_DATE(
------------------- ---------------------------
03-SEP-13 01-JAN-07
CONVERSION FUNCTIOSNS
 DECODE(a,b,c,d,e,default_value)
 This function substitutes on a value-by value basis, it actually dows an ‘if-then –else’ test. It checks the value
of ‘a’, if a=b, then returns ‘c’. If a=d, then results ‘e’. Else, returns default value.
Example:
SELECT ENAME, JOB,
DECODE(JOB,’CLERK’,EXECUTIVE’,’MANAGER’,’GM’,’ CASHIER’) FROM EMP;
Output:
ENAME JOB DECODE(JO
- -- - - - - - - - - - - - - - - - - - - - - - - -
SMITH CLERK EXECUTIVE
ALLEN SALESMAN CASHIER
WARD SALESMAN CASHIER
JONES MANAGER GM
CONVERSION FUNCTIOSNS
AGGREGATE FUNCTIONS
• 1.AVG:- returns the average value
syntax:- Select avg(sal) from emp;
• 2.MIN:- return the minimum value of expr.
syntax :-select min(sal) from emp;
• 3.COUNT:- returns the no. of rows where expr. Is not null
syntax:-select count(acct_no) from acct_mstr;
• 4.COUNT(*) :- Returns the no. of rows in a table including duplicates and those with null.
syntax:- select count(*)”no of records” from acct_mstr;
• 5.MAX:- Returns the minimum value of expr.
syntax:-select max(curbal) from acct_mstr;
• 6.SUM:-Returns the sum of the value of ‘n’
syntax:-select sum(curbal) from acct_mstr;
AGGREGATE FUNCTIONS
DATE FUNCTIONS
 Oracle database stores date in an internal numeric format, representing the century ,
Year, month, day hours, minutes, and seconds. The default date display format is
DD_MON_YY.
 Date function operates on oracle dates. These are the function that takes values of
DATE datatype as input and return values of date datatype as output, except for the
MONTHS_BETWEEN function, which returns a number as output. Few date functions
are as given below.
 SYSDATE
SYSDATE is a pseudo-column that returns the system’s current date and time of type DATE.
The SYSDATE can be used just as any other column name. it takes no arguments. When used in
distributed SQL statements, SYSDATE returns the date and time of the local database.
Example:
SELECT SYSDATE FROM DUAL;
output: O3-SEP-13
DATE FUNCTIONS
 ADD_MONTH(d,n)
This function adds or subtract months to or from date, it returns a date as result.
Example:
SELECT SYSDATE, ADD_MONTHS(SYSDATE,4) FROM DUAL;
OUTPUT:
SYSDATE ADD_MONTHS
------------ ------------------
03-APR-13 03-AUG-13
DATE FUNCTIONS
 MONTHS_BETWEEN(d1,d2)
This function returns the number of months between two dates, d1and d2. if d1 is later than
d2, then the result is positive. If d1 is earlier than d2, then the result is negative. The output will be
a number.
Example
SELECT MONTHS_BETWEEN(“25-DEC-81’,25-DEC-79’) AS DATE1, MONTHS_BETWEEN(‘25-DEC-79’,’25-DEC-81’) AS
DATE2 FROM DUAL;
OUTPUT:
DATE1 DATE2
--------- ----------
24 -24
DATE FUNCTIONS
 NEXT_DAY(DATE,DAY)
THIS FUNCTION RETURNS THE DATE OF NEXT SPECIFIED DAY OF THE WEEK AFTER THE ‘DATE’.
EXAMPLE
SELECT SYSDATE, NEXT_DAY(SYSDATE,’FRIDAY) FROM DUAL;
OUTPUT:
SYSDATE NEXT_Day(
------------- ---------------
03-SEP-13 06-SEP-13
DATE FUNCTIONS
 LAST_DAY(d)
This function returns the date of the last day of the month specified. The result will be a date.
Example:
SELECT SYSDATE, LAST_DAY(SYSDATE) FROM DUAL;
OUTPUT:
SYSDATE LAST_DAY(
------------ ---- -------------------
03-SEP-13 30-SEP-13
DATE FUNCTIONS
 ROUND(d[,format])
This function rounds the date d to the unit specified by format. If format is not specified, is
default to ‘DD’ , which rounds d to the nearest day.
Example:
SELECT SYSDATE, ROUND(SYSDATE,’MM’) AS “NEAREST MONTH” FROM DUAL;
OUTPUT:
SYSDATE NEAREST M
-------------- ---------------
03-SEP-13 01-SEP-13
DATE FUNCTIONS
 TRUNC(d[,formt ])
This function returns the date d truncated to the unit specified by format. If
format is omitted, then it defaults to ‘DD’, which truncates d to the nearest day.
Example:
SELECT SYSDATE, TRUNC(SYSDATE,’YEAR’) AS “FIRST DAY” FROM DUAL;
OUTPUT:
SYSDATE FIRST DAY
--------------- ------------------
03-SEP-13 01-JAN-13
DATE FUNCTIONS
 Sometimes the date value is required to be displayed in special format for e.g. instead of 03-jan-81, displays
the date as 3rd of January 1981. for this oracle provides special attributes, which can be used in the format
specified with the to char and to date functions. The significance and use of these characters are explained in
the examples…….
SPECIAL DATE FORMAT USING TO_CHAR FUNCTION
USE OF TH IN THE TO_CHAR() FUNCTION
 DDTH places TH, RD, ND for the date like 2nd, 3rd, 8th etc……
e.g. select cust_no,To_char(dob_inc,’ddth-mon-yy’) “DOB_INC” from cust_master;
OUTPUT====
CUST_NO DOB_INC
C1 25TH-JUN-52
C2 29TH-OCT-82
C3 28TH-OCT-75
C4 02ND-APR-79
…. ………………..
USE OF SP IN THE TO_CHAR() FUNCTION
 indicates that the date(dd) must be displayed by spelling such as one, twelve.
e.g. select cust_no,to_char(dob_inc,’DDSP’)”DOB_DDSP ” from cust_master;
Output=========
CUST_NO DOB_DDSP
C1 TWENTY-FIVE
C2 TWENTY -NINE
C3 TWENTY-EIGHT
C4 TWO
…. ………………..
USE OF SPTH IN THE TO_CHAR FUNCTION
 Displays the date (dd) with th added to the spelling like fourteenth, twelfth.
e.g. select cust_no,to_char(dob_inc,’DDSPTH’)”DOB_D DSPTH” from cust_master;
Output=========
CUST_NO DOB_DDSPTH
C1 TWENTY-FIFTH
C2 TWENTY -NINTH
C3 TWENTY-EIGHTH
C4 SIXTH
…. ………………..
TRANSACTIONAL COMMANDS
 Transaction Control Language(TCL) commands are used to manage transactions in
the database.
 These are used to manage the changes made to the data in a table by DML
statements.
 It also allows statements to be grouped together into logical transactions.
COMMIT COMMAND
 COMMIT command is used to permanently save any transaction into the database.
 When we use any DML command like INSERT, UPDATE or DELETE, the changes made by
these commands are not permanent, until the current session is closed, the changes made
by these commands can be rolled back.
 To avoid that, we use the COMMIT command to mark the changes as permanent.
 Following is commit command's syntax,
 COMMIT;
ROLLBACK COMMAND
 This command restores the database to last commited state. It is also used with
SAVEPOINT command to jump to a savepoint in an ongoing transaction.
 If we have used the UPDATE command to make some changes into the database,
and realise that those changes were not required, then we can use the ROLLBACK
command to rollback those changes, if they were not commited using the COMMIT
command.
 Following is rollback command's syntax,
 ROLLBACK TO savepoint_name;
SAVEPOINT COMMAND
 SAVEPOINT command is used to temporarily save a transaction so that you can
rollback to that point whenever required.
 Following is savepoint command's syntax,
 SAVEPOINT savepoint_name;
 In short, using this command we can name the different states of our data in any
table and then rollback to that state using the ROLLBACK command whenever
required.
USING SAVEPOINT AND ROLLBACK
 Following is the table class,
id name
1 Abhi
2 Adam
4 Alex
USING SAVEPOINT AND
ROLLBACK
 Following is the table class,
id name
1 Abhi
2 Adam
4 Alex
USING SAVEPOINT AND
ROLLBACK
 Following is the table class,
USING SAVEPOINT AND
ROLLBACK
 Following is the table class,

More Related Content

DOCX
SQL report
PPTX
SQL JOIN.pptx
PPTX
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
PPTX
Joins in SQL
PPTX
SQL Class Note By Amit Maity PowerPoint Presentation
DOCX
PPTX
Sql slid
PDF
Structured query language(sql)
SQL report
SQL JOIN.pptx
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
Joins in SQL
SQL Class Note By Amit Maity PowerPoint Presentation
Sql slid
Structured query language(sql)

Similar to Unit_9.pptx (20)

PPTX
DDL,DML,SQL Functions and Joins
PDF
SQL Beginners anishurrehman.cloud.pdf
PPTX
Sql practise for beginners
PPTX
PDF
Assignment 4
PPT
Mysql 120831075600-phpapp01
PDF
SQL Overview
PDF
WORKSHEET SQL SOLVED FOR CLASS XII FINAL
PPTX
Database management Systems : Normalization
PPT
Ms sql server ii
PPTX
DBMS and SQL(structured query language) .pptx
PPT
MY SQL
PPTX
BASICS OF STRUCTURED QUEERY LANGUAGE.PPT
RTF
Sql functions
PDF
1670595076250.pdf
PDF
Cheat sheet SQL commands with examples and easy understanding
PDF
SQL 🌟🌟🔥.pdf
PDF
SQL learning notes and all code.pdf
PDF
Database Management System 1
PDF
Sql basics v2
DDL,DML,SQL Functions and Joins
SQL Beginners anishurrehman.cloud.pdf
Sql practise for beginners
Assignment 4
Mysql 120831075600-phpapp01
SQL Overview
WORKSHEET SQL SOLVED FOR CLASS XII FINAL
Database management Systems : Normalization
Ms sql server ii
DBMS and SQL(structured query language) .pptx
MY SQL
BASICS OF STRUCTURED QUEERY LANGUAGE.PPT
Sql functions
1670595076250.pdf
Cheat sheet SQL commands with examples and easy understanding
SQL 🌟🌟🔥.pdf
SQL learning notes and all code.pdf
Database Management System 1
Sql basics v2
Ad

Recently uploaded (20)

PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PDF
First part_B-Image Processing - 1 of 2).pdf
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Amdahl’s law is explained in the above power point presentations
PPTX
wireless networks, mobile computing.pptx
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PDF
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
PPTX
ai_satellite_crop_management_20250815030350.pptx
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PPTX
Building constraction Conveyance of water.pptx
PDF
Computer System Architecture 3rd Edition-M Morris Mano.pdf
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
Soil Improvement Techniques Note - Rabbi
PDF
Computer organization and architecuture Digital Notes....pdf
PDF
Implantable Drug Delivery System_NDDS_BPHARMACY__SEM VII_PCI .pdf
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
"Array and Linked List in Data Structures with Types, Operations, Implementat...
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
First part_B-Image Processing - 1 of 2).pdf
Management Information system : MIS-e-Business Systems.pptx
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Amdahl’s law is explained in the above power point presentations
wireless networks, mobile computing.pptx
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
MLpara ingenieira CIVIL, meca Y AMBIENTAL
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
ai_satellite_crop_management_20250815030350.pptx
distributed database system" (DDBS) is often used to refer to both the distri...
Building constraction Conveyance of water.pptx
Computer System Architecture 3rd Edition-M Morris Mano.pdf
Abrasive, erosive and cavitation wear.pdf
Soil Improvement Techniques Note - Rabbi
Computer organization and architecuture Digital Notes....pdf
Implantable Drug Delivery System_NDDS_BPHARMACY__SEM VII_PCI .pdf
Ad

Unit_9.pptx

  • 1. SQL JOINS Miss Bhagyasri G. Patel Assistant Professor Comp. Sci. & Engg. Dept RNGPIT, Bardoli
  • 2. SQL JOIN  A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
  • 3. SQL JOIN  Different Types of SQL JOINs  Here are the different types of the JOINs in SQL:  (INNER) JOIN: Returns records that have matching values in both tables  LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table  RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table  FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table
  • 5. SQL INNER JOIN KEYWORD  The INNER JOIN keyword selects records that have matching values in both tables.  INNER JOIN Syntax SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
  • 6. SQL INNER JOIN ORDER TABLE CUSTOMER TABLE Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column.
  • 7. SQL INNER JOIN  we can create the following SQL statement (that contains an INNER JOIN), that selects records that have matching values in both tables:  SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
  • 8. JOIN THREE TABLES  The following SQL statement selects all orders with customer and shipper information:  SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName FROM ((Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID) INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID);
  • 9. SQL LEFT JOIN KEYWORD  The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side, if there is no match.  Syntax:  SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
  • 10. SQL LEFT JOIN KEYWORD  SQL LEFT JOIN Example  The following SQL statement will select all customers, and any orders they might have:  SELECT Customers.CustomerName, Orders.OrderID, Orders.OrderDate FROM Orders LEFT JOIN Customers ON Customers.CustomerID = Orders.CustomerID ORDER BY Customers.CustomerName; OrderId CustomerName OrderDate 10308 Ana Trujillo Emparedados y helados 1996-09-18 10309 1996-09-19 10310 1996-09-20
  • 11. SQL RIGHT JOIN KEYWORD  The RIGHT JOIN keyword returns all records from the right table (table2), and the matched records from the left table (table1). The result is NULL from the left side, when there is no match.  Syntax:  SELECT column_name(s) FROM table1  RIGHT JOIN table2  ON table1.column_name = table2.column_name;
  • 12. SQL RIGHT JOIN KEYWORD Customers table:  ORDER Table:
  • 13. SQL RIGHT JOIN KEYWORD  SQL RIGHT JOIN Example  The following SQL statement will return all employees, and any orders they might have placed:  SELECT Customers.CustomerName, Orders.OrderID, Orders.OrderDate FROM Orders RIGHT JOIN Customers ON Customers.CustomerID = Orders.CustomerID ORDER BY Customers.CustomerName; OrderId CustomerName OrderDate Alfreds Futterkiste 10308 Ana Trujillo Emparedados y helados 1996-09-18 Antonio Moreno Taquería
  • 14. SQL FULL OUTER JOIN KEYWORD  The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table records.  SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name = table2.column_name WHERE condition;
  • 15. SQL FULL OUTER JOIN KEYWORD  The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table records.  SELECT Customers.CustomerName, Orders.OrderID, Orders.OrderDate FROM Orders FULL OUTER JOIN Customers ON Customers.CustomerID = Orders.CustomerID ORDER BY Customers.CustomerName; OrderId CustomerName OrderDate Alfreds Futterkiste 10308 Ana Trujillo Emparedados y helados 1996-09-18 Antonio Moreno Taquería 10309 1996-09-19 10310 1996-09-20
  • 16. SQL SELF JOIN  A self JOIN is a regular join, but the table is joined with itself.  SYNTAX:  T1 and T2 are different table aliases for the same table.  SELECT column_name(s)  FROM table1 T1, table1 T2  WHERE condition;
  • 17. SQL SELF JOIN EXAMPLE  The following SQL statement matches customers that are from the same city:  SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City  FROM Customers A, Customers B WHERE A.CustomerID <> B.CustomerID  AND A.City = B.City ORDER BY A.City;
  • 18. SQL SELF JOIN  CUSTOMERS TABLE:
  • 19. select * from table T1, table2 T2 where T1.column_name1 = T2.column_name2 SQL EQUI-JOIN  An equi-join is used to match two columns from two tables using explicit operator =: Example:
  • 21. FUNCTIONS  Functions are very powerful feature of SQL used to manipulate data items .  SQL functions are built into oracle database and are operated for use in various appropriate SQL statements.  If you call a SQL function with a null argument, then the SQL function automatically returns null. The only SQL functions that do not necessarily follow this behavior are CONCAT, NVL, REPLACE, and REGEXP_REPLACE.  Functions are similar to operators in that they manipulate data items and return a result.
  • 22. SQL FUNCTION Functions Arg 1 arg2 Arg n Resullt value Function performs action
  • 23. ADVANTAGES OF FUNCTION  Function can be used to perform complex calculations on data.  Functions can modify individual data items  Function can very easily manipulate output for groups of rows. Function can manipulate character as well as numeric type of data.  function can alter date formats for display
  • 24. TYPES OF FUNCTION  There are two types of function: 1) Single row functions 2) Multiple row functions
  • 25. SINGLE ROW FUNCTION  These function operate on single rows only and return one value for each row, column name or an expression. Single-row functions can be used in SELECT. WHERE and ORDER by clauses.  Syntax of using a single-row function is  function_name [(arg1, arg2,…..)]  Where, function_name is the name of the function. arg1,arg2 is any argument to be used by the function. This can be represented by a user- supplied constant value, variable value, column name or an expression.
  • 26. TYPES OF SINGLE ROW FUNCTIONS There are different types of single row function:  Character functions  Number functions/arithmatic functions  Date functions  conversion functions  General functions  Aggregate functions
  • 27. TYPES OF SINGLE ROW FUNCTIONS
  • 28. STRING/CHARACTER FUNCTION  1.LOWER:- returns char, with all letters in lowercase Syntax:-lower(char) e.g. select lower(‘IVAN BAYROSS’)”Lower” from dual; Output=ivan bayross 2.INITCAP:- returns a string with the first letter of each word in upper case. Syntax:- initcap(char) e.g. select initcap(‘IVAN BAYROSS’)”Title case” from dual; Output=Ivan Bayross
  • 29.  3.UPPER:- returns char, with all letters in uppercase. syntax:- upper(char) e.g. select upper(‘ivan bayross’)”capitalized” from dual; Output= IVAN BAYROSS STRING/CHARACTER FUNCTION
  • 30. 4.SUBSTR:-returns a portion of characters beginning at character m, and going up to character n. if n is omitted the result returned is up to the last character in the string. The first position of char is 1. Syntax:- substr(<string>,<start_position>,[<length>])  Where string is source string  start_position is the position for extraction. The first position in the string is always 1.  Length is the number of character is extract. e.g. select substr(“secure”,3,4) ”Substring” from dual; Output= cure STRING/CHARACTER FUNCTION
  • 31. 5.ASCII:-returns the number code that represents the specified character. If more than one character is entered, the function will return the value for the first character and ignore all the characters after the first. syntax:-ascii(character) e.g. select ascii(‘a’) “Ascii 1”, ascii(‘A’)”ascii 2”, ascii(‘cure’)”ascii “ from dual; ouput= 97 65 99 STRING/CHARACTER FUNCTION
  • 32.  6.COMPOSE:- return a unicode string. It can be a char, ncahr, nvchar2, clob or nclob. Syntax:-compose(<single>) Below it is a listing of unistring values that can be combined with other characters in compose function. unistring value resulting character UNISTR(‘0300’) grave accent(‘) UNISTR(‘0301’) acute accent(`) UNISTR(‘0302’) circumflex(^) UNISTR(‘0303’) tilde(~) UNISTR(‘0308’) umlauted(“) STRING/CHARACTER FUNCTION
  • 33.  7.DECOMPOSE:- accept a string and returns as unicode string. Syntax:-decompose(<single>) 8. LENGTH:- returns a length of a word. Syntax:- length(word) e.g. select length(‘sharanam’) “length” from dual; Output= 8 STRING/CHARACTER FUNCTION
  • 34.  9.LTRIM:- returns characters from the left of char with initial characters removed upto the first character not in set. Syntax:-ltrim(char[,set]) e.g. select ltrim(‘nisha’,’n’)”ltrim” from dual; Output= isha 10. RTRIM:- returns char, with final characters removed after the last character not in set. ‘set’ is optional, it defaults to spaces. Syntax:- rtim(char[,set]) e.g. select rtrim(‘sunila’,’a’)”rtrim” from dual; Output= sunil STRING/CHARACTER FUNCTION
  • 35.  11. TRIM:- remove all specified character either from beginning or the ending of a string. Syntax:- trim([leading|trailing|both[<trim_character> from]]<string>) e.g. select trim(‘ hansel ‘)”trim both side” from dual; Output=hansel e.g. select trim(leading ‘x’ from ‘xxxhanselxxx’)”remove prefixes” from dual; Output= hanselxxx e.g. select trim(both ‘x’ from ‘xxxhanselxxx’) from dual; Output=hansel STRING/CHARACTER FUNCTION
  • 36.  12.LPAD:- returns char1, left-papped to length n with the sequence of character specified in char2. Syntax:- lpad(‘char1,n[,char2]) E.g. select lpad(‘page1’,10,’*’)”lpad” from dual; Output=*****page1 13. RPAD:- returns char1, right papped to length n with the character specified in char2. Syntax:- rpad(char1,n[,char2]) e.g. select rpad(ivan,10,’x’)”rpad” from dual; Output=ivanxxxxxx STRING/CHARACTER FUNCTION
  • 37.  14. VSIZE:- returns the number of bytes in the internal representation of an expression. Syntax:- vsize(<expression>) e.g. select vsize(‘sct on the net’)”size” from dual; Output= 14  15. INSTR:- returns a location of a substring in a string. Syntax:- instr(<string1>,<string2>, [<start_position >], [<nth_appearance>]) e.g. select instr(‘sct on the net’,’t’), instr(‘sct on the net’,’t’,1,2) from dual; Output= 3 8 STRING/CHARACTER FUNCTION
  • 38. NUMERIC FUNCTIONS • 1. ABS:- returns the absolute value of ‘n’. syntax:- ABS(-15) e.g. Select ABS(-15) “absolute” from dual; • 2.POWER:- returns m raised to the nth power. n must be an integer else an error is returned. syntax:-power(m,n) e.g. Select power(3,2)”raised” from dual;
  • 39.  3.Round:-returns n, rounded to m places to the right of the decimal point. If m is omitted, n is rounded to 0 places, m can be negative to round off digits to the left of the decimal point. m must be an integer syntax:-round(n,[m]) e.g. select round(15.91,1) from dual; output=15.2 4.SQRT:- returns square root of n. syntax:-sqrt(n) e.g. select sqrt(25) from dual; output=5 NUMERIC FUNCTIONS
  • 40.  5.EXP:-returns e raised t the nth power where e=2.71828183 syntax:- exp(n) E.g. select exp(5) from dual; Output=148.413159  6.EXTRACT:-returns a value extracted from a date or an integer value. A date can be used only to extract year, month and day, while a timestamp with a time zone data type can be used only to extract timezone_hour and timezone_minute. E.g. select extract(year from date ‘2004-07-02’)”year”, extract(month from sysdate)”month” from dual; Output=2004 7 NUMERIC FUNCTIONS
  • 41. • 7. GREATEST :- returns a greatest value in a list of expressions. Syntax:-greatest(expr1,expr2,expr3…expr n) e.g.:- select greatest(4,5,17)”num”, greatest(‘4’,’5’,’17’)”text” from dual; output= 17 5 • 8.LEAST:- returns the least value in a list of expressions. Syntax:- least(expr1,expr2,…..,exprn); e.g. select least(4,5,17)”num”, least(‘4’,’5’,’17’)”text” from dual; Output= 4 17 NUMERIC FUNCTIONS
  • 42. • 9.MOD :-returns the remainder of a first number divided by second number passed a parameter. If the second number is zero the result of the same as the first number Syntax:-mod(m,n) e.g. select mod(15,7)”mod1”, mod(15.7,7)”mod2” from dual; Output= 1 1.7 • 10.TRUNC:- returns a number truncated to a certain no. of decimal places. The decimal place value is must be an integer. Syntax:- trunc(no,[decimal_places]) e.g. select trunc(125.815,1)”trunc1”, trunc(125.815,-2)”trunc2” from dual; Output= 125.8 100 NUMERIC FUNCTIONS
  • 43. 11. FLOOR:- return a largest integer value that is equal to less than a number. Syntax:-floor(n) e.g. select floor(24.8)”flr1”, floor(13.15)”flr2” from dual; Output=24 13 12.CEIL:-return the smallest integer value that is greater than or equal to a number. Syntax:-ceil(n) e.g. select ceil(24.8)”ceil”, ceil(13.15)”ceil2” from dual; Output= 25 14 NUMERIC FUNCTIONS
  • 44. CONVERSION FUNCTIONS  These are functions that help us to convert a value in one form to another form. For example: a null value into an actual value, or a value from one datatype to another datatype . Few of the conversion functions available in oracle are:  TO_CHAR(d,f) This function converts the date ’d’ to character format ‘f’. Example: SELECT SYSDATE, TO_CHAR(SYSDATE,’DAY’) FROM DUAL; OUTPUT: SYSDATE TO _CHAR(S -------------- ------------- ---------------------------------------- 03-SEP-13 TUESDAY
  • 45.  TO_DATE(char,f) This function converts the character string representing date into a date format according to ‘f’ format specified. If no format is specified, then the default format is DD-MON-YY. Example: SELECT SYSDATE, TO_DATE(‘JAN2007’,’MONYYYY’) FROM DUAL; Output: SYSDATE TO_DATE( ------------------- --------------------------- 03-SEP-13 01-JAN-07 CONVERSION FUNCTIOSNS
  • 46.  DECODE(a,b,c,d,e,default_value)  This function substitutes on a value-by value basis, it actually dows an ‘if-then –else’ test. It checks the value of ‘a’, if a=b, then returns ‘c’. If a=d, then results ‘e’. Else, returns default value. Example: SELECT ENAME, JOB, DECODE(JOB,’CLERK’,EXECUTIVE’,’MANAGER’,’GM’,’ CASHIER’) FROM EMP; Output: ENAME JOB DECODE(JO - -- - - - - - - - - - - - - - - - - - - - - - - - SMITH CLERK EXECUTIVE ALLEN SALESMAN CASHIER WARD SALESMAN CASHIER JONES MANAGER GM CONVERSION FUNCTIOSNS
  • 47. AGGREGATE FUNCTIONS • 1.AVG:- returns the average value syntax:- Select avg(sal) from emp; • 2.MIN:- return the minimum value of expr. syntax :-select min(sal) from emp; • 3.COUNT:- returns the no. of rows where expr. Is not null syntax:-select count(acct_no) from acct_mstr;
  • 48. • 4.COUNT(*) :- Returns the no. of rows in a table including duplicates and those with null. syntax:- select count(*)”no of records” from acct_mstr; • 5.MAX:- Returns the minimum value of expr. syntax:-select max(curbal) from acct_mstr; • 6.SUM:-Returns the sum of the value of ‘n’ syntax:-select sum(curbal) from acct_mstr; AGGREGATE FUNCTIONS
  • 49. DATE FUNCTIONS  Oracle database stores date in an internal numeric format, representing the century , Year, month, day hours, minutes, and seconds. The default date display format is DD_MON_YY.  Date function operates on oracle dates. These are the function that takes values of DATE datatype as input and return values of date datatype as output, except for the MONTHS_BETWEEN function, which returns a number as output. Few date functions are as given below.
  • 50.  SYSDATE SYSDATE is a pseudo-column that returns the system’s current date and time of type DATE. The SYSDATE can be used just as any other column name. it takes no arguments. When used in distributed SQL statements, SYSDATE returns the date and time of the local database. Example: SELECT SYSDATE FROM DUAL; output: O3-SEP-13 DATE FUNCTIONS
  • 51.  ADD_MONTH(d,n) This function adds or subtract months to or from date, it returns a date as result. Example: SELECT SYSDATE, ADD_MONTHS(SYSDATE,4) FROM DUAL; OUTPUT: SYSDATE ADD_MONTHS ------------ ------------------ 03-APR-13 03-AUG-13 DATE FUNCTIONS
  • 52.  MONTHS_BETWEEN(d1,d2) This function returns the number of months between two dates, d1and d2. if d1 is later than d2, then the result is positive. If d1 is earlier than d2, then the result is negative. The output will be a number. Example SELECT MONTHS_BETWEEN(“25-DEC-81’,25-DEC-79’) AS DATE1, MONTHS_BETWEEN(‘25-DEC-79’,’25-DEC-81’) AS DATE2 FROM DUAL; OUTPUT: DATE1 DATE2 --------- ---------- 24 -24 DATE FUNCTIONS
  • 53.  NEXT_DAY(DATE,DAY) THIS FUNCTION RETURNS THE DATE OF NEXT SPECIFIED DAY OF THE WEEK AFTER THE ‘DATE’. EXAMPLE SELECT SYSDATE, NEXT_DAY(SYSDATE,’FRIDAY) FROM DUAL; OUTPUT: SYSDATE NEXT_Day( ------------- --------------- 03-SEP-13 06-SEP-13 DATE FUNCTIONS
  • 54.  LAST_DAY(d) This function returns the date of the last day of the month specified. The result will be a date. Example: SELECT SYSDATE, LAST_DAY(SYSDATE) FROM DUAL; OUTPUT: SYSDATE LAST_DAY( ------------ ---- ------------------- 03-SEP-13 30-SEP-13 DATE FUNCTIONS
  • 55.  ROUND(d[,format]) This function rounds the date d to the unit specified by format. If format is not specified, is default to ‘DD’ , which rounds d to the nearest day. Example: SELECT SYSDATE, ROUND(SYSDATE,’MM’) AS “NEAREST MONTH” FROM DUAL; OUTPUT: SYSDATE NEAREST M -------------- --------------- 03-SEP-13 01-SEP-13 DATE FUNCTIONS
  • 56.  TRUNC(d[,formt ]) This function returns the date d truncated to the unit specified by format. If format is omitted, then it defaults to ‘DD’, which truncates d to the nearest day. Example: SELECT SYSDATE, TRUNC(SYSDATE,’YEAR’) AS “FIRST DAY” FROM DUAL; OUTPUT: SYSDATE FIRST DAY --------------- ------------------ 03-SEP-13 01-JAN-13 DATE FUNCTIONS
  • 57.  Sometimes the date value is required to be displayed in special format for e.g. instead of 03-jan-81, displays the date as 3rd of January 1981. for this oracle provides special attributes, which can be used in the format specified with the to char and to date functions. The significance and use of these characters are explained in the examples……. SPECIAL DATE FORMAT USING TO_CHAR FUNCTION
  • 58. USE OF TH IN THE TO_CHAR() FUNCTION  DDTH places TH, RD, ND for the date like 2nd, 3rd, 8th etc…… e.g. select cust_no,To_char(dob_inc,’ddth-mon-yy’) “DOB_INC” from cust_master; OUTPUT==== CUST_NO DOB_INC C1 25TH-JUN-52 C2 29TH-OCT-82 C3 28TH-OCT-75 C4 02ND-APR-79 …. ………………..
  • 59. USE OF SP IN THE TO_CHAR() FUNCTION  indicates that the date(dd) must be displayed by spelling such as one, twelve. e.g. select cust_no,to_char(dob_inc,’DDSP’)”DOB_DDSP ” from cust_master; Output========= CUST_NO DOB_DDSP C1 TWENTY-FIVE C2 TWENTY -NINE C3 TWENTY-EIGHT C4 TWO …. ………………..
  • 60. USE OF SPTH IN THE TO_CHAR FUNCTION  Displays the date (dd) with th added to the spelling like fourteenth, twelfth. e.g. select cust_no,to_char(dob_inc,’DDSPTH’)”DOB_D DSPTH” from cust_master; Output========= CUST_NO DOB_DDSPTH C1 TWENTY-FIFTH C2 TWENTY -NINTH C3 TWENTY-EIGHTH C4 SIXTH …. ………………..
  • 61. TRANSACTIONAL COMMANDS  Transaction Control Language(TCL) commands are used to manage transactions in the database.  These are used to manage the changes made to the data in a table by DML statements.  It also allows statements to be grouped together into logical transactions.
  • 62. COMMIT COMMAND  COMMIT command is used to permanently save any transaction into the database.  When we use any DML command like INSERT, UPDATE or DELETE, the changes made by these commands are not permanent, until the current session is closed, the changes made by these commands can be rolled back.  To avoid that, we use the COMMIT command to mark the changes as permanent.  Following is commit command's syntax,  COMMIT;
  • 63. ROLLBACK COMMAND  This command restores the database to last commited state. It is also used with SAVEPOINT command to jump to a savepoint in an ongoing transaction.  If we have used the UPDATE command to make some changes into the database, and realise that those changes were not required, then we can use the ROLLBACK command to rollback those changes, if they were not commited using the COMMIT command.  Following is rollback command's syntax,  ROLLBACK TO savepoint_name;
  • 64. SAVEPOINT COMMAND  SAVEPOINT command is used to temporarily save a transaction so that you can rollback to that point whenever required.  Following is savepoint command's syntax,  SAVEPOINT savepoint_name;  In short, using this command we can name the different states of our data in any table and then rollback to that state using the ROLLBACK command whenever required.
  • 65. USING SAVEPOINT AND ROLLBACK  Following is the table class, id name 1 Abhi 2 Adam 4 Alex
  • 66. USING SAVEPOINT AND ROLLBACK  Following is the table class, id name 1 Abhi 2 Adam 4 Alex
  • 67. USING SAVEPOINT AND ROLLBACK  Following is the table class,
  • 68. USING SAVEPOINT AND ROLLBACK  Following is the table class,

Editor's Notes

  • #2: Delete this slide when you finish preparing the other slides.