Apostila SQL
STRUCTURED QUERY LANGUAGE
• Semelhante ao inglês falado
• Fácil de escrever, ler e entender
Componentes do SQL
• DML - Data Manipulation Language
– SELECT
– UPDATE
– INSERT
– DELETE
• DDL - Data Definition Language
– CREATE
– ALTER
– DROP
• DCL – Data Control Language
– GRANT
- REVOKE
Tabelas Usadas nos Exemplos
ID
NOME
DEPT
Staff
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
•
SANTANA
ORSINI
DANTAS
O’BRIEN
SOUZA
SUZUKI
ALMEIDA
JAMES
KOONITZ
PLOTZ
NGAN
NAUGHTON
YAMAGUCHI
FRAYE
OLIVEIRA
MOLINARI
KERMISCH
ABRAHAMS
SNEIDER
SCOUTTEN
LU
SMITH
LUNDQUIST
DANIELS
WHEELER
JONES
LEA
WILSON
PINHO
DANIVS
GRAHAM
GONZALES
BURKE
VIEIRA
GAFNEY
DEPTCOD
Org
20
20
38
38
15
38
15
20
42
42
15
38
42
51
51
10
15
38
20
42
10
51
51
10
51
10
66
66
84
84
66
66
66
84
84
CARGO
TEMP
SALARIO
COMIS
7
8
5
6
10
7
6
7
5
6
6
6
7
4
3
8
10
7
3
5
6
12
9
9
10
5
13
4
1
7
5
18357.50
18171.25
17506.75
18006.00
20659.80
16808.30
16502.83
13504.60
18001.75
18352.80
12508.20
12954.75
10505.90
21150.00
19456.50
22959.20
12258.50
12009.75
14252.75
11508.60
20010.00
17654.50
13369.80
19260.25
14460.00
21234.00
18555.50
18674.50
19818.00
15454.50
21000.00
16858.20
10988.00
17844.00
13030.50
612.45
846.55
650.25
1152.00
128.20
1386.70
206.60
180.00
75.60
637.65
110.10
236.50
126.50
84.20
992.80
189.65
513.30
811.50
806.10
200.30
844.00
55.50
1285.00
188.00
GER
VENDAS
GER
VENDAS
GER
VENDAS
VENDAS
ATEND
VENDAS
GER
ATEND
ATEND
ATEND
GER
VENDAS
GER
ATEND
ATEND
ATEND
ATEND
GER
VENDAS
ATEND
GER
ATEND
GER
GER
VENDAS
GER
VENDAS
VENDAS
VENDAS
ATEND
VENDAS
ATEND
DEPTNOME
GERENTE
DIVISAO
LOCAL
160
CENTRO
SAO PAULO
50