Anda di halaman 1dari 141

° 

°  



||   |
 |
° 

‡ COALESCE ‡ Partitioned Outer Join


‡ CASE enhanced ‡ MEDIAN Function
‡ JOINS syntax ‡ FLASH BACK ± VERSIONS
‡ FULL OUTER JOIN ‡ MODEL clause
‡ FLASHBACK ± AS OF Functions CV() ,
‡ DEFAULT keyword PRESENTV(),
‡ INSERT ± Multi-table ± Direct Path PRESENTNNV(),
‡ MERGE ITERATION_NUMBER
‡ Date Data types ‡ MERGE ± DELETE clause
TIMESTAMP,
TIMESTAMP WITH TIME ZONE,
TIMESTAMP WITH LOCAL TIME ZONE
‡ DATETIME functions
TZ_OFFSET, CURRENT_DATE,
LOCALTIMESTAMP
‡ Multi-Table Insert
Un-conditional, Conditional ALL, FIRST
‡ Create Index with create table statement
||   |
| |
° 

 


°  
 

 °
 
°
 


 
  
 
 
  
  

°! 

 
 
 
 
   
 
 

"

°# $°

%  
%
° 
&  & '%( )  
*  °!#

+
  &

* 
$
 

||   |
 |
° 

!" # "

||   |
|
° 

$

Ë Every Organization had some information needs.


Ë Organizations can store µpieces of information¶ called DATA.
Ë Data stored in different formats, hard copy document, electronic spread
sheet or in database.
Ë A database is an organized collection of information.
Ë DBMS a program that stores retrieves and modifies data in the database
on request.
Ë Types of Database ± Hierarchical, Network, Relational, Object Relational.

||   |
 |
° 

ÿ 

%&  !'
 () * 
+" " + " ""#
,-.  + " #"" "
$

!'
$#  /,.0 $ " () *

,.0  + " +,-


,120%))",%12%-"+"
",1-

"3 ","!"#43,!5
+,1-""67+  )$# "676
66|"666

||   |
 |
° 

0 "$ " 

Ë Dr. EF. Codd proposed the relational model for database systems in 1970,
³A Relational Model of data for Large Shared Data Banks´.
Ë It is the basis for RDBMS
Ë The Relational model consists of the following :
- Collection of objects or relations.
- Set of operators to act on the relations.
- Data Integrity for accuracy and consistency.
Ë Definition :
A relational database is a collection of relations or
two-dimensional tables (rows & columns).

||   |
8 |
° 

%"0 " 

Ë Entity / Table : A thing of significance about which information needs to be
known.
e.g. Employees, Departments, Students, and Orders.
Ë Attribute / Column : Something that qualifies an entity. eg. eno, ename, ordno.,
Ë Relationship : Association between entities showing cardinality / degree.

EMPLOYEES DEPARTMENTS
number number
name name
job title location

Scenario:
- ³ « assign one or more employees to a department«´
- ³ « some departments do not yet have assigned employees«´

||   |
7 |
° 

%"0 " 
" "" "
Entity - Table Attribute - Column
Soft box Singular name
Singular, unique name Lowercase
Uppercase Mandatory marked with *
Synonym in parentheses Optional marked with o

EMPLOYEE DEPARTMENT
assigned to
# * number # * number
* name * name
composed of
o job title o location

Unique Identifier UID Relationships


Primary marked with # Dashed Line Optional ³may be´
Secondary marked with (#) Solid line Mandatory ³must be´
Crow¶s foot Degree element ³one or more´
Single line ³one and only one´
||   |
6 |
° 

0 "$9"  
Primary Key Column Non-key value Foreign Key

ENO ENAME SALARY COMM_PCT DNO


100 King 24000 90

Row / Record 101 Kochhar 17000 90


102 Rey 6000 null 60
103 DeCarl 3500 50
104 Abel 11000 .3 80
105 Grant 7000 .15 80
106 Reyarndo 8300 110

field

||   |
 |
° 




Model of system
in client¶s mind

Entity model of
client¶s model

Table model of
Oracle Server
entity model

Tables on disk

||   |
 |
° 

:0'
, :$/"0 "
'
"",

Ë Relational model and Object Relational model.


Ë User-defined data types and objects.
Ë Fully compatible with relational database.
Ë High-quality database server features.

||   |
| |
° 

#:7`
 


    Ô  

Oracle Product Non-Oracle Product


SQL, PL/SQL, Developer, Forms ... Java, XML, HTML ...
||   |
 |
° 

#:6`

Two Tier Three Tier


 

—  
 

Oracle Product Non-Oracle Product


SQL, PL/SQL, Developer, Forms ... Java, XML, HTML ...
||   |
 |
° 

,#

, ,,

   

X A 
||   |
 |
° 

#"")0'
,#",1-

SQL Statement SELE T last_name


is entered FROM employees;

LAST_NAME
Statement is sent
to Oracle Server
King
Kochhar
Oracle Server
Reynardo
DeCarl
Abel
Grant
Rey
||   |
 |
° 

,1-,"
p 



p  


p



 p
  !
"#!
#
"#
$%&
 '
(!p

pp   
pp

 
 p$! # (#

) 


$" $

&% *!$"##"$#

p
p

'# *$%

 + ++



"$# 
,

||   |
8 |
° 

Ë Improved performance and functionality of


On-Line Transaction Processing OLTP
Ë Operating within the Network Computing Architecture (NCA)
frame work, supports
Client-Server (TCP-IP) and
Web-based applications (HTTP)
Ë 10,000 concurrent users, support upto 512 Peta-bytes of data
( 1 Peta-byte is 1,000 Tera-bytes)
Ë Support of Multimedia and Large OBjects

||   |
7 |
° 

,#

Ë Relational databases are composed of relations, managed by


relational operations, and governed by data integrity
constraints.
Ë The Oracle is the database for Internet Computing and
based on the ORDBMS.
Ë Oracle Server supports ANSI standard SQL and contains
extensions.
Ë SQL is the language used to communicate with the server to
access, manipulate, and control data.

||   |
6 |
° 

;"',1-
SELE T ,"

||   |
| |
° 

 $ +,1-SELE T ,"


Table A Projection Table B Selection

Joins

Table A Table B

||   |
| |
° 

' SELE T ,"

SELE T *|{[DISTIN T] column|expression [ alias],«}


FROM table;

SELE T identifies what column(s)


FROM identifies which table

," #"

SELE T *
FROM departments;

||   |
|| |
° 

,", + #"


SELE T department_id, location_id
FROM departments;

;",1-,"

Ë ,1-,"" "
Ë ,1-""$ " "  "
Ë <) "" $$$   "
Ë ###  " "

||   |
| |
° 

%=  "


=  ")"#$"$#"
 

SELE T last_name, salary, salary+300


FROM employees;

:   "

SELE T last_name,salary,12*salary+300,12+salary*300
FROM employees;

:#$#"
"
12*(salary+300)

||   |
| |
° 

+""3#>#
Ë 32--##"$#""#"*" )"
" $
Ë "#" ?  $"* 
Ë =  " """"### "#

ENO ENAME SALARY COMM COMM+1 DNO


100 King 24000 .3 1.3 90
101 Kochhar 17000 90
102 Ernst 6000 60
103 Rajs 3500 50
104 Abel 11000 .5 1.5 80
105 Grant 7000 .15 1.15 40
106 Gietz 8300 110
||   |
| |
° 

+"" #"
Ë 0" #""
Ë !#+#)# "
Ë !+  ) #""AS *) "$
 "$)" #"""
Ë 0@# #$@#  "*+ ""  
  "

SELE T last_name AS name, commission_pct comm


FROM employees;

SELE T last_name AS ³Name´, salary*12 ³Annual Salary´


FROM employees;

||   |
| |
° 

"" ":  


Ë "" #" "   #"

Ë ! "$) $AA

SELE T last_name||job_id AS ³Employees´


FROM employees;

Ë "##$" )"
"@#  "*

Ë %" # # "+  )#"

SELE T last_name||¶ is a µ||job_id AS ³Employees´


FROM employees;

||   |
|8 |
° 

# 0 )
Ë 9+#  +@# )"#"#  )

SELE T department_id
FROM employees;

Ë %"#  )$#"DISTIN T or UNIQUE


*) "SELE T #
You cannot specify
SELE T DISTIN T department_id DISTIN T if the
FROM employees; select_list contains
LOB columns.

 9$,##
DES [RIE] tablename;

DES RIE employees; DES employees;

||   |
|7 |
° 

,#
SELE T statement
- Returns all rows and columns from a table
- Returns specified columns from a table
- Uses column aliases to give descriptive column headings

To write, save, execute the SQL statements


use the `RSQLPlus environment, SQL WorkSheet.

SELE T *|{[DISTIN T] column|expression [ alias],«}


FROM table;

||   |
|6 |
° 

0"", "

||   |
 |
° 

-"0 )#", "

9WHERE #+  )FROM #

SELE T *|{[DISTIN T] column|expression [ alias],«}


FROM table
[ WHERE condition(s) ];

Ë È   " "6B


SELE T employee_id, last_name, department_id
FROM employees
WHERE department_id = 90;

||   |
 |
° 

,""
Ë ""#" ""
@#  "*
Ë # ""
#+  "
Ë 9+#+ 
:3 00

SELE T employee_id, last_name, department_id


FROM employees
WHERE last_name = µAdam¶;

||   |
| |
° 

  " " "


Ë 2" " "   "=  " " 
# =  "

SELE T employee_id, last_name, department_id


FROM employees
WHERE last_name = µAdam¶;

WHERE hire_date = ¶01-Jan-95¶ ;


WHERE salary >= 6000 ;
WHERE department_id <> 80 ; ë C

||   |
 |
° 

ETWEEN " "


Ë 2ETWEEN  " "   )$ "
" +#
SELE T employee_id, last_name, salary
FROM employees
WHERE salary ETWEEN 2500 AND 3500 ;

- ) 2 

IN " "
Ë 2IN $  " " + #"

SELE T employee_id, last_name, salary, manager_id


FROM employees
WHERE manager_id IN (100, 101, 201) ;

||   |
 |
° 

LIKE " "


Ë LIKE  " "  + ) +
"#
Ë " "" "#$
D" ?  "
E" ""

SELE T employee_id, last_name


FROM employees
WHERE last_name LIKE µS%¶;

Ë 2ES APE "+ + 


#D"E$ 
SELE T employee_id, last_name, job_id
FROM employees
WHERE job_id LIKE µSA\_%¶ ES APE µ\¶;

||   |
 |
° 

2"NULL " "


Ë 9+ "#)IS NULL  

SELE T employee_id, last_name, manager_id


FROM employees
WHERE manager_id IS NULL;

-  " "


AND 0#"TRUE +‰    "" " "#

OR 0#"TRUE +? ?   "" " "#

NOT 0#"TRUE ++  )" " "+

||   |
 |
° 

2"AND :  
Ë AND @#$  " " $#

SELE T employee_id, last_name, job_id, salary


FROM employees
WHERE salary >= 10000
AND job_id LIKE µ%MAN%¶;

2"OR :  
Ë OR @# " " $#

SELE T employee_id, last_name, job_id, salary


FROM employees
WHERE salary >= 10000
OR job_id LIKE µ%MAN%¶;

||   |
8 |
° 

2"NOT :  
SELE T employee_id, last_name, job_id
FROM employees
WHERE job_id NOT IN (µIT_PROG¶, µST_ LERK¶);

0# + "
1 Arithmetic operators
2 Concatenation operators
3 Comparison Conditions
4 IS [NOT] NULL, LIKE, [NOT] IN
5 [NOT] ETWEEN
6 NOT logical condition
7 AND logical condition
8 OR logical condition
Override rules of precedence by using parentheses
||   |
7 |
° 

0# + "

SELE T last_name, job_id, salary


FROM employees
WHERE job_id = µSA_REP¶
OR job_id = µAD_PRES¶
AND salary > 15000;

Select the row if an employee is AD_PRES and earns more than


15000, or if the employee is a SA_REP

SELE T last_name, job_id, salary


FROM employees
WHERE (job_id = µSA_REP¶
OR job_id = µAD_PRES¶)
AND salary > 15000;

Select the row if an employee is AD_PRES or SA_REP , and if the


employee earns more than 15000.

||   |
6 |
° 

ORDER Y #
Ë ,  ))ORDER Y #

AS "" +#
DES "" 

Ë 9ORDER Y # "SELE T "

SELE T employee_id, last_name, job_id, salary


FROM employees
ORDER Y hire_date;

ORDER Y salary DES ;

||   |
 |
° 

, "$ #"
SELE T employee_id, last_name, salary*12 annsal
FROM employees
ORDER Y annsal ;

, "$ #"  "


SELE T employee_id, last_name, salary*12 annsal
FROM employees
ORDER Y 3 ;

, "$
#  #"
SELE T last_name, department_id, salary
FROM employees
ORDER Y department_id, salary DES ;

Ë † #V   $ #"" "SELE T 

||   |
 |
° 

,#
Ë 2WHERE #  ) + # #
2   " " "
2'%9;%%3!3-!<%"32-- " "
  3:0"3:9  

Ë 2ORDER Y #   ) + # #

SELE T *|{[DISTIN T] column|expression [ alias],«}


FROM table
[ WHERE condition(s) ]
[ORDER Y {column, expr, alias} [AS |DES ]];

||   |
| |
° 

 -./) 

||   |
 |
° 

,1-&#" "
!" #

&#" " :# #

&#" "#"
arg 1 #
arg 2
arg n Result value

&#" "

Single-row Multiple-row
functions functions
!" # :# # !" # :# #

||   |
|
° 

," 0 )&#" "


Ë
" #
Ë  #""#" "#
Ë  " )#"
Ë 0#" "#  )
Ë  " #. # #@#+ 
Ë "$"
Ë  #")"$ #" "=  "

åunction_name [(arg1, arg2,«)];

||   |
 |
° 

&#" "

Ë  " # "+#" "


LOWER(µHello angalore¶) hello bangalore
UPPER(µHello angalore¶) HELLO ANGALORE
INIT AP(µHeLlo angAlore¶) Hello angalore

SELE T employee_id, last_name, department_id


FROM employees
WHERE lower(last_name) = µabel¶;

||   |
 |
° 

&#" "
Ë  " # "+#" "
ON AT(µHello¶, ¶World¶) HelloWorld
SUSTR(µHelloWorld,1,5) Hello
LENGTH(µHelloWorld¶) 10
INSTR(µHelloWorld¶,¶o¶) 5
LPAD(salary,10,¶*¶) *****24000
RPAD(salary,8,¶#¶) 9900####
WHERE SOUNDEX(city) = SOUNDEX(µSidny¶)
RTRIM(¶AMERI A¶, µA¶) AMERI
LTRIM(¶AMERI A¶, µA¶) MERI A

TRIM(µH¶ FROM ¶HelloWorld¶) elloWorld


TRIM(µA¶ FROM ¶AMERI A¶) MERI

||   |
8 |
° 

3#$&#" "
AS(-6) 6
AS(6) 6
EIL(1.4) 2
FLOOR(1.6) 1
SIGN(-25) -1
SIGN(25) 1
SQRT(36) 6
VSIZE(city) ± The storage size in bytes

For any datatype :


GREATEST(10,45,100,1) 100
LEAST(10,45,100,1) 1

||   |
7 |
° 

3#$&#" "
Ë ROUND ›0 #"#  +
SELE T ROUND(45.923,2),ROUND(45.923,0),ROUND(45.923,-1)
FROM DUAL;

6| 
2-#$ #"# )#+ +#" ""# "

Ë TRUN ›9#"#  +


SELE T TRUN (45.923,2),TRUN (45.923),TRUN (45.923,-2)
FROM DUAL;
6| 
Ë MOD ›0#"" + "
SELE T MOD(10,3), MOD(10,7)

FROM DUAL;

||   |
6 |
° 

; *")
Ë :$ """""#+ 
"#†
"F #
"#, "
% G" ||

†
 F
,
|      

Ë +# + 


:3 00

Ë >:$)"
G"# 8|' "$6666

Ë ,†,9%+#" "#"#"$
"9
SELE T SYSDATE
FROM DUAL;

||   |
 |
° 

)

Ë H3#$  "#$ +


Ë I 3#$  ,#$"#$ +
Ë I  "  + ,#$ "+ 
" 
Ë H3#$.|  "#$ + # 


SELE T last_name, (SYSDATE-hire_date)/7 as WEEKS


FROM employees
WHERE department-id = 90;

||   |
 |
° 

Ë +#" "
MONTHS_ETWEEN(¶15-NOV-05¶,¶01-SEP-05¶) -> 1.5
ADD_MONTHS(¶11-JAN-95¶,6) -> ¶11-JUL-95¶
NEXT_DAY(¶01-JUN-05¶,¶FRIDAY¶) -> ¶03-JUN-05¶
LAST_DAY(¶18-FE-08¶) -> ¶29-FE-08¶

Ë #,†,9% J| G2- JK


ROUND(SYSDATE, µMONTH¶) -> 01-Aug-05
ROUND(SYSDATE, µYEAR¶) -> 01-Jan-06
TRUN (SYSDATE, µMONTH¶) -> 01-Jul-05
TRUN (SYSDATE, µYEAR¶) -> 01-Jan-05

||   |
| |
° 

 /) 
Ë ! 9  " "

Ë %= 9  " "

TO_NUMER TO_DATE

NUMER ÿ DATE

TO_ HAR TO_ HAR

SELE T employee_id, TO_ HAR (hire_date,¶MM/YY¶)


FROM employees;

||   |
 |
° 

%" +& 



YYYY / +0

YEAR ,1

MM .-1  +2

MONTH /+2+2

MON 2-00  2+2

DY 2-00  212.3

DAY /+212.3

DD #+ )12+2

WW W 43+2

RM +#+0

J 5 162+01 )7 p)8 7&


||   |
 |
° 

%" +& 



SELE T to_char(sysdate,¶DD-Mon-YYYY HH24:MI:SS AM¶)
FROM dual;

DD ³oå´ MONTH 4 oå October


DDth 4th
DDsp FOUR
Ddspth Fourth

SELE T last_name,
to_char(hire_date,¶åmDD Mon YYYY¶) Hiredate
FROM employees;

||   |
 |
° 

2"TO_ HAR +#" ")"#$

SELE T last_name,
TO_ HAR(salary,¶L9,999,999.99¶) Sal
FROM employees;

6 0 ""#$
 + ?  $ 
L + " "
- 2+ " #"$ 
 " "
 " #"" 

||   |
 |
° 

M"&#" "
Ë These function work with any data type and pertain to using nulls.
NVL +#" "
Ë Converts a null to an actual value
- Data type must match
NVL(commission_pct,0)
NVL(hire_date,¶01-Jan-05¶)
NVL(job_id,¶No Job Yet¶)

NVL2 +#" "


Ë NVL2(expr1, expr2, expr3)
- examine the expr1, if expr1 is null returns expr3,
if expr1 is not null returns expr2
NVL2(commission_pct,¶SAL+ OMM¶, µSAL¶)
||   |
8 |
° 

NULLIF +#" "


Ë NULLIF(expr1, expr2)
- expr1 compares to expr2, if both are equal returns null
if both are not equal expr1 is
returned
NULLIF(length(åirst_name), length(last_name))

NVL(åirst_name, (NVL(last_name,¶No Name¶)))

OALES E +#" "


Ë OALES E(expr1, expr2, expr3, .. exprn)
- returns the first non null expression
OALES E(åirst_name, last_name, ¶No Name¶)
||   |
7 |
° 
DE ODE &#" "
SELE T last_name, job_id, salary,
DE ODE (job_id, µIT_PROG¶, 1.10*salary,
µST_ LERK¶, 1.15*salary,
µSA_REP¶, 1.20*salary,
salary) ³Revised Salary´
FROM employees;
ASE %=  "
Ë & " ""@#$ ") * +"
!& 9F%3 %-,%"
SELE T last_name, job_id, salary,
ASE job_id WHEN µIT_PROG¶ THEN 1.10*salary
WHEN µST_ LERK¶ THEN 1.15*salary
ELSE salary END ³Revised Salary´
FROM employees;
"24ÿ#)2+)2209
4ÿ#)1:
SELE T course_name,
ASE WHEN period >= 1 AND period <=3 THEN µMorning¶
WHEN period >= 4 AND period <=6 THEN µAåternoon¶
ELSE µAåter School¶ END FROM course;
||   |
6 |
° 

00& 
If the specified two-digit year is
0-49 50-99

If two digits 0-49 the return date is The return date is in the
of the in the current century century before the
current current one
year are
50-99 the return date is The return date is in the
in the century after current century
the current one

Current Year Specified date RR Format YY Format


. 1995 27-Oct-95 1995 1995
. 1995 27-Oct-17 2017 1917
. 2001 27-Oct-17 2017 2017
. 2001 27-Oct-95 1995 2095

||   |
 |
° 

0 RR 
  

2. )++1 .0 )1


0)2,,+ 2 21 
2)); :
SELE T last_name, TO_ HAR(hire_date, 'DD-Mon-yyyy')
FROM employees
WHERE TO_DATE(hire_date, 'DD-Mon-yy') < '01-Jan-90';
no rows selected
9 +"     66#00
+ )  ##)
 "#""666 " )

SELE T last_name, TO_ HAR(hire_date, 'DD-Mon-YYYY')


FROM employees
WHERE hire_date < TO_DATE('01-Jan-90', 'DD-Mon-RR');

||   |
 |
° 

Summary
Ë + # " "#"+#" "
Ë
+"##"+#" "
Ë
" # # #+  #  + )#"+#" "
Ë + +  #"+#" "
Ë 23>-3>-|32--!& :-%, %
Ë 2!& 9F%3 %-,% % :% ,%

||   |
| |
° 

 "+ 
# 9$

||   |
 |
° 

"  #.  G "


Ë / " " " 
Ë / ""
Ë  )"+$/ "  )" "$
Ë 9  )"#/ " " ""WHERE #

SELE T last_name, department_name Dname


FROM employees, departments;

Ë 9 "  #$)") $

SELE T last_name, department_name


FROM employees ROSS JOIN departments;

||   |
 |
° 

3#.!""G " %12!

SELE T department_id, department_name,


location_id, city
FROM departments
NATURAL JOIN locations;

Ë G "+  #""" 


Ë 0#") $@##" #"
Ë !+"   " #"" "  #

||   |
 |
° 
USING #
Ë
 " " #")" " " #"
Ë  " #$" "+" #"

SELE T e.employee_id, e.last_name, d.location_id


FROM employees e JOIN departments d
USING (department_id);

SELE T e.employee_id, e.last_name, d.location_id


FROM employees e, departments d
WHERE e.department_id = d.department_id;

43 " @#G "5


SELE T e.eno, e.ename, s.grade
FROM emp e, salgrade s
WHERE e.sal ETWEEN s.losal AND s.hisal;

||   |
 |
° 

ON #4,+/ "5
Ë 9/ " " "+ "#/ "@# / "
2#  +/ " " "

Ë £ ? ? ?  ? ? V? ??

SELE T e.employee_id, e.last_name, e.manager_id,


m.last_name
FROM employees e JOIN employees m
ON (e.manager_id = m.employee_id);

SELE T e.employee_id, e.last_name, e.manager_id,


m.last_name
FROM employees e , employees m
WHERE e.manager_id = m.employee_id ;

||   |
8 |
° 

Creating Three-way joins with the ON Clause


SELE T employee_id, city, department_name
FROM employees e
JOIN departments d
ON d.department_id = e.department_id
JOIN locations l
ON d.location_id = l.location_id;

SELE T employee_id, city, department_name


FROM employees e, departments d, locations l
WHERE e.department_id = d.department_id
AND d.location_id = l.location_id;

Ë Ñ  3  ‰?  
3  V   ?
?
||   |
7 |
° 

LEFT OUTER JOIN


Ë 9 )"%  )+$
"+" " "$

SELE T e.last_name,e.department_id, d.department_name


FROM employees e
LEFT OUTER JOIN departments d
ON (e.department_id = d.department_id);

SELE T e.last_name,e.department_id, d.department_name


FROM employees e, departments d
WHERE e.department_id = d.department_id(+) ;

||   |
6 |
° 

RIGHT OUTER JOIN


Ë 9 )" ")
$"+" "%  $

SELE T e.last_name,e.department_id, d.department_name


FROM employees e
RIGHT OUTER JOIN departments d
ON (e.department_id = d.department_id);

SELE T e.last_name,e.department_id, d.department_name


FROM employees e, departments d
WHERE e.department_id(+) = d.department_id;

||   |
8 |
° 

FULL OUTER JOIN


Ë 9 )"%  "+" 
" "$
Ë !  )" "$"+
" "%  $

SELE T e.last_name,e.department_id, d.department_name


FROM employees e
FULL OUTER JOIN departments d
ON (e.department_id = d.department_id);

||   |
8 |
° 

Summary
ROSS JOIN
NATURAL JOIN
USING
ON
LEFT OUTER JOIN
RIGHT OUTER JOIN
FULL OUTER JOIN

||   |
8| |
° 

 p
( '/) 

||   |
8 |
° 

;M # &#" "N


Ë M # +#" "  " + ) 
"#  #  Multiple-row
" $
functions

ÈÑ?=#    ?  ?? ‰?


SELE T AVG(salary), SUM(salary),
MIN(salary), MAX(salary)
FROM employees;

SELE T MIN(hire_date), MAX(hire_date),


MIN(last_name), MAX(last_name)
FROM employees;

||   |
8 |
° 

2" OUNT &#" "


Ë OUNT(*) 2+0. 0

SELE T OUNT(*)
FROM employees;

OUNT(expr) 2+0.. 2-


2<

SELE T OUNT(commission_pct)
FROM employees
WHERE department_id = 80;

||   |
8 |
° 

2" DISTIN T <) 


Ë OUNT(DISTIN T expr)
#""#$ +"" " "## += 

SELE T OUNT(DISTIN T department_id)


FROM employees;

M # &#" ""3#>#

Ë M # +#" "" "##" #"

SELE T AVG(commission_pct)
FROM employees;

||   |
8 |
° 

2"3>-&#" ")M # &#" "

Ë 93>-+#" "+  # +#" " "#"##

SELE T AVG(NVL(commission_pct,0))
FROM employees;

||   |
88 |
° 

"M #  +
ÈÑ?    ?  ?? ‰? ? V? ?

Ë  )"$"  # $#"


GROUP Y #

SELE T *|{[DISTIN T] column|expression [ alias],«}


FROM table
[ WHERE condition(s) ]
[ GROUP Y @  
 ]
[ORDER Y {column, expr, alias} [AS |DES ]];

||   |
87 |
° 

2"GROUP Y #
Ë  #"45"SELE T "  # +#" "

‰? "GROUP Y #

SELE T department_id, AVG(salary)


FROM employees
GROUP Y department_id;

Ë 9GROUP Y  #"45 ?   $"SELE T 

SELE T AVG(salary)
FROM employees
GROUP Y department_id;
||   |
86 |
° 

2"GROUP Y # "


#  #"

SELE T department_id dept_id, job_id, SUM(salary)


FROM employees
GROUP Y department_id, job_id;

%=#"M # 0#
ÈÑ?=#   ?? ? ??  ? ?  

SELE T department_id, MAX(salary)


FROM employees
GROUP Y department_id
HAVING MAX(salary) > 10000;

||   |
7 |
° 

3M # &#" "


È  ?  
 ? ?  

SELE T MAX(AVG(SALARY))
FROM employees
GROUP Y department_id;


£
V V ‰???  ? Ñ

||   |
7 |
° 

,#
Ë 2 # +#" "
Ë ;@##M0:2 '†#
Ë ;@##F>!3M#

SELE T *|{[DISTIN T] column|expression [ alias],«}


FROM table
[ WHERE condition(s) ]
[ GROUP Y @  
 ]
[ HAVING @   

 ]
[ORDER Y {column, expr, alias} [AS |DES ]];

||   |
7| |
° 

Sub-Queries

||   |
7 |
° 

Using a Subquery to Solve a Problem


Which employees have salaries greater than Abel¶s salary ?

You need two queries :


First, find what Abel earns, and
Second, find who earns more than that amount.

What is the Abel¶s Salary 

Combine two queries, placing one query inside the other query.
i.e. ³Query within a query.´
||   |
7 |
° 

Sub-query
SELE T select_list
FROM table
WHERE expr operator ( SELE T select_list
FROM table );

The subquery (inner query) executes once before the main query.
The result of the subquery is used by the main query(outer query).

SELE T last_name
FROM employees
WHERE salary > ( SELE T salary FROM employees
WHERE last_name =µAbel¶ );

||   |
7 |
° 

Types of Subqueries

SELE T select_list
FROM table
WHERE expr operator ( SELE T select_list
FROM table );

Ë Single-row subquery
ST_ LERK

Ë Multiple-row subquery
ST_ LERK
SA_MAN

||   |
7 |
° 

Single Row Subqueries


Ë Returns only one value
Ë Use single-row comparison operators
= < <= > >= <>
SELE T last_name, job_id
FROM employees
WHERE job_id = ( SELE T job_id FROM employees
WHERE employee_id = 141 );

SELE T last_name, job_id, salary


FROM employees
WHERE job_id = ( SELE T job_id FROM employees
WHERE employee_id = 141 )
AND salary > ( SELE T salary FROM employees
WHERE employee_id = 143 );

||   |
78 |
° 

Using Group Functions in a Subquery

SELE T last_name, job_id, salary


FROM employees
WHERE salary = ( SELE T MIN(salary) FROM employees);

The HAVING clause with Subqueries


SELE T department_id, MIN(salary)
FROM employees
GROUP Y department_id
HAVING MIN(salary) > ( SELE T MIN(salary)
FROM employees
WHERE department_id = 50);

||   |
77 |
° 

Will this statement Return Rows ?


SELE T last_name, job_id
FROM employees
WHERE job_id = ( SELE T job_id FROM employees
WHERE last_name = µXyz¶);

Ë If subquery returns no rows, main query returns null result

Null values in the Subquery


SELE T last_name, job_id
FROM employees
WHERE job_id = ( SELE T job_id FROM employees
WHERE last_name = µHaas¶);

Ë If subquery returns null values, main query returns null result

||   |
76 |
° 

What is Wrong in this Statement


SELE T last_name, job_id
FROM employees
WHERE salary = ( SELE T MIN(salary) FROM employees
GROUP Y department_id);

Ë Single row operator with multiple-row subquery

Using the IN Operator


Ë Equal to any member in the list

SELE T last_name, salary, department_id


FROM employees
WHERE salary IN ( SELE T MIN(salary) FROM employees
GROUP Y department_id);

||   |
6 |
° 

Using the ANY Operator


Ë Compare value to each values returned by the subquery

SELE T last_name, salary, department_id


FROM employees
WHERE salary < ANY ( SELE T salary FROM employees
WHERE job_id = µIT_PROG¶);

Using the ALL Operator


Ë Compare value to every values returned by the subquery

SELE T last_name, salary, department_id


FROM employees
WHERE salary < ALL ( SELE T salary FROM employees
WHERE job_id = µIT_PROG¶);

||   |
6 |
° 

Summary
Ë Write subqueries when a query is based on unknown values

SELE T select_list
FROM table
WHERE expr operator ( SELE T select_list
FROM table );

||   |
6| |
° 

SQL*Plus Formating Elements

||   |
6 |
° 

Column Headings
COLUMN employee_name HEADING ³Employee Name´
Employee Name
-------------

COLUMN employee_name HEADING ³Employee | Name´


Employee
Name SET UNDERLINE @
--------

COLUMN employee_name HEADING ³Employee | Name´ JUSTIFY RIGHT


COLUMN employee_name HEADING ³Employee | Name´ JUSTIFY CENTER

Page Width SET LINESIZE 60 Page Length SET PAGESIZE 50

||   |
6 |
° 

OLUMN department_name FORMAT A15 Heading DNAME


OLUMN department_id FORMAT 9999 Heading JO

SELE T department_name,department_id
FROM departments d;

||   |
6 |
° 

># &  0#


| 6666 |
|  666666 | 
|  L66666666 L| 
 666 
 6666 
 66666 
 ,6666 H
 6666 0 OP
 6666 0 

||   |
6 |
° 

Defining a Title
TITLE
TTITLE LEFT ³My ompany´
ENTER ³ urrent´
RIGHT ³Page´ FORMAT 999 SQL.PNO SKIP 1
ENTER ³Employee Listing´ SKIP 4

My ompany urrent Page 1 SQL.RELEASE


Employee Listing SQL.USER

Getting the Date into a title


OLUMN curdate NEW_VALUE report_date
SELE T to_char(sysdate,¶dd¶mon-yyyy¶) curdate
FROM dual;

TITLE LEFT ³Report Date : ³ report_date

||   |
68 |
° 
Report Breaks
REAK ON owner
The below above example causes a
SELE T owner, table_name page break to occur whenever an
FROM all_tables owner changes, and a blank line to
ORDER Y owner,table_name; be printed whenever an owner
changes, and a blank line to be
OWNER TABLE_NAME printed whenever the object type
---------------------- --------------------------
changesON: owner SKIP PAGE
CTYSYS DR$CLASS REAK
DR$DELETE ON object_type SKIP 1
DR$INDEX
SELE T owner, object_type,
SCOTT CUSTOMER object_name
DEPARTMENT
FROM dba_objects
EMPLOYEE
ORDER Y owner,
object_type, object_name;
REAK ON owner SKIP 1
REAK ON owner SKIP PAGE

||   |
67 |
° 

Creating and Managing Tables

||   |
66 |
° 

Table
Basic unit of storage ; composed of rows and columns

REATE TALE [schema.]table


(column datatype [DEFAULT expr] [,..]);

TABLE name and COLUMN name


Ë Must begin with a letter
Ë Must between 1-30 characters long
Ë Must contain only A-Z, a-z, 0-9, _ , $ , #
Ë Must not be an Oracle server reserved word

||   |
 |
° 

Creating Table
REATE TALE student
(sno number(2),
sname varchar2(15),
dob date,
age number(2),
tno number(2));

REATE TALE teacher


(tno number(2),
tname varchar2(15),
dept varchar2(15) DEFAULT µno dept¶);
Creating a table by using a Subquery
REATE TALE dept80
AS SELE T employee_id, last_name, hire_date,
department_id
FROM employees
WHERE department_id = 80;
||   |
 |
° 

The ALTER TALE statement


Use ALTER TALE statement to add, modify or drop columns

ALTER TALE dept80


ADD (job_id varchar2(9));

ALTER TALE dept80


MODIFY (last_name varchar2(30));

ALTER TALE dept80 ALTER TALE dept80


DROP OLUMN job_id; SET UNUSED (last_name);

ALTER TALE dept80 ALTER TALE dept80


SET UNUSED OLUMN job_id; DROP UNUSED OLUMNS ;

||   |
| |
° 
Dropping a Table
DROP TALE dept80;

Changing the Name of an Object / Column


RENAME dept TO detail_dept;

ALTER TALE emp RENAME OLUMN dept TO depart;

Truncating a table
TRUN ATE TALE detail_dept;

Ë Removes all the rows from a Table


Ë Releases storage space used by that table
HWM
||   |
 |
° 

Adding Comments to a Table & Column


OMMENT ON TALE employees
IS µEmployee Inåormation¶;

Removing Comments from a Table


OMMENT ON TALE employees
IS µ ¶;

OMMENT ON OLUMN employees.last_name


IS µLast Name oå the Employee¶;

ALL_ OL_ OMMENTS USER_ OL_ OMMENTS


ALL_TA_ OMMENTS USER_TA_ OMMENTS

||   |
 |
° 

Constraints
Constraints enforce rules at the Table level

NOT NULL value must exist


UNIQUE no duplicates
PRIMARY KEY NOT NULL & UNIQUE
FOREIGN KEY relationship between two
columns
HE K condition must be true

||   |
 |
° 

Defining Constraint
REATE TALE student1
(sno number(2) ONSTRAINT s_sno_pk PRIMARY KEY,
sname varchar2(15) NOT NULL,
dob date UNIQUE, SYS_Cnnnnnn
age number(2) HE K (age < 25),
tno number(2),
ONSTRAINT st_te_åk FOREIGN KEY (tno)
REFEREN ES teach(tno) ON DELETE AS ADE
);

ON DELETE AS ADE Deletes the dependent rows in the


child table when a row in parent table is deleted

ON DELETE SET NULL


Converts dependent foreign key values to null

||   |
 |
° 

Constraints

ALTER TALE teach


ADD ONSTRAINT emp_mgr_uk UNIQUE (tname);

ALTER TALE teach


DROP ONSTRAINT emp_mgr_uk;

ALTER TALE teach


DISALE ONSTRAINT emp_mgr_uk;

ALTER TALE teach user_constraints


ENALE ONSTRAINT emp_mgr_uk; user_cons_columns

||   |
8 |
° 

Manipulating Data

||   |
7 |
° 

SQL Statements
SELECT Data retrieval
INSERT DML Data Manipulation Language
UPDATE
DELETE
MERGE
CREATE DDL Data Definition Language
ALTER
DROP
RENAME
TRUNCATE
COMMIT Transaction Control
ROLLBACK
SAVEPOINT
GRANT DCL Data Control Language
REVOKE
||   |
6 |
° 

Data Manipulation Language


A DML statement is executed when
Ë Add new rows to a table.
Ë Modify existing rows in a table.
Ë Remove existing rows from a table.

The INSERT statement


Add new rows to a table by using the INSERT statement

INSERT INTO table [(column [, column«])]


VALUES (value [, value«]);

Ë Only one row is inserted at a time with this syntax

||   |
 |
° 

Inserting New Rows


INSERT INTO departments(department_id,
department_name, manager_id, location_id)
VALUES (9, µDatabase Admin¶, 100, 1700);

INSERT INTO departments


VALUES (9, µDatabase Admin¶,100,1700);

INSERT INTO departments(department_id,


location_id)
VALUES (9, 1700);

INSERT INTO departments(department_id,


department_name, manager_id, location_id)
VALUES (9, USER , null ,¶¶);

||   |
 |
° 

Inserting New Rows


INSERT INTO employees
VALUES (18,¶Reyarndo¶,¶De arl¶,¶RDE ARL¶, µ515.17.61¶,
TO_DATE(µFE 3, 2005¶,¶MON DD, YYYY¶), µDA¶, 11000,
NULL, 100, 30);

Copying Rows from Another Table


INSERT INTO empp
SELE T * FROM employees WHERE deptno = 30;

Inserting using & && (Substitution variables)


INSERT INTO departments
VALUES (&c1, &c2 , &&c3);

||   |
| |
° 

The UPDATE statement


Modify existing rows with the UPDATE statement

UPDATE table
SET column = value [, column = value,«]
[WHERE condition];

Ë Update more than one row at a time, if required

UPDATE employees
SET department_id = 70
WHERE employee_id = 113;

Ë Updates all rows, if WHERE clause is omitted

UPDATE empp
SET department_id = 70;

||   |
 |
° 

The UPDATE statement

UPDATE employees
SET job_id = (SELE T job_id FROM employees
WHERE employee_id = 205),

salary = (SELE T sal FROM emp


WHERE eid = 200)

WHERE employee_id = 114;

||   |
 |
° 

The DELETE statement


Remove existing rows with the DELETE statement
DELETE [FROM] table
[WHERE condition];

Ë Delete more than one row at a time, if required


DELETE FROM departments
WHERE department_name = µFinance¶;

DELETE FROM empp;

DELETE employees
WHERE department_id = (SELE T department_id
FROM departments
WHERE department_name
LIKE µ%Public%¶);

||   |
 |
° 

The MERGE statement


Insert or Update rows in the OPY_EMP table to match the
EMPLOYEES table.

MERGE INTO copy_emp c


USING employees e
ON (c.employee_id = e.employee_id)
WHEN MAT HED THEN
UPDATE SET
c.åirst_name = e.åirst_name,
... ...
c.department_id = e.department_id
WHEN NOT MAT HED THEN
INSERT VALUES (e.employee_id, e.åirst_name, ...
e.department_id);

||   |
 |
° 

# $!3,%09
Ë Unconditional INSERT ALL
Ë Select the EMPLOYEE_ID, HIRE_DATE, SALARY, and
MANAGER_ID values from the EMPLOYEES table for those
employees whose EMPLOYEE_ID is greater than 200.
Ë Insert these values into the SAL_HISTORY and
MGR_HISTORY tables using a multi-table INSERT
Ë All the table must be valid, otherwise rollback.
INSERT ALL
INTO sal_history VALUES(empid, hiredate, sal)
INTO mgr_history VALUES(empid, mgr, sal)
SELE T employee_id EMPID, hire_date HIREDATE,
salary SAL, manager_id MGR
FROM employees
WHERE employee_id > 200;

||   |
8 |
° 


# $!3,%09
Ë Conditional INSERT ALL
Ë Select the EMPLOYEE_ID, HIRE_DATE, SALARY, and MANAGER_ID
values from the EMPLOYEES table for those employees whose
EMPLOYEE_ID is greater than 200.
-- If the SALARY is greater than $10,000, insert these values into the
SAL_HISTORY table
-- If the MANAGER_ID is greater than 200, insert these values into the
MGR_HISTORY table.
INSERT ALL
WHEN sal > 10000 THEN
INTO sal_history VALUES(empid, hiredate, sal)
WHEN mgr > 200 THEN
INTO mgr_history VALUES(empid, mgr, sal)
SELE T employee_id EMPID, hire_date HIREDATE,
salary SAL, manager_id MGR
FROM employees
WHERE employee_id > 200;
||   |
7 |
° 

# $!3,%09
Ë Conditional FIRST INSERT
Ë Select the DEPARTMENT_ID, SUM(salary) and MAX(hire_date)
from the EMPLOYEES table
-- If the SUM(salary)is greater than $18,000, then insert these values into the
SPE IAL_SAL.
-- If the first WHEN clause evaluates to true, the subsequent WHEN clauses for
this rows should be skipped.
-- For the rows that do not satisfy the first WHEN condition, insert into the
HIREDATE_HISTORY_00, or HIREDATE_HISTORY_99 or HIREDATE_HISTORY tables,
based on the value in the HIRE_DATE column

INSERT FIRST
WHEN sal > 18000 THEN
INTO special_sal VALUES(deptid, sal)
WHEN hiredate like (µ%00%¶) THEN
INTO hiredate_history_00 VALUES(deptid, hiredate)
WHEN hiredate like (µ%99%¶) THEN
INTO hiredate_history_99 VALUES(deptid,hiredate)
ELSE INTO hiredate_history VALUES(deptid, hiredate)
SELE T department_id DEPTID, SUM(salary) SAL,
MAX(hire_date) HIREDATE FROM employees
GROUP Y department_id;

||   |
6 |
° 

Transaction
Transaction consists of the collection of DML statements that
form a logical unit of work

Ë DML statements which constitute one consistent change to the data.


Ë One DDL statement
Ë One DCL statement

Ë Begin when the first DML statement is executed


Ë End with one of the following events :
- A OMMIT or ROLLA K statement is issued
- A DDL or DCL statement executed
- The user exits SQL*Plus / Worksheet

||   |
| |
° 

Controlling Transactions

OMMIT
Transaction
DELETE
SAVEPOINT A
INSERT

UPDATE
SAVEPOINT 
INSERT
ROLLA K TO ROLLA K TO
SAVEPOINT  SAVEPOINT A
ROLLA K
||   |
| |
° 

!"=
Ë Used by the Server to speed up the retrieval rows by using pointer
Ë Automatically - PRIMARY KEY or UNIQUE constraint
Manually - create non-unique index on column
REATE INDEX emp_lname_idx
ON employees(last_name);

Ë A Function-based index is an index based on expressions

REATE INDEX upper_emp_job_idx


ON employees( UPPER (job_id));

user_indexes
DROP INDEX emp_lname_idx;
user_ind_columns

||   |
|| |
° 

,@#"
Ë Generates unique numbers sequentially
Ë Used to create a primary key value
REATE SEQUEN E d_did_seq
START WITH m 
IN REMENT Y m
MAXVALUE   NOMAXVALUE
Y LE | NO Y LE
A HE 10 | NO A HE;
ORDER | NOORDER;

INSERT INTO departments


VALUES (d_did_seq.NEXTVAL , µSupport¶, 2500);

SELE T d_did_seq. URRVAL FROM dual;

NEXTVAL returns the next available sequence


URRVAL obtains the current sequence value
||   |
| |
° 

,@#"
Ë ALTER SEQUEN E is used to modify

ALTER SEQUEN E d_did_seq


IN REMENT Y m
MAXVALUE 
NO Y LE;

START WITH cannot be modified always

DROP SEQUEN E d_did_seq;

user_sequences
||   |
| |
° 

," "
Ë Shorten lengthy objects names

REATE SYNONYM d_sum


FOR department_sum_vu;

DROP SYNONYM d_sum;

||   |
| |
° 

Summary
!3,%09 
-
" # "-"#
2 9%
%-%9%

%0M%
:

!9 9" " " 


0:--' <
,>% :!39

# $!3,%09

2" " " !3,%09--


" " !3,%09--
" " &!0,9!3,%09

!3%QI ,%12%3 % ,†3:3†

||   |
| |
° 

Controlling User Access

||   |
|8 |
° 


Ë Privileges are the right to execute particular SQL statements
Ë System Privileges : Gaining access to the database
± REATE TALE, REATE USER ..
Object Privileges : Manipulating the content of the db objects
D SELE T, UPDATE, REFEREN ES...

GRANT create user, create table, create view


TO hr;

REATE USER   
IDENTIFIED Y  ;

ALTER USER   
IDENTIFIED Y ;

||   |
|7 |
° 

0 
Ë Role is a named group of related privileges that can be granted
to the user
Ë A User can have several roles, and several users can be
assigned the same role
Ë Create a Role
REATE ROLE ! @ 

Ë Grant privileges to a
Role
GRANT create table, create user
TO ! @ ;
Ë Grant a role to users SET ROLE gardener IDENTIFIED Y
marigolds;
GRANT ! @ SET ROLE ALL;
TO dehann, kochhar; SET ROLE ALL EX EPT dw_manager;
SET ROLE NONE; -- )1p/(

||   |
|6 |
° 


* Object privileges is access to on object i.e. table, view«
* An owner has all privileges on the object which has been
created
* An owner can give specific privileges on his object to other user
GRANT select, update Connect to SCOTT to retrieve from HR
ON employees SELE T *
TO scott; FROM hr.employees;

GRANT update (department_id, location_id)


ON employees
TO scott, rey ; reåerences

GRANT select, update GRANT select


ON employees ON rey.student
TO scott TO PULI ;
WITH GRANT OPTION ;

||   |
 |
° 

0 *
Ë REVOKE statement used to revoke privileges granted to other users
Ë Privileges granted to others through WITH GRANT OPTION also
revoked

REVOKE select, update


ON employees
FROM scott;

· 
—
  


  
 




   




 

X Y Z X Y Z


 
 





 
 
 


||   |
 |
° 

Summary
Ë Privilege - rights to execute particular SQL statements
System D REATE TALE, REATE USER ..
Object D SELE T, UPDATE ..

Ë Role is a named group of related privileges

Ë Grant
Revoke

||   |
| |
° 

Views

||   |
 |
° 

">)
Ë Logically represents subsets of data from one or more tables.
Ë Logical table based on a table or another view.
Ë A View contains no data of its own but is like a window
through which data from tables can be view or changed.
Ë View is stored as a SELE T statement in the data dictionary.

REATE [OR REPLA E] [FOR E|NO FOR E] VIEW r


 !
[(alias[, alias] ..)]
AS subquery
[WITH HE K OPTION [constraint !]]
[WITH READ ONLY [constraint !]] ;

||   |
 |
° 

">)
Ë Create a view EMPVU80, that contains details of the employees
in department 80
REATE OR REPLA E VIEW !r
AS SELE T employee_id, last_name, salary
FROM employees WHERE department_id = 80;

REATE OR REPLA E VIEW !r


AS SELE T employee_id EID, last_name NAME,
salary*12 ANN_SAL
FROM employees WHERE department_id = 50;

REATE OR REPLA E VIEW !r (EID,NAME,ANN_SAL)


AS SELE T employee_id, last_name, salary
FROM employees WHERE department_id = 50
WITH READ ONLY ;

||   |
 |
° 

 =>)
Ë Create a Complex view that contains group functions to display
values from two tables

REATE OR REPLA E VIEW  !r


( name, minsal, maxsal, avgsal)
AS SELE T d.department_name, min(e.salary),
max(salary), avg(salary)
FROM employees e, departments d
WHERE e.department_id = d.department_id
GROUP Y d.department_name;

||   |
 |
° 

WITH HE K OPTION
Ë Any attempt to change the department number for a row
in the view fails, because it violates WITH HE K OPTION
REATE OR REPLA E VIEW !r 
AS SELE T employee_id, last_name, salary,
department_id FROM employees
WHERE department_id = 20
WITH HE K OPTION ;

WITH HE K OPTION ONSTRAINT !r  ;

DROP VIEW view_name;

||   |
8 |
° 

" * .=$!-#


Ë A named subquery in the FROM clause of the main query.
Who are the top TEN earners ?
Who are the least FIVE earners ?

SELE T ROWNUM as RANK, last_name, salary


FROM ( SELE T last_name, salary FROM employees
ORDER Y salary DES )
WHERE ROWNUM < = 10 ;

WHERE must use < or <= operator

||   |
7 |
° 

Why use Views ?


Ë To restrict data access
Ë To make complex queries easy
Ë To present different view of the same data table.

Simple View vs Complex View


Feature Simple View Complex View
No of tables One One or More
Contains group functions No Yes
DML operations Yes Not
always
through a view
||   |
6 |
° 

Summary

Ë Create View ± Simple / Complex

Ë WITH CHECK OPTION

Ë INLINE / TOP-N

||   |
  |
° 

||   |
  |