Вы находитесь на странице: 1из 27

...

3
I. SQL.....4
1.1.

..4

1.2.

SQL-......10

1.3.

SQL....12

1.4.

SQL...13

1.5.

....13

1.6.

SQL-......16

II. SQL ...18


2.1. ....18
2.2. SELECT....19
2.3. DISTINCT........22
2.4. .24
.....27
...28



. ()

: ;
;
.
70-
IBM SQL,

de-facto


Oracle, Informix, Sybase, DB2, Progress
SQL , ,
SQL ,
.
SQL.

:

SQL;

SQL .

I. SQL
1.1.
SQL ( "Sequel")
. ,
,
.
,

,
.
, , , ,
,
, ,
.
,
, ,

.

,
, SQL,
, .
, , 90-
SQL.
SQL ANSI (
) ISO
( ). ,
SQL ANSI,
3

, , ,
. ,

"" .
- ,
.
. ,
. ,
, ,
, . ,
.
(

;
- , ,
. :

Gerry Farish

( 415)365-8775 127

Primrose Ave.,SF

Celia Brock

( 707)874-3553 246

#3rd St.,Sonoma

Yves Grillet

( 762)976-3665

778 Modernas,Barcelona

- ,
( ) . ,
.
. ,
.
,
, .

. ,
( ) - .
4

,
.
, , , .

Farish

Drume

B.C./B.S.

$272.99

Grillet

Halben

None

$44. 76

Brock

Halben

Health,Inc.

$9077.47


,

. , - . Halben
.
,
( ) , , . , ,
Grillet Brock,
.

,
.
-
- SQL Halben
.
, ,
, .
,
.
. ,
5

-
.

,
,
- .
,
. ,
: " . "
,
, , , .
, , -
.
,
. ,
- ,
. , ,
, Mary Smiths; ,
, .
. (
),
, -
.
.
- ;
, .
, ,
.
,
.
6

, ( )
. ,
, " " " 3 ". ,
,
.
.
1.1, 1.2, 1.3 ,
, ,
,
SQL.
,
. - .
.
. ,
,
.
1.1 -
SNUM

SNAME

CITY

COMM

1001

Peel

London

.12

1002

Serres

San Jose

.13

1004

Motika

London

.11

1007

Rifkin

Barcelona

.15

1003

Axelrod

New York

.10

1.2 -
CNUM
2001
2002
2003
2004
2006
2008
2007

CNAME
Hoffman
Giovanni
Liu
Grass
Clemens
Cisneros
Pereira

CITY
London
Rome
SanJose
Berlin
London
SanJose
Rome

RATING
100
200
200
300
100
300
100

SNUM
1001
1003
1002
1002
1001
1007
1004

1.3 -
ONUM
3001
3003
3002
3005
3006
3009
3007
3008
3010
3011

AMT
18.69
767.19
1900.10
5160.45
1098.16
1713.23
75.75
4723.00
1309.95
9891.88

ODATE
10/03/1990
10/03/1990
10/03/1990
10/03/1990
10/03/1990
10/04/1990
10/04/1990
10/05/1990
10/06/1990
10/06/1990

CNUM
2008
2001
2007
2003
2008
2002
2004
2006
2004
2006

SNUM
1007
1001
1004
1002
1007
1003
1002
1001
1002
1001

, snum ,
. snum ,
. ,
- ,
snum
. , , "
"
.
1.1

snum

( "

sname
city
comm

" ).
.
( )

1.2 :

cnum
cname
city
rating



( )

.

snum

( )
(
)

1.3:
8


onum
amt
odate
cnum

snum

)

( )

1.2. SQL-
SQL ,
. , ,
,
C. C,
. , ,
,
.
, ,
:
.
-
.
, -
.
.
, 1.
, 3.
(, C ,
). SQL
. SQL

, .
9

SQL ANSI (
). SQL ANSI.
IBM.
SQL , ANSI
( ANSI ).
, .
ANSI .
ANSI ,
ANSI

. ANSI SQL

.
SQL ,
. - , ,
,
- SQL.
, , ,
SQL .
.
,
.
- " FROM Salespeople " " WHERE city
= "London".
.
, Salespeople - , FROM -
FROM.
, " city = "London" " - WHERE.
-
.
10

, (
), .
1.3. SQL
SQL: . ,
, . SQL

. SQL,
,
( ) - .
SQL SQL
, (
).
. ,
, SQL

SQL. SQL SQL


("passed off")
.
1.4. SQL
, SQL,
, .
,
. ANSI
, SQL
,

SQL.

11

DDL ( ) -
ANSI, , (,
, , ) .
DML ( ) -

.
DCD ( )
,
. DDL ANSI.
, SQL .
1.5.
, . -
.
.
,

.
SQL, -
,
.
.
, , cname city - ,
snum, cnum - . ,
Highest () None () rating,
. ,
.
,
12

, .
,
.
,
,
SQL, . ANSI SQL
,
. ,
DATA () TIME () - (
).
, MONEY () BINARY (). (MONEY
- .

,
).
ANSI ,
- .
ANSI , ,
SQL,
.
ANSI, INTEGER ( ) DECIMAL
( ) ( INT DEC,
), ,
. ,
,
.
- CHAR ( ),
. CHAR ,
, .

13


VARCHAR ( ),

( 254 ). CHARACTER VARCHAR
"".
CHAR VARCHAR , CHAR
, VARCHAR
.
, .
, 1 "1". "1" -
,
1.
1 + 1 = 2, "1" + "1" "2".

,

,
.
( ) :
ASCII ( )
EBCDIC

) ( ).
, ,
.
1.6. SQL

SQL. SQL ,
ANSI. , ANSI

14

ANSI . ANSI -
,
.
SQL
,
. , ,
(
). ,
(),

ID().

ID ,
; ,
( ),
.
SQL . SQL

.
, .

.

USER

()

.
, .
I:
.
,
- ,
,
. , ,
15

. .
, .
SQL-,
, , SQL,

).

16

II. SQL

2.1.
SQL

- SQL. ,
SQL , -
- . ,
SQL .
- ,

.
, , ,
, ( ),
.
DML. ,
,
,
DML ,
.
SQL .
,
.
SELECT ().

17

2.2. SELECT
, SELECT
. ,
, :
SELECT snum, sname, sity, comm
FROM Salespeople;
2.1.
2.1 - SELECT
SQL Execution Log
SELECT snum, sname, sity, comm FROM Salespeople;
snum
sname
1001
Peel
1002
Serres
1004
Motika
1007
Rifkin
1003
Axelrod

city
London
San Jose
London
Barcelona
New York

comm
0.12
0.13
0.11
0.15
0.10

, .
,
,
.
:
SELECT - ,
- . ,
.
Snum, sname - -
.
. , ,
,
; .
FROM FROM - , SELECT,
Salespeople .
18


. - (Salespeople).
SQL
.
(\) ,
.
,

.

. ,
,
- .
.
SQL :
.
( ENTER) .
, ,
, :
SELECT snum, sname, city, comm FROM Salespeople;
SQL
, SQL (
ENTER) . - ,
,
.
(*)
:
SELECT *
FROM Salespeople;
.

19

, SELECT
SELECT, .
, .
, (*).
FROM ,
. ,
( ; )
.
SELECT
. .
, , ,
SELECT. ,
SELECT sname, comm
FROM Salespeople;
2.2:
2.2 -
SQL Execution Log
SELECT snum, comm FROM Salespeople;
sname
Peel
Serres
Motika
Rifkin
Axelrod

comm
0.12
0.13
0.11
0.15
0.10

,
,
. ,
.
, , ,
. ,
(*) ,
, .
20

, (odate),
(snum), (onum), (amt):
SELECT odate, snum, onum, amt
FROM Orders;
2.3.
2.3 -
SQL Execution Log
SELECT odate, snum, onum, amt FROM Orders;
odate
snum
10/03/1990
1007
10/03/1990
1001
10/03/1990
1004
10/03/1990
1002
10/03/1990
1007
10/04/1990
1003
10/04/1990
1002
10/05/1990
1001
10/06/1990
1002
10/06/1990
1001

onum
3001
3003
3002
3005
3006
3009
3007
3008
3010
3011

amt
18.69
767.19
1900.10
5160.45
1098.16
1713.23
75.75
4723.00
1309.95
9891.88

-
SQL.
2.3. DISTINCT
DISTINCT () ,
SELECT. ,
,
. ,


. , ;
(snum). :
SELECT snum
FROM Orders;
2.4.
21

2.4 - SELECT
SQL Execution Log
SELECT snum FROM Orders;
snum
1007
1001
1004
1002
1007
1003
1002
1001
1002
1001

, ,
:
SELECT DISTINCT snum
FROM Orders;
2.5.
, DISTINCT , ,
. -
. ,
DISTINCT,
- - .
DISTINCT
SELECT. ,
2.5 - SELECT
SQL Execution Log
SELECT DISTINCT snum FROM Orders;
snum
1001
1002
1003
1004
1007

DISTINCT .
-
22

. DISTINCT, , ,
(
), .

DISTINCT,

- ALL.

, .
- , DISTINCT ALL,
ALL - , .
2.4.
,
,
.
, SQL ,
, .
WHERE

SELECT,

,
.
. ,
.
:
SELECT sname, city
FROM Salespeople;
WHERE city = "LONDON";
WHERE ,

. , Peel,
city,
"London", . Serres
, .
23

2.6.
2.6 - SELECT c WHERE
SQL Execution Log
SELECT sname, city FROM Salespeople WHERE city = 'London'
sname city
Peel London
Motika London

WHERE.
rating

. -
.

. 100,
:
SELECT *
FROM Customers
WHERE rating = 100;
, -
. 2.7.
, ,
SELECT WHERE.

SELECT, WHERE.
2.7 - SELECT
SQL Execution Log
SELECT * FROM Customers WHERE rating = 100;
num
cname
city
2001
Hoffman
London
2006
Clemens
London
2007
Pereira
Rome

rating
100
100
100

24

snum
1001
1001
1001

II:

,
.
, ,
.
,
,
, .

25

SQL

,
. ,
, .

.
SQL
, .,
Fox, dBASE IV .

26


1. . , . SQL: . :

, 2006.
2. . DB2. - .:

, 1988. - 320 .
3. ..

. - .: , 1994. - 90 .
4. . . - .: , 1987. - 608 .
5. . Informix. .1. . -

/ ..
- : , 1995.
6. . . - .: , 1990. - 386 .

27