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

. .

2004


................................................................................................................................. 5
................................................................................................................................................................. 6
...................................................................................................................................................................... 6
1. ....................................................................................................................... 7
1.1. ......................................................................................................................... 7
1.2. ............................................................................................................... 9
1.2.1. ...................................................................................... 10
1.3. ....................................................................................................................... 11
1.3.1. .................................................................................................... 11
1.3.2. ................................................................................... 12
1.4. ....................................................................................................... 13
1.5. ............................................................................................................................... 15
1.5.1. ................................................................................................... 17
2. ............................................................................................... 17
2.1. () ................................. 17
2.1.1. -............................................................................................................................ 18
2.1.2. - ......................................................................................... 22
2.2. .............................................................................................................. 24
2.2.1. .................................................................................................................... 25
2.2.2. ....................................................................... 28
2.2.3. ..................................................................................................................................... 31
2.2.4. - .............................................. 40
2.3. ................... 43
2.3.1. .................................................................................................................... 44
2.3.2. ........................................................................................................................... 44
2.3.3. .......................................................................................................................... 45
2.3.4. ........................................................................................................................... 45
2.3.5. - ................................................................................................................ 46
2.3.6. .................................................................................................................... 46
2.3.7. ( -) ................................................... 47
3. ........................ 47
3.1. (MS ACCESS) .................................. 47
3.1.1. ........................................................................................................................................... 47
3.1.2. . ............................................................. 51
3.2. QBE.............................................................................................................. 53
3.2.1. ................................................................................................ 55
3.2.2. , ................................... 58
3.2.3. ......................................................................................................................................... 61
3.2.4. . ............................................. 62
3.2.5. ..................................................................................................................................... 64
3.2.6. ........................................................................................................................... 65
3.2.7. QBE SQL-...................................................................................................... 67

4. SQL .................................................................................................................... 67
4.1. SELECT ..................................................................................................................... 68
4.1.1. SELECT ................................................................................................................... 68
4.1.2. ................................................................................................ 70
4.1.3. ..................................................................... 71
4.1.4. ......................................................................................................................................... 72
4.2. ........................ 73
4.2.1. SQL- ................................................................................................................................................. 73
4.2.2. ............................................................................................................................... 74
4.3. ........................................................................................... 76

. ........................................................................ 77

................................................................................................................................................. 79
.............................................................................................................. 81
..................................... 82
- ...................................................................................................................................... 82
................................................................................................................................. 82
............................................................................................................................................... 82
..................................................................................................................................... 83
QBE ........................................................................................................................................................ 83
SQL......................................................................................................................................................... 84
........................................................................................................................ 85


1.

1.1.
1.2.

1.3.


1.4. .
. .
1.5. .
.
2.

2.1
- (ER-).
: , , , . .
-

2.1.



-

2.3.

. 1. 2. 3. . 4. 5
3.

3.1. (MS Access)



. .

3.2. (QBE)

, .
.
. .

QBE SQL-
4. SQL

4.1. Select
Select



4.2.
SQL-

4.3.
.
-


.
, -.
.
MS Access.
: 351400 (
) .


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

: 351400 ( )
.
.
1 ,
, ,
.
2 .

-,
, .
3 MS
Access, QBE.
4 SQL.
.

1.
1.1.

,
(), 1982 ., .
, :
()
,
,
,
,
-
,

.
() ,
.
()
, ,
.
, ,
.
. , ,
, ,
,
,
. ,
, , 6 ,

, , ,
.

,
[1].

,

(, )






, .
, :

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


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

. (,
) , .


, , .


. ,
, , . ,
, .


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


. , ,
; ,
(. ). ,
. ,
1999, 2004 ( 5 ?),
.
. ,
(.. ,
).

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

( ),
( ,
).

1.2.
- ,
. ( ):
1.
2.
3.
4.
5.

.
.

, .

. ,
, .
, , ,

. ,
,
. , ,
, ,
, ,
. ,
-
.

,

,
.

.

, ,
.
,
.
, .
.
,
.
,
- ,
, .
.
. :
;

;
;
;
.
9

,
.

1.2.1.
1. : ,
, (, ) ,
, , -
.
2. :
, ,
().
3.
:
, ;
,
, ;
, ;
;

.
4. :
,
;

.
,

;

.
5. :
, ,
, ;
;

;
;
;

.
6. :
;

.
7. : ,
,
8. :
;
( ) .
9. :
;
;
, ;

.

10

10. :

;
-
;

;
.
11. - :
;
;
;
- ;
;
;
, .

1.3.
1.3.1.
,
. ,
,
:
, (,
).
.
,
, , ,
.
, ,
, .
ANSI (American National Standards
Institute) , . 1-1:

. 1-1.

11

1. ,
. .
,
. ,
, , ,
, .
2. ,
, , ,
.
( ),
. , ,
, .
3. ,
, .
( 1 2)
( 2 3) .

, .

,
.

.

1.3.2.
. 1-2 , ()
.
:

. 1-2.

1. .
2. ,
,
.
3. ( 12)
,
, ( 4)
12

4. .
5. (
).
6.
.
7. ,
.
8.
.
9. .
10. , , ,
, .
,
, , , ,
.
,
.
? , .
, . , ,
,
, ,
, 11 12
.
, ,
,
, .

1.4.

.
, ,
, , . :
, $30 . . ,
, ,
.
. ,
, , ,
.
, ,
, ,
, , .
. 1-3 .

. ,
, ,
.
, :
,
, , , .
, .
, , .

13

. 1-3.

, .

, .
,
. , ,

- ,
, .

,
.

(, , ).

, ,
.
, , , ,
SGML (Standart Generalised Markup
Language), ISO 80- .
, (),
.
, DTD-,
.
, .
SGML , ,
, .
SGML
( HTML),
SGML- .

14

, SGML, HTML
,
. HTML
-
, .
, HTML, ,
HTTP. , , HTML

, ,
HTML
.
HTML ,
.
, , , , XML.
?
XML (Extensible Markup Language) ,
, XML-.
.
XML , ,
.
,
.
-, .
,
,
.
.
,
. , ,
, , ,
, ,
. ,
, , .

1.5.
,
, .
. 0-4. , ,
, ,
.


.
:
1. .
2.
,
, R-.
3. ,
.
4. ,
.

15

. 0-1.

, ,
,

(. 0-5). .

. 0-2.

16

1.5.1.
,
,
, . ,

.
:
,
,
.
,
.

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

,
, ,
, ,
, ,
.

2.
2.1. ()
( )
,
. , ,
.
, .. ,
. 1970-
1980- . , .
"-" (entity-relationship model, ER), 1976 . - .
- , ..
. "-"
(, , , ).
"-" , .
, ,
. , ,
"-".

17

"-":




4.
5.
"-".

2.1.1. -
"-" : , .
,
.
- ,
.
, .
,
.
: , , ..
: , ,
..
. ,
, .
, ,
, . ,
.
:
, .
: , , , ,

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

18

, ..
.
(, , , )

.
- , ,
.
:
, ..
- (, ,
,
)
,
-
(
), -
. , -
, ..
, , .
, n , n- .
.
, n- ,
.
,
, .
.
"-" ,
().
. "-"
(). , ,
(
). 2-1 .
2-1

1,
1,

19

N,
N,

:
-- ( 1:1). ,
A 1 0 B.
. 2-1, , . 1,
.

. 2-1. --

-- (1:N). A 0, 1 N
B. N ""
, (. 2-2).

. 2-2. --

-- (N:1). 1:N.
B 0, 1 N A (. 2-3).

. 2-3. --

-- (M:N). A 0,
1 N B, , B
0, 1 N A (. 2-4).

. 2-4. --


. .
--:
1. ,
1:1. , , ,
. , ,
. , , , , .
, (2-5).

. 2-5. 1:1,

2. (. 2-6).
, ,
20

1:1. , , ..
(
). ,
, .. ( )
. , ,
( ).

. 2-6. 1:1,

3. (. 2-7). ,
, , 1:1.
, .
, . ,
.

. 2-7. 1:1,

-- (--):
4. .
, , ..
1:N (. 2-8). ,
, ..

. 2-8. 1:N,

5. , ,
. ,
. .. N:1, ,
(. 2-9).

. 2-9. N:1,

x y, x
( x "", "" y - ).
1 .
.
6. . ,
. (. 2-10).
( ),
. , N:1,
, -
( , )

. 2-10.

--:
21

7. . , ,
,
. ..
M:N (. 2-11), ,
.

. 2-11. M:N,
, :
8. , ,
,
. ,
(. 2-12).
. .
,
.

. 2-12.

9. . ,
. , , (.2-13).

. 2-13.

2.1.2. -
"-" :


(, ,
, )
"-"
,
. ,
, , ,
.
, :
1.
:
,
22


, , ..

, ..
2.
,

, ,
(, )
, (
)



3.


,


4. ,

,

, :
(, , , (), )
(, , , , , , )
(,
,
,
)
, ,
,
(, )
, :
1. , .. M:N
( 7
2.1.1., . 2-11). :



,



: , ,
(, )
2.
, .. M:N
( 8
2.1.1, . 2-12). :



,

23

: , ,
(, )
3.
, .. N:1
( 6 2.1.1,
. 2-10)
4.
, .. N:1
( 5
2.1.1., . 2-9)
,
"-", . 2-14.

. 2-14. -

2.2.

:
()

24

2.2.1.
( relation )
IBM .. 1970 .
: (
), [1, 2].
() .

,
.
D1, D2,,Dn (
) D1 D2 Dn : d1
d2 dn , d1D1, d2D2,, dnDn.
: D1={a,b,c}, D2={m,k}, D3={y,z}.

D = D1D2D3 =(a m y, a m z, a k y, a k z,
b m y, b m z, b k y, b k z,
c m y, c m z, c k y, c k z)
R, D1, D2,,Dn (n 1), ,
D1 D2 Dn.
D1, D2,,Dn
d1 d2 dn
n ( n=1 - , n=2 - , ..., n-)

.
, .. ,
. ,
. ,
, , , .
,
. .. ;
, .
, . ..
, ,
. ,
; : =, , <,
, >, . , .
,
, n , ,
(. 2-15).
, . ,
. ,
.
: (
, ).
( ) ,
, <- : ->:
{<A1:D1>, <A2:D2>, , <An:Dn>},
Aj Dj (j =
1, 2, , n). A1, A2, , An .

25

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

<- : ->:
{<A1:vi1>, <A2:vi2>, , <An:vin>},
(i = 1, 2, , m, m ).
<- : ->, .. <Aj:vij>, Aj
. <Aj:vij> vij Dj,
Aj.
.. , ,
.
, ,
( ).
, , .
.
, .
( ) .
: ,
. 2-15. : (
), ( ), ()
( ).

. 2-15. /

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

26

,
( ).
( ) ( , ,
, , , )
:
{< : >,
< : >,
< : >,
< : >,
< : >,
< : >},
,
. ,
.
().
:
(681, , , 22:05, 9:30, )
:
{< : 681>,
< : >,
< : >,
< : 22:05>,
< : 9:30>,
< : >},
,
.
, ,
,
; , . ,
,
.
, ..
. , ,
.


,
.





,
.
, ..
, .

,
. , ,
.
"", .. ,
.

.

27

( ) ,
, .
, ..
, .


. , , ,
SQL
. , , ,
.

( ) ,
{ , }.
.
,
, .

. ,
, , .
,
, . , ,
( ). ..
,
, .
R1 .2-16.
, R2 (. 216). R2 R1 (
?).
. , . 216 R2 , R1, R2.

. 2-16.

2.2.2.
.

.
.
3 :



3
.
, ,
, :
28



,
. , ,
, (
, , ,
).
:

, - , ,

(Null) [1, 2]. ,
.
: Null- Null.

:
< > Is Null
< > Is Not Null
2-2 .
2-2

Is Null
Is Not Null
Null
True
False
., 12
False
True
Null- . 2-3
.

2-3
A
True
True
True
False
False
False
Null
Null
Null

B
True
False
Null
True
False
Null
True
False
Null

Not A
False
False
False
True
True
True
Null
Null
Null

A&B
True
False
Null
False
False
False
Null
False
Null

AB
True
True
True
True
False
Null
True
Null
Null


,
SQL.
, .


. ,
.
:
, ,
.
, , .
:

, .. ,
.
29

:
1.
2. ,
?
, , , , .
:
, ,
(
)
,
, ,
( ,
)
,
(Null-),
(
Null-,

)
.
,
,

3. ,
? ,
, .
:
,
(
)
,
,
, ( ,
)
,
,
(
Null-, )


. :
. , ( , ,
, ) :
(.. ) (..
)
( Null-).
,
: , . ..
, , Null-
. ,
,
.,
,

, 1 5,
( MS Access) : Between 1 And 5
30

,
,
( MS Access) : Or .

2.2.3.
,
.
.
:
(- ) .
:

, ,
,

, ,


, ,


, ,
,
:
()
, ,


, ( )

()
, (
),
(
)

, , ,
, ( )

,
. .
: , (),
.
, , .. ,
.

31

,
. , , ,
:
1. ( )
2. ,
, .. ,
: (. 2-17)
1 ,
2 , P2


, ..
. 1
2, .. ,
, .

. 2-17. ( )

-

, , , ,
( ).
A={a}, B={b}, a b
A B,
AB = {c | cA cB},
c ,
.
: , . 2-17,
1 ( , ) 2
( , P2).
R1 (. 0-18), ,
P2 ( ).
,
R1.

32

. 2-18.


, , , ,
.
AB = {c | cA cB},
( ).

: 1 2 (. 217) R2 (. 2-19), ,
P2.

. 2-19.


, , , ,
.
A \ B = {c | cA cB}

,
, ..
. , ..
.
: 2 1 (. 2-17)
R3 (. 2-20), , ,
, P2.
1 2
R4 ( ). R4 (. 2-20)
, P2, ,
.
33

. 2-21.



,
.
, ,
, .
, , c = <c1,c2,,cn> q = <q1,q2,,qm>
, . c q
(c,q).
(c,q) = <c1,c2,,cn,q1,q2,,qm>
n c, m q.

.
.
,
, ,
, , c, ,
c a, A, b,
B.
.. A={a}, B={b},

A B = {(a,b) | aA bB}

,
,
.

, .
: (. 2-17)
R5 (. 2-21). R5 ,
.

34

. 2-21.

,
, . , , ,
, ..
AB = BA
AB = BA
A B = B A
- , ..
A(BC) = (AB)C = ABC
A(BC) = (AB)C = ABC
A \ (B \ C) = (A \ B) \ C = A \ B \ C
A(BC) = (AB) C = ABC

(, )
.
, (),
(), (-) , , . :
1. ,
, D; ,
D, D; D (=, ,
<, , >, );
2. ,
, - , ,
D.
(-),
, ,
, , , ,
,
:
[(t)] = {t | t A (t) = }

. .
:
, P3, 1
(. 2-17) R6 (. 2-22, a)
(. 2-17)
R7 (. 2-22, b)

35

. 2-22.

A X, Y, , Z,
A(A[X, Y, , Z]), {X, Y, , Z} ,
{X:x, Y:y, , Z:z}, , A
X x, Y y, , Z z. ,

, .. ,
, ,
() , .

.
:
1 (. 2-17)
R8 (. 2-23, a). ,
R8
(. 2-17) R9 (.
2-23, b)
.
, (
. 2-17). ,
(. 2-23, c).

. 2-23.

(, )
.
,
.
A B :
{X1, X2,, Xm, Y1, Y2,, Yn}

{ Y1, Y2,, Yn, Z1, Z2,, Zp} ;


.. Y1, Y2,, Yn ( ) ;

36

X1, X2,, Xm A; Z1, Z2,, Zp


B. , (..
) . {X1, X2,, Xm},
{Y1, Y2,, Yn}, {Z1, Z2,, Zp} X, Y, Z .
A B {X,
Y, Z} ,
{X:x, Y:y, Z:z}, , A
X x, Y y,
B Y y,
Z z.

.
, A B ,
.
: 1 (. 2-17).
.
,
, .
1
R11 (. 2-24).

. 2-24.

( -). ,
,
.
A B ,
. A X B Y
,
( ), ,
t, t
X Y . X Y
, .
: ( 1 . 2-17),
( . 2-17). ,
:
37

, (R12);
(R13) (. 2-25).

. 2-25.

A B :
{X1, X2,, Xm, Y1, Y2,, Yn}

{ Y1, Y2,, Yn } ;
.. Y1, Y2,, Yn , A
X1, X2,, Xm, B
. ( A B ).
, (.. )
. {X1, X2,, Xm} {Y1, Y2,, Yn}
X Y .
A B
{X} ,
{X:x} , {X:x, Y:y},
A {Y:y},
B.
:
X- A,
Y- ( A) Y-
B.

( , ),
.
: R14 ,
(. 2-26). ,
, R14
(. 2-26).

38

. 2-26.

, . (,
, , , , , , )
. ..
, , . ,
. , , ..
, : ,
, , , .
.
( )
, , ,
.



.
I. : (, , ).
R1 , P1, R2
, P2, R3 ,
. .
:
1. , , .. ,
R1 R2 , R3
R1R2
\
R3

(R1
\
R3)
(R2
\
R3)
,
2. , , ..
,

R1R2R3
3.
,

(R1R2) \ (R1R2)
4. , ,
(R1R2) \ (R1R2) R3 (R1R3)(R2R3) \ (R1R2)
II. :
R1(, , , )
R2(, )
R3(, ) , ..
.
.
:
1.

(R1[ = ]) [, ]
2.

3000

(R1[R1. = R2. R2. > 3000]R2) []


3.

R3 \ (R1[, ])
39

4. ,

R3 \ R3[ = ]
5.
,

(R1[R1. = R1. R1. R1.]R1)[]


, , ,
.
R1 R1.
6.
,

R4 = (R1[R1. = R1. R1. R1.]R1)[]

R1

R4
(R1[]) \ R4
7. , , , , 1

1
R4
=
(R3[
=

1])
[]

R3[ ]R4

2.2.4. -
- .
-
( ,
..). -
(..
). .
1. -
. ,
.
2. .
.

(.. Null-)
3. .
, ,
(Not Null).
4. , ( 1:N),
,
. , ,
.

5. ,
, .

.
6. M:N. , ,
,
. .

40

-
, -
. , 2.1.2. . 2-14
-.
1. : , ,
, . ,
.
2. (
) ,
. 2-27. 2-4 .
3. , 2-4, .

. 2-27. ER-

41

2-4

()

Null-
( Access)

(30)

(5)

(200)

(50)

(100)

(50)

(15)

(15)

(30)

4. N:1,
( )
( -);
N:1,
( )
( -).
5. ( )
Null-: , .. -
; ( )
Null-: ,
( 0-4).
6. M:N. .
,
. 0-5 .

42

2-5


( Access)

Null-

( ) . 2-28.

. 2-28.

2.3.

, ,
, .
,
.
.
- ,
.
-,
(. 2-28), ..
.

.
, .

43

:
(), ,
( ),

,


,

.
,
,
.

2.3.1.
.
, ,
, ,
.
. Y
X ( ), X
Y. X Y.
,
, ,
.
.
,
- .
. X, Y, Z
. X Y Y Z, , .. Z -/-> Y Y -/-> X.
Z X.
. X, Y, Z R. R
R.X ->> R.Y , Y,
X Z, X Z.
(5).
(3).

2.3.2.
(1): 1,
.
,
, . 1
.
.

. .
(, , , ). ,
,
(), (, ,
).
( 1) . 2-16.

44

2.3.3.
(2): () 2,
1, .
- , :
, :
( )
,
,
, R(k1, k2, a1, a2), 1,
k1, k2 , a1 a2 R,
:
k1, k2 a1 ( a1 k1, k2),
k1 a2 ( a2 k1, ..
)
R 2, :
R1(k1, a2) R2(k1, k2, a1). R1 R2 -- k1.
: (, , ).
,
.
. , :
,
, ,
(, ,
). .. (
):

:
(, ) (, )
:
( ,
)
( )
( , ,
)
.

2.3.4.
(3): 3, 2
.
, R(k1, a1, a2), 2, k1 ,
a1 a2 R, :
k1 a1
a1 a2
a2 k1.
R 3, :
R1(k1, a1) R2(a1, a2). R1 R2 -- a1.
: (, , )
. ,
. .. :
( , -/-> )
( -/-> )
:
(, ) (, )

45

2.3.5. -
, 3, -
(), , ( ) ,
. ,
, 3 .
, R(a1, a2, a3, a4), 3, a1, a2
, a2, a3 , a4 R,
:
a1 a3
a3 a1
a1, a2 a4
a2, a3 a4
R , :
R1(a1, a3) R2(a1, a2, a4)
R1(a3, a1) R2(a2, a3, a4).
: ( , , , , ).
: , , , ,
. :
, ,
, ,


:
( , ), ( , , , )

( , ), ( , , , )

2.3.6.
(4): 4,
, ,
.

R 4 ,
A ->> B R A.
, R(a1, a2, a3),
:
a2 a1 (a1 ->>
a2)
a3
a1 (a1 ->> a3)
R 4, :
R1(a1, a2) R2(a1, a3).
: (ISBN, , , ).
ISBN, ,
( 2-6).
2-6
ISBN


5-123-12345-1

..

5-123-12345-1

..

5-123-12345-1

..

5-123-12345-1

..

:
ISBN
ISBN ->>
ISBN ->>
46

4 :
(ISBN, )
(ISBN, )
(ISBN, )

2.3.7. ( -)
. R (X, Y, ..., Z)
*(X, Y, ..., Z) , R
X, Y, ..., Z. X, Y, ..., Z R.
(5): R 5
, R
R.
, R(k1, k2, k3), 4, k1, k2, k3
, :
*({k1, k2}, {k1, k3}, {k2, k3})
R 5, :
R1(k1, k2), R2(k1, k3) R3(k2, k3).
5 .
-,
, R.

3.

3.1. (MS
Access)

, 2.2.4, MS Access.
.
MS Access
. ,
. 0-1
Access.
0-1

MS Access

3.1.1.

( Access1)
:
64 ;
, ,
(.), (!), (`)
([ ]);
;
( ASCII 0 31);
(") ,
MS Access.
1

MS Access , , , , ,
47

, ,
MS Access .
, , Visual
Basic.

MS Access
. :
1. (. 3-1)
2.
3. :
(Text) , (
), 255
MEMO , ,
., 65 535
(Number) ,
,

,
:

. 3-1.

(Byte) 1 ( 0 255)
(Integer)
2 ( -32 768 32 767)
(Long Integer)
4 ( -2 147 483 648 2 147 483 647)

(Single)

(
-3.402823E38

-1.401298E-45

1.401298E-45 3.402823E38 )

(Double)

( -1.79769313486231E308 -4.94065645841247E-324
1.79769313486231E308 4.94065645841247E-324 )
(Replication ID) 16 ( GUID)
(Decimal) 12 ( 28 )
/ (Date/Time) / 100 9999 (8 )
(Currency) .
. 15
4 - . 8
(AutoNumber) .
: , ,
.
( )
(Yes/No) : ,
, 1
OLE (OLE Object) (, Microsoft Word,
Microsoft Excel, , ),
48

, OLE.
Microsoft Access.
(Hyperlink) .
UNC, URL-. 4- ,
2048
(Lookup Wizard) ,
, .


4. ( )
5. :
,
. :

,
. , /
,
: 25.02.04. 25--04 (
),

( )
, ,

.

.
/, .
( ),

,

, ,
: >0
,
, :

!
:

/
(Null-)

,
. :

( ) ,

( ) ,
.
, (
,
)
6. .2-5
7. . (
)
8.

49


(. 3-28),
(), .
, ,
, ,
, Null- ( 3-4,
3-5). , :
(. 3-2), , (. 3-3), , , .

. 3-2.

. 3-3.

50

3.1.2. .
, ,
.

:
1. ,
, )

2. (. 3-4),
( , )

. 3-4.

3. ,
,
4.
(
).

( ),
(. 3-5).

. 3-5.

(. 36):



51

. 3-6.

(/ )
:

(/ )
:

(/ )

(. 3-7)

. 3-7. N:1

5. .2-4

,
( 3-2), . 3-28.
3-2

. 3-8.

52

. 3-8.

3.2. QBE
QBE ( Query-By-Example ),
SQL, .
QBE SQL,
.
QBE ( , MS Access QBE-
SQL).
QBE .
. 3-8.
,
( 3-3 3-9).
3-3.
()
1

30
2

30
3

60
4

90
5

30
6

10
7

3
8

3
9

30
10

90
11

30
12

10
13

300
14

300
15

90
16

730
17

300
18

3
19

90
20

30
21

730

53

3-4.


1
""
3
, 3
..
223344 223345
2
..
4
, 27
.. 265493
3
8
1
, 17
.. 94238
4
" "
3
, 3
.. 222222
5

5
, 19
..
26748
6
..
3
,8
.. 284732
7
..
6
, 15
..
32212
8
""
2
, 64 ..
45789
9
""
3
, 7
.. 453212
3-5.

3-6.

54

3-7.

2

3

7
-
3-8.

25.03.03
3
15
60,00.
25.03.03
7
15
22,00.
25.03.03
10
15
10,00.
02.01.04
1
20
75,00.
02.01.04
4
10
38,00.
02.01.04
6
40
60,00.
02.01.04
8
10
60,00.
02.01.04
12
40
100,00.
02.01.04
13
30
10,00.
02.01.04
15
10
28,00.
02.01.04
16
10
20,00.
02.01.04
19
5
25,00.
18.02.04
4
4
38,00.
18.02.04
6
12
60,00.
18.02.04
8
11
60,00.
18.02.04
9
10
10,00.
18.02.04
12
2
100,00.
18.02.04
18
8
50,00.
3-9.

()
21

730

31
""

7
2-5
32
""
7
2-5

3.2.1.
1. (. 3-9).
, ,

55

. 3-9.

2. ( )
;
: (.
3-10)

. 3-10.

3. ( , ).
Like , *

56

4. ( ,
, ). , ,
(. 3-11,) (. 3-11,
), (. 3-11, )
5. ( ,
(.. = 3)). ,
, .
,
(, 1.02.04 31.03.04
: >= #01.02.04# And <=#31.03.04#)

. 3-11.

. 3-12.

6. ( ,
15 50 . ). ,
Between And ( ) (. 3-13, ),
>=, >, <, <= (. 3-13, ).

57

. 3-13.

3.2.2. ,
1. .
. , ..
.
(. 3-14, ). . 3-14,
, ..
n*m, n m (
189).

. 3-14.

58

2. .
,
,
, (. 3-15)

. 3-15.

3. . , 2 2004.
(. 3-16)

. 3-16.

4. . (. 3-18). ..
, , .
/ (.
3-17) (. 3-18).
, ,
( ) (Null-).
Is Null
.

59

. 3-17.

. 3-18.

5. . ,

6. .
.
_n, n
. , .. ,
( )
.

60

. 3-19.

3.2.3.
1. .
(, ).

:
: (. 3-20)

. 3-20.

2. (. 3-21)
: ( )
( ) ( () ).

) : [] + [()]

) : []![] + []![()]
, :
- [] (
, /
)

, : []
: []![]
.

61

. 3-21.

3.2.4. .
- ,
. , , ,
, ,
..
.
:
Count ,
Sum ,
Avg ,

Max ,

Min ,

,
, . ,
() :

(Count)

62

, .
(. 3-22).
:
1. (. 0-22, )
, , ,
(. 3-22, ).

. 3-22.

2.

.
, ,
. ..
( , ) (. 3-23).
Date(),
. ,
.

. 3-23.

3. , ,
. ,
: : *, Sum
(. 3-24)

63

. 3-24.

3.2.5.
QBE . ,
, .
, .
1. , 2 2004.
.3.2.2. . 3-16.
. 2.01.04,
(. 3-25).

(. 3-26).

. 3-25.

. 3-26.

2. ?
(. 3-27, , ).
, ,
, () (. 3-27, , ).
64

. 3-27.

3.2.6.
:



(
)

1.
,
(. 3-28)

. 3-28.

, ,
.
, ,
5%: []*1,05

65

2.
.
(
), ( 3-29)

. 3-29.

>21 (.. 1 21
) . 3-30.
.

. 3-30.

3.
(. 3-31)

. 3-31.

66

1 2004. 31 2004. (. 3-32)

. 3-32.

3.2.7. QBE SQL-


QBE-
SQL. , SQL (. 3-33).

. 3-33. QBE- SQL-

, . 3-10 SQL-:
SELECT DISTINCT .
FROM ;

4. SQL
SQL (Structured Query Language)
[4]. IBM Research
1970- ,
IBM, .
1989 . SQL, 1992 .
SQL, .
.
SQL .
. 3-8.
,
QBE, ( 3-3 3-9).

67

4.1. SELECT

SELECT.
SELECT . ()
SELECT .., .. .
SELECT .

4.1.1. SELECT
SELECT :
,
();
WHERE- HAVING- ( ,
" ");
CREAT VIEW, DECLARE CURSOR INSERT;

(INTO-).
:
(*) "" -
, .. " , ";
([]) , , ,
(.. );
({}) , , ,
, ..
, ,
SQL;
(...) ,
;
(|) .
ASC|DESC , ASC DESC;
, ,
(, [ASC]|DESC ,
ASC);
(;) SQL;
(,) ;
( )
SQL;

SQL ( ) ,
;
,
, ,
(_);
, , ... (
) _, _, ..., ;
, _,
; (
) () _
().
SELECT () :
[UNION [ALL] ] ...
[ORDER BY {[.] | __SELECT}

[[ASC]

DESC]
[,{[.] | __SELECT} [[ASC] | DESC]] ...;
68

(UNION) (ORDER BY)


, "".
- ASC (ASCending) DESC (DESCending),
ASC.

( )
SELECT
() ( )
()
FROM
() ,
WHERE
()

GROUP BY
( ) ,
, SELECT SQL- SUM (),
COUNT (), MIN ( ), MAX ( ) AVG
( )
HAVING
() ,


SELECT
[[ALL] | DISTINCT]{ * | _SELECT [,_SELECT]
...}
FROM

{_ | } []
[,{_ | } []] ...
[WHERE
]
[GROUP BY [HAVING ]];
_SELECT - :
[.]* | | SQL_ | _
:
[.] | () | |

( {[ [+] | - ] { | _} [ + | - | * | ** ]}... )
SQL_ :
{SUM|AVG|MIN|MAX|COUNT} ( [[ALL]|DISTINCT][.] )
{SUM|AVG|MIN|MAX|COUNT} ( [ALL] )
COUNT(*)
WHERE :
WHERE [NOT] WHERE_ [[AND|OR][NOT] WHERE_]...
WHERE_ :
{ = | <> | < | <= | > | >= } { | ( ) }
_1 [NOT] BETWEEN _2 AND _3
[NOT] IN { ( [,]... ) | ( ) }
IS [NOT] NULL
[.] [NOT] LIKE '_' [ESCAPE '']
EXISTS ( )

(= | <> | < | <= | > | >=) WHERE


BETWEEN (), LIKE ( ), IN (), IS NULL (
) EXISTS (), NOT ().
69

,
:
AND
- AND ;
OR
- OR ;
AND NOT
- ;
OR NOT
- ,
AND OR ( AND
OR). WHERE
, .
-
, , .
, ,
, ASCII. , ,
,
.
, GROUP BY
GROUP BY [.] [,[.]] ... [HAVING ]
GROUP BY ,
, GROUP BY.
, SELECT,
(, ..).
HAVING (
WHERE)
HAVING [NOT] HAVING_ [[AND|OR][NOT] HAVING_]...
, :
{ = | <> | < | <= | > | >= } { | ( )
| SQL_ }
{_1 | SQL__1} [NOT] BETWEEN
{_2 | SQL__2} AND {_3 | SQL__3}
{ | SQL_} [NOT] IN { ( [,]... )
| ( ) }
{ | SQL_} IS [NOT] NULL
[.] [NOT] LIKE '_' [ESCAPE '']
EXISTS ( )

4.1.2.
1. ( )
SELECT *
FROM
ORDER BY ;
"" (*) ,
FROM. ,
.
, . 3-9, .
2. ( )
.

DISTINCT (, ), :
SELECT DISTINCT
FROM ;
. 3-10, .
70

3. ( , ,
).
WHERE
Like , *

SELECT
FROM
WHERE Like '**' Or Like '**' Or
Like '**';
. 3-11, .
4. ( 1.02.04 31.03.04).
, Between And (
)
SELECT , , ,
FROM
WHERE Between #2-1-2004# And #3-31-2004#;
. 4-1.

. 4-1.

4.1.3.
1.

. , ..
.
SELECT *
FROM , ;

SELECT .*, .*
FROM , ;
. 3-14, .
2.
.
, ,
.
,
.
SELECT .*, , , [()],
FROM ,
WHERE . = .;
. 3-15, .
3.

2004.


71

SELECT , , ,
FROM ,
WHERE

=
#1-2-2004#
AND
.
.;
. 3-16, .

4. , , ,
. .
, :
SELECT .*
FROM
UNION SELECT .*
FROM ;

4.1.4.
1.
(,
).
( )
.
SELECT
DISTINCT
.
AS
,

FROM ,
WHERE . = .;
. 4-2.

. 4-2.

2.
( , ).
. .
: ( )
( ) ( () ).
, .
SELECT , , [] + [()] AS

FROM ,
WHERE . = .
ORDER BY ;

72

4.2.

4.2.1. SQL-
SQL (SQL-).
COUNT(*)
, :
COUNT ,
SUM ,
AVG ,

MAX ,

MIN ,

SUM AVG .
, - ,
, ,
()
. , ,
, SQL- ( SQL-
). SQL- .
, COUNT(*),
DISTINCT (), ,
, .
COUNT(*)
( ).
1.
SELECT Count(*)AS
FROM ;

GROUP BY, _SELECT
SQL- , . ,
, SQL-.
2. (=8), ,

SELECT Sum() AS , Count() AS
FROM
WHERE = 8;

3.
SELECT , Sum([]*[]) AS
FROM
GROUP BY ;

73

GROUP BY ( ) FROM
, , GROUP BY.
,
= 25.03.03,
= 02.01.04 .. (. 3-6). SELECT.
, ..
, GROUP BY, ,
, , SQL-,
(, ).

4.2.2.

- ,
WHERE (HAVING) SELECT , WHERE
. WHERE (HAVING)
.. , ,
, .
. WHERE
(HAVING) IN, EXISTS ( = | <> | < | <= | >
| >= ). " ".
. ,
, ..

. ,
, ,
( ).
, . ..,
,
( ).
IN
,
- IN
1.
9, .. .

SELECT ,
FROM
WHERE IN
(SELECT
FROM
WHERE =9);
,
. ,
= 9, (1, 2, 3).
:
SELECT ,
FROM
WHERE IN (1,2,3);

74

2.
9, ,

SELECT ,
FROM
WHERE IN
(SELECT
FROM
WHERE IN
(SELECT
FROM
WHERE = ''));

(9). ,
(1, 2, 3). , SELECT,
. .
SQL .
:
SELECT ,
FROM , ,
WHERE . = .
AND . = .
AND = '';

, .
, ,
.
3.
, ,

SELECT
FROM
WHERE IN
(SELECT
FROM );

SELECT .
FROM ,
WHERE . = .;
4.
, ,
SELECT
FROM
WHERE NOT IN
(SELECT
FROM );

, IN
, , .
SELECT
FROM
WHERE =
(SELECT
FROM
WHERE = '');
75


(<>, <=, <, >=
>), ,
IN, .

4.3.
UPDATE (),
INSERT () DELETE ().

UPDATE :
UPDATE ( | }
SET = [, = ] ...
[WHERE ]
: | | |
, ..
,
, .
WHERE
. WHERE ,
.
: ,

UPDATE SET = ''
WHERE = '';

INSERT :
INSERT
INTO { | } [( [,] ...)]
;
, .. SELECT
, .
i- (i- SELECT) i-
.
:
> 21
INSERT INTO (, , , [()],
)
SELECT , , , [()],
FROM
WHERE . > 21;

DELETE
DELETE
FROM |
[WHERE ];
( WHERE
) , WHERE .

76

1:

DELETE .*
FROM ;
2:
1 2004. 31 2004.
DELETE
FROM
WHERE Between #1-1-2004# And #1-31-2004#;

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

.
, ,
, ,
.

. ,
, -
.
,
, ,
. , -
.
-
- () .
1980-.
.
.
, , :
,
.
-
. ,
.
.
,
.
.
-
.
, . ,
(), .
, .
.
, .
, ,
- , .
77

, ,
.
, , ..,
. ,

() () . ,
,
. , ,
.


,
, , , ,
.
:
;

;
.
.
.
.
- , .
, -
.

.
t
. ,
,
.
,
. ,
. SQL date time.
:
;
( ,
); .
.
, ,
.. ,
, t1 t2,
( ) [t1,t2].

. - .
, ,
.

78


()
()


()

()

,


, , , , ,


,
,

, ,

, ,
, ,
, ,
,
, ,
,
,
,

,

( )
,
()
,

, ,




, .. ,
.
.
,
,

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

,
,
,



,


79


(Null-)

SQL



, ..

,

,
,
,



80

1. .. / .. . .;.;: , 2001. 1096 .


2. .. : , , / .. . .: , 2001.
304 .
3. .. Microsoft Access 2002 / .. , .. .: , 2002.

1. .. / .. .: ,
1995.
2. .. / .. , ..
., 1989.
3. . / .
.: , 1991.
4. .. (SQL) / .. , .. .:
, 1994 (http://iclub.nsu.ru/~abstract/docs/SQL/index.shtml)
5. . / . .:
, 1984.
6. . / . .: , 1987.
7. . . 2 . / . , . .: , 1985.
8. . / . , . .: , 1985.

81


-
1.

2.
3.
4.

5.

6.

7.

:
1:1
1:N
M:N
.
.
"-", 2.1.2,
?
"-" .
:
, (, , , )

( ),



- .
:

2 3-


- .
:

(, , , )
(, )

- ,
( )?


1. -, ,




2. , ,
Null- .


1.
2.
3.
4.
5.





,
5.1. :
1 (ISBN, , ) , ISBN
2 (ISBN, , ) ,
3 (ISBN, , )
, ,
, .
:
a)
82

b) ,
c) ,
d) ,
e)
5.2. :
(, , )
(, , )
(, , , )
(, )
(, , , )
.
.
.
a) , 15
b) , 25.10.04 20.12.04
c) ,
d) ,
e) ,
f) ,
g) , ,

( )


4
1. (, , , , , )

2. ( , , , )
,
3. ( , , -, )
4. (, , , )
5. (, , )
, ,

6. ( , , , )
7. (, , , )

8. (, , , , , )
9. ( , , , , ,
)
1
10. (, , )

11. ( ., , , , , )
5 ,

QBE
1. ,

, :


1 23
() ?
?
?

83

,
, 50 ( )
?
2. ,
, :


,
1 ?
1- ?

?

?
?
3. ,
, :
( ),

(, )
(, )


( )
,

,

SQL
1. ,
, :

, ( )
,

, , (
)
2. ,
, :
, 1-

?
1-

3. ,
, :


( )
1 31

84



. ,
, .
.
.
. , , :
;
;
( );
();
;
;
;
;
.
, (ISBN).
. :
, , ;
;
( , );
.
.
5 .
.
.
:
;
, ;
,
:
, ;
;
.
:
1. .
2. 17 .
3. , 1960 .
4. 5 .
5. :
.
6. ,
.
:
;
;
.
:
1. .
2. .
3. , .
4. , ,
, ,
.
5. . ,
. ,
85

6.

7.
8.

.
, :
. ,

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

:
1. , ,
.
2. , .
3. ,
.
.
, (
).
4. , .

:
1. ,
;
2. , , . .
;
3.
4.

,
;
, ,
.

86