DATABASE SYSTEMSA Practical Approach to Design, Implementation,
and Management
Third Edition
Thomas M. Connolly Carolyn E. BeggUNIVERSITY OF PAISLEY
A TTADDISON-WESLEY Boston San Francisco New York Toronto
Montreal London Munich Paris Madrid Capetown Sydney Tokyo Singapore
Mexico City
http://openlib.org.ua/
http://openlib.org.ua/
,
,
- 2003
http://openlib.org.ua/
32.973.26-018.2.75 64 681.3.07
"". .. .. , . . "" : [email protected],
http://www.wiHiamspubUshing.com , , , . 64 . , . . 3- . : . . . :
"", 2003. 1440 . : . . . . ISBN 5-8459-0527-3 (.) , , . , . Web
Web, JDBC, SQLJ, ASP, JSP PSP Oracle. , OLAP, , - - . , , , , .
32.973.26-018.2.75 . , , , Addi:;on-Wesley UK. Authorized
translation from the English language edition published by
Addison-Wesley Longman, Inc., Copyright Pearson Education Limited
1995, 2002 All rights reserved. No part of this book may be
reproduced or transmitted in any form or by any means, electronic
or mechanical, including photocopying, recording or by any
information storage retrieval system, without permission from the
Publisher. Russian language edition published by Williams
Publishing House according to the Agreement with R&I
Enterprises International, Copyright 2003 1BN 5-8459-0527-3 (.)
ISBN 0-201-70857-4 (.) "", 2003 Pearson Education Limited, 1995,
2002
http://openlib.org.ua/
I.
23 2541
1. 2. . 3. 4. 5. SQL:
43 77 113 115137 163
6. SQL: 7. QBE 8. : Access Oracle III. 9. , 10. 11. "-" 12. "-"
13. IV. 14. 15, 16. 17.
211 255 283 329 331 367 397 429 447 495 497 525 569 603619 621
655 723 777
V. 18. 19. 20. 21. SQL
VI. 22.
813 815
http://openlib.org.ua/
23. 24. 25. - 26. - 27. - VII. 28. Web- 29. XML 30. 31. 32, OLAP
VIII. . DreamHome . . . . ER- . . 3. Web-
869 927 961 1005 1049 1105 1107 1173 1227 1263 1289 1315 1317
1325 1339 1359 1365 1369 1377 1381 1395 1413 1427
http://openlib.org.ua/
UML ( ) I. II. III. IV. V. VI. VII. I. 1. 1.1. 1.2. 1.2.1. ,
1.2.2. , 1.3. 1.3.1. 1.3.2. 1.3.3. 1.3.4. 1.4. 1.4.1. 1.4.2. 1.4.3.
1.4.4. 1.5. 1.6.
23 25 25 26 27 28 29 30 30 31 31 31 32 33 33 34 35 36 38 38 40
40 41 43 44 46 47 52 55 55 56 60 62 63 63 64 65 65 65 68
http://openlib.org.ua/
2, 2.1. ANSI-SPARC 2.1.1. 2.1.2. 2.1.3. 2.1.4. , 2.1.5. 2.2.
2.2.1. DDL 2.2.2. DML 2.2.3. 4GL 2.3. 2.3.1. 2.3.2. 2.3.3. 2.3.4.
2.4. 2.5. 2.6. 2.6.1. 2.6.2. 2.6.3. "/" 2.7. 2.7.1. IRDS
7778 80 80 81 81 83 84 84 85 86 88 89 90 92 92 93 98 101 101 102
102 107 108
. 3. 3.1. 3.2. 3.2.1. 3.2.2. 3.2.3. 3.2.4. 3.2.5. 3.2.6. 3.3.
3.3.1. 3.3.2. 3.3.3. 3.3.4. , 3.4. 3.4.1. 3.4.2. 3.4.3. 4. 4.1.
4.1.1. 4.1.2. 4.1.3. 4.1.4. 4.1.5. 4.2.
113 115116 117 118 121 122 123 124 126 128 128 129 130 130 131
131 132 132 137 138 139 141 145 149 150 152
http://openlib.org.ua/
4.2.1. 4.2.2, 4.3. 5. SQL: 5.1. SQL
152 156 159 163 164 166 167 168 168 169 170 179 184 187 190 198
199 202 211 212212 213 191 182 164
5.1.1. SQL 5.1.2. SQL 5.1.3, SQL 5.1.4, 5.2. SQL 5.3. 5.3.1.
5.3.2. ( ORDER BY)5.3.3. SQL
5.3.4. ( GROUP BY) 5.3.5. 5.3.6. ANY ALL5.3.7.
5.3.8. EXISTS NOT EXIST UNION, INTERSECT EXCEPT) 5.3.10. 6. SQL:
m 6.1. SQL, ISO 6.1.3. ( exact numeric) 6.2. 6.2.2. 6.2.3. 6.2.4.
6.2.5. 6.3. 6.3.1. 6.3.. ( CREATE TABLE) 6.3.5. ( CREATE INDEX)
6.3.6. ( DROP INDEX) 6.4. 6.4.1. ( CREATE VIEW) 6.4.2. ( DROP VIEW)
6.4.3. 6.4.4. 6.4.5. 6.4.6. WITH CHECK OPTION 6.4.7. 6.4.8. 6.3.3.
( ALTER TABLE) 6.3.4. ( DROP TABLE) 6.2.1. 6.1.1. SQL 6.1.2. SQL
5.3.9. (
214 218218
219 220 221 222 223 223 224 230 231 231 232 235 235 236 237 239
240243 228 230
6.5.
244
http://openlib.org.ua/
6.5.1. 6.6. 6.6.1. ( GRANT) 6.6.2. ( REVOKE) 7. QBE 7.1.
Microsoft Access 7.2. QBE 7.2.1. 7.2.2. 7.2.3. 7.3. QBE 7.3.1.
7.3.2. 7.3.3. 7.3.4. , 7.3.5. 7.4. 7.4.1. 7.4.2. 7.4.3. 7.4.4. 8. :
Access Oracle Microsoft Access 2000 8.1.1. 8.1.2. Microsoft Access
8.1.3. 8.1.4. 8.1.5. 8.1.6. 8.1.7. 8.1.8. 8.2. Oracle 8/8i 8.2.1.
8.2.2. Oracle 8.2.3. 8.2.4. 8.2.5. PL/SQL 8.2.6. , , 8.2.7. III. 9.
, 9.1. 9.2. 9.3.
246 246 247 249 255 256 259 259 262 265 266 267 269 269 272 273
274 274 277 277 277 283 283 284 284 286 291 292 294 295 298 299 301
303 311 314 315 320 322 329 331 332 333 335
http://openlib.org.ua/
9.4. 9.4.1. 9.5. 9.5.1. 9.5.2. 9.6. 9.6.1. 9.6.2. 9.6.3. 9.7.
9.7.1. 9.8. 9.8.1. 9.8.2. 9.9. 9.10. 9.11. 9.12. 9.13. 9.14. CASE-
9.15. 9.15.1. 9.15.2. 9.15.3.
336 337 337 339 339 340 341 342 343 346 347 351 351 353 355 355
356 356 357 358 360 360 361362
10. 10.1. 10.2. 10.3. 10.3-1. 10.3.2. 10.3.3. 10.3.4. 10.3.5.
10.4. 10.4.1. DreamHome 10.4.2. DreamHome 10.4.3. DreamHome 10.4.4.
DreamHome 10.4.5. DreamHome 11. "-" 11.1. 11.2. 11.2.1. 11.2.2,
11.3. 11.3.1. 11.3.2.
367 368 368 370 370 370 371 372 373 373 374 379 388 395 397 398
401 403 404 405 407 11
http://openlib.org.ua/
11.3.3, 11.3.4. 11.4. 11.5. 11.6. 11.6.1. " " 11.6.2. " " (1:*)
11.6.3. " " 11.6.4. 11.6.5. 11.7. - 11.7.1. "" 11.7.2. "" 12. ""
12.1. / 12.1.1. 12.1.2. / 12.1.3. 12.1.4. 12.1.5. 12.1.6. / 12.1.7.
/ Branch DreamHome 12.2.
407 408 410 410 412 412 413 415 416 418 419 419 422 429 430 430
431 432 433433 436 437 441
12.3. 13. 13.1. 13.2. 13.2.1. 13.2.2. 13.2.3. 13.3. .
443 447 448 449 450 450 451451
13.3.1. 13.3.2. 13.3.3. 13.3.4.
451
455 456 458459
13.4.
13.5. (1) 13.6. (2) 13.6.1. 13.6.2. 13.7.2. 13.8. 13.9. - ()
13.9.1. ' - 13.10. ( 1 ) 13.11. (4)13.7. () 13.7.1.
460 464 465 465 468 472 472 473 476 483 468 468
http://openlib.org.ua/
13.11.1. 13.11.2. 13.12. (5) 13.12.1. 13.12.2. (5) IV. 14. 14.1.
14.1.1. 14.1.2. , 14.1.3. 14.2. 14.3. 1. 15. 15.1. 2. 3. 16. 16.1.
16.2. 16.3. 4. 5. 6. 7. 17. , 8. 9. V. 18. 18.1.
483 485 486 486 486 495 497 498 499 499 500 500 503 503 525 526
526 549 569 570 571 572 573 578 598 599 603 603 614 619 621 622
13
http://openlib.org.ua/
18.1.1. 18.2. 18.2.1. 18.2.2. () 18.2.3. 18.2.4. 18.2.5. 18.2.6.
RAID ( ) 18.3. Microsoft Access 18.4. Oracle 18.5. Web 18.5.1. -
18.5.2. 18.5.3. 18.5.4. 18.5.5. Kerberos 18.5.6. HTTP 18.5.7.
18.5.8. Java 18.5.9. ActiveX 19. 19.1. 19.1.1. 19.1.2. 19.2.
19.2.1. 19.2.2. 19.2.3. 19.2.4. 19.2.5. 19.2.6. 19.2.7. 19.2.8.
19.3. 19.3.1. 19.3.2. 19.3.3. 19.4. 19.4.1. 19.4.2. 19.4.3.
19.3.4.
623 625 627 630 631 631 632 633 635 638 640 643 643 644 645 646
646 647 648 651 655 656 659 660 660 660 664 671 679 683 687 689 690
694 694 695 699702
705
19.4.4. 19.4.5. 19.5. Oracle 19.5.1. Oracle 14
706 709 710
711 712 713 714
http://openlib.org.ua/
19.5.2. 19.5.3. 19.5.4. 20. 20.1. 20.2. 20.3. 20.3.1. 20.3.2.
20.4. 20.4.1. 20.4.2. (S = a p (R)) 20.4.3. (T=(R >400;
70
I.
http://openlib.org.ua/
, , . , . , , . , . ( ), , . (, 40 41 ) , . : , . . 2.1.5. , . ,
. , . 19. . , . , , , , . . 19.3.
, , . 1.9.
1.
71
http://openlib.org.ua/
1.9.
, , . , , , . , . , , . . , 100 . , , : 100 000 1 000 000 . , ,
. , , . , , , , . . . 72 I.
http://openlib.org.ua/
, , . , . , , . , , . , - . , . . , .
() , . , . , .. , , . . , , . , . ( ), . , , , . , (Data
Definition Language DDL), , (Data Manipulation Language DML), , . .
, , /, . , , . 73
1.
http://openlib.org.ua/
(), (, ), , . , , . . CODASYL . IMS (Information Management
System), (CODASYL-) - IDS (Integrated Data System). 1960- . , . .
1970 , . , 100 . - . , , , , , . , , .
1.1. 1.2. , , 1,1. : ) ; ) ; ) ; ) ; ) ; ) ; ) . , . ? , , . . ?
: ) ; ) ; ) ; ) ; ) ; ) . ?
1.3. 1.4. 1.5. 1.6.
1.7.
74
I.
http://openlib.org.ua/
11.8.
. |'|1111|1|'111||1'|111|111 ; t ^
. ? ? ? 1.9. ( , ), ( , , , , ). . . , , . , ? 1.10. DreamHome,
10.4 . ? , , ? ? , , ? 1.11. Wellmeadows Hospital, . ? , , ? ?
1.
75
http://openlib.org.ua/
http://openlib.org.ua/
...
. , . . . DDL DML. . . . . "/" . ( Transaction Processing) . ( )
, , . , , . "" , , . , DreamHome : " ", staff (), PropertyForRent (
), PrivateOwner ( ) Client (); , (, staff name (), position ()
salary ()); (, Staff Manages PropertyForRent).
http://openlib.org.ua/
, , , , . ANSISPARC. .
2.1 ANSI-SPARC , . 2.2 , , 2.3 , . 2.4 , , 2.5 2.6 . 2.7 , (.. ,
). DreamHome, 10.4 . . , , . , , .
2.1. ANSI-SPARC 1971 DBTG. CODASYL (Conference on Data Systems
and Languages ), . DBTG , , .. (schema), , .. (subschema). 1975
SPARC (Standards Planning and Requirements Committee) (American
National Standard Institute ANSI), ANSI/X3/SPARC [5]. ANSI/SPARC .
, Guide and Share, IBM, . [144]. ANSI/SPARC , . , .. . , , 78
I.
http://openlib.org.ua/
, . 2.1. , , (external level), (internal level). , . (conceptual
level) . . , . , . , . , ( ). , . () , . , . - . 1 2 ?
1 \ 1
. 2,1. ANSI-SPARC
2,
http://openlib.org.ua/
2.1.1. ' . . , , . . . " ", . , " ", . , , , , . , - . , (, , ),
(, , ). , , . , DreamHome . , . , . . 3.4 6.4.
2.1.2. . ; ,1 , , , . " ' :";,'"^
. ( ). , . : , ; ; ; . , , ( ) . . , (, 80 I.
http://openlib.org.ua/
) ( ), , .
2.1.3. . . 5 , . . , . ( ) , , .. : ; ( ); ; . (physical level),
, . . , . (, , ).
2.1.4. , . , , . 2.1. , . , . , , . , . , ' , . . 2. 81
http://openlib.org.ua/
, . , , . . . , , , , . , , , .. , . . . 2.2. : (sNo), (fName)
(iName), (age), (salary). (staf fNo), (IMame) , (branchNo). . ,
(age) (DOB). . , sNo staf fNo . , . . (next), . , , . , . 1 2
struct STAFF { intstaffNo, int branchNo, charfName [15], float
salary, struct STAFF 'next,
/* Staff *//* */
index staffNo, index branchNo;
, 2.2.
82
I.
http://openlib.org.ua/
. . , , . , . , , . , . , ,
2.1.5. , , . : . . ^ , -1 . , , , . , , , , , . . *! , . , , , ,
. . . . 2.3 . ANSI-SPARC , . ANSISE'ARC , . , . 2. 83
http://openlib.org.ua/
. 2.3. ANSISPARC
2.2. ^: (Data Definition Language DDL) (Data Manipulation
Language DML). DDL , DML , . , , , . , , COBOL, Fortran, Pascal,
Ada, , C++, Java Visual Basic. (host language). , , . , , . . , , .
*
2.2.1. DDL DDL. , , ^, , , , . , DDL. DDL , . . !.
http://openlib.org.ua/
DDL- , , . .. , , . , , , . . , ( ) , . 2.7. DDL, DDL , DDL DDL
. DDL, , , .
2.2.2. DML DML. , one-j ; . : ; , ; , ; . , , . , . , . , , , .
DML, , . , . "" , . " " " " , , . DML . DML: . , , DML, , . , , .
2. 85
http://openlib.org.ua/
DML DML. , , , , . DML , , , . , ( ), . DML , , , , , .. , . DML
, . DML ( 2.3).
DML DML. , , , , . DML . DML , , . DML ( ), . , . . . SQL
(Structured Query Language) QBE (Query-by-Example). , . DML, , .
SQL 5, 6 21, QBE 7.
2.2.3. 4GL 4GL (Fourth-Generation Language). , , , . 86 I.
http://openlib.org.ua/
(3GL) COBOL , 10-20 . , 4GL , , , , . , , " ". , , , . , , , . :
, ; , ; , , , ; , . SQL QBE. .
, . , . , , , , .. , .
. , , . , , . , . 2. 87
http://openlib.org.ua/
: . . , .
, . , , , ..
, . , , . , , . , , "" . , , , .
2.3. , . . , ; , . , , . . . , , . " " , . , , . , , . , , . .
88 I.
http://openlib.org.ua/
, .. , . , ( , ). () , . . , . 2.1 ANSI-SPARC : , , (Universe of
Discourse UoD); , ( ) , ; , , . . : (object-based) , (record-based)
. , .
2.3.1. , , . ( , , ), . , , . . "-", ER- (Entity-Relationship
model). . . - . ER- , . - , , , , .. . , . "-" 11 12, - 24-27.
2.
89
http://openlib.org.ua/
2.3.2. , . , . : (relational data model), (network data model)
(hierarchical data model). , .
. , . . 2.1 2.2 DreamHome, . , . 2.2 , John White 30000
(branchNo) 005, , . 2.1, 22 Deer Rd, London. , Staff Branch : . ; ,
, branchNo Staff branchNo Branch. 2.1. Branch branchNo 005007 8003
004 002
street 22 Deer Rd 16ArgyllSt 163 Main St 32 Manse Rd 56 Clover
Dr
city London Aberdeen Glasgow Bristol London
postcodeSW1 4EH
AB23SUGil 9QX
BS99 1NZNW10 6EU
2.2. Staff staffNoSL21
fName JohnAnn
IName White Beech Ford Howe BrandLee
position
sexMF M
DOB
salary 30000 1200018000
branchNoBOOS
SG37SG14SA9 SG5
Manager AssistantSupervisor
David Mary Susan Julie
l-Oct-45 lO-Nov-60 24-Mar-58 19-Feb-70 3-Jun-40 13-Jun-65
B003
SL41
Assistant Manager Assistant
F F F
900024000
B007
BOOS
9000
90
i.
http://openlib.org.ua/
, , . , .. ANSI/SPARC. , . 3.
, . , , . . . 2.4 , . 2.1 2.2. IDMS/R Computer Associates. Web-
(URL ).005 22Deer.nd i. '!!'::!
su
Julie
Assistant' ' Manager-:
BOQTJ?004 002
16ArgyllSt: 32 Manse Re!'-' jr. "Brtsto('-ii 56 Clover Dr-:: '
r::"-l3(Ktofi ' ,'i., SG37 I Ann '[ ^Seech [ ..;. j Ford Brand
Assi^lant^jAs'slsta^t'" [; 1)
\1 SG14 j David | SG5 Susan
j ... {supervisor | 15000 | Manager!
Puc. 2.4.
. , . . ( ) . . 2.5 , . 2.1 2.2. IMS IBM, . Web (URL ). () . , ,
. 2.
91
http://openlib.org.ua/
\~~\1QQ4. L-. 3003 I SL4i^ j Julie | __lje 1 .;, | ; Asslstant
Tj;; /iiQQO: : ; :
BOOS .:'J Gtasgw'l j 007..
SL21 [ John j While TSG37| Ann_]^'BeeiJl | 7.[ ^ssjstant ; | ;
12 Ford (~SG5~| Susan | Brano |; .-J [/24^ i SA5 [ Mary | ' Howe ]
.;;;: ; :
Puc. 2.5.
, . , . , , . , (.. , ), (.. , ).
2.3.3. , , , . , , (unifying model) (frame memory).
2.3.4. , "" . , . . 1 . , .
92
I.
http://openlib.org.ua/
. ( ) . , , , . . . . , . 14 15 , , , . 9.6.
2.4. , . , [71]. .
1. , | , = = . . , 2.1, , (, ).
2. , , | . ANSI-SPARC , , .. , , , ( ) , ( , " ", ). . : , ; ;
2. 93
http://openlib.org.ua/
; , ; , (. 2.1,4); , . , . , , . , . , . , . . . , , , . . . . ,
, (data directory), . " " . 2.7.
3. , ;;!:; , , , . DreamHome , . . . , - , , 94 I.
http://openlib.org.ua/
, . , . 19.1.
4. : , | - i : . .' , . , , . , , , . 2 , . 2.3. 2.3. " " t| t3
tj.-s
TIread (bal x ) bal x = bal x - 10 write (balx)
2read (bal x ) bal x = bal x + 100 write (bal x )
balx100 100 200 90 90
: 10 , 1, 2 100 . , .. , , 190 , . . , 2 , 100 . 2 100 ( 200 ) .
TI 10 ( 90 ) , "" 100 . , . 19.2. 2. 95
http://openlib.org.ua/
5. - . , . , , . , . . 19.3.
6. , . , & . , , , . , . . , . 18.
7. -' . . . , , . (communications messages) . (DEM Data Exchange
Manager). , , , . , . , 96 !,
http://openlib.org.ua/
, . . 22.1.1.
8. : , . . . , , , . , . , , . , , . , , , .
9. , . 2.1.5, . , , . . , , , . .
10. | . . , , , , . . 2. 97;''
'
-
.-"'":'
'.-
-
/"-
...
...;..-.
'.;,
http://openlib.org.ua/
, , , . , . , . , . , .
2.5. , . , . . , 8.2.2 Oracle. (), . , . , . , . . 2.6. , , ,
(.. , ). . [302], [325], [404] [585]. . 2.6 . . , . 20. . . , . . .
2.7.
98
I.
http://openlib.org.ua/
. 2.6.
. . , . , . , , ( ). DML. DML- . DML . DDL. DDL DDL , . , . . .
. , . 2.
99
http://openlib.org.ua/
. 2.7. . . . . . , , , (, , ). . . 20. . , . 100 I.
http://openlib.org.ua/
. . , . . . , . . , . ( ) , . 19. , , . DAFTG (Database
Architecture Framework Task Group) 1986 . ,
2.6. , , , "/".
2.6.1. , , , . 2.8. , "" , . , ( ). , . . , , , (, , ). .
(downsizing), .. , , , , , . : "/". 2. 101
http://openlib.org.ua/
. 2.8.
2.6.2. , (). , . , , . 2.9. , . , . , . , , , , 163 Main St. SQL
( 5): SELECT fName, IName FROM Branch b, Staff s WHERE b.branchNo =
s.branchNo AND b . s t r e e t =
163 Main St
SQL, , Branch () S t a f f (), . , . 1. . 2. . 3. , , .
2.6.3. "/" "/" , . , -
102
!.
http://openlib.org.ua/
. , , , , . , . , . . 2.10 "/", . 2.11 "/". 2
Hlfllilll
;
1I MMI '\
""1"
Ni.nir
. 2.9. 2
3
I
~^
; SUlJJl !1
!-^-.
1
"" ()
. 2.10. "/" 2.
103
http://openlib.org.ua/
2)
3
2
. 2.11. ^ "/": ) ; ) ; &J
, , . , SQL , . , . , . , , , . , . . 2,4.
104
I.
http://openlib.org.ua/
2.4. , "/"
/
. . . , . , . . . . , . . , . . . , .. , . , , "/" , . 22 23.
28.3.2 "/", , . "/" 2. 105
http://openlib.org.ua/
, . . , Internet , Web-. , .
(). , , , , (On-Line Transaction Processing OLTP)., .; -.:.'.
,.:.,..'.,; . , -,.;, . . . . " , ....". -..' -. . ;
-
( , , ). ( -) , , . - , . 2.12. , . . - .
1
2
3
. 2.12. - "/"
106
!.
http://openlib.org.ua/
. - , , , . , , Oracle 1, Informix 2 IMS 3. - DTP (Distributed
Transaction Processing ) /Open. , , -, . DTP 22 23. . - , , . , , .
. . . - , , , , . , . ; , , , . , - , . - , . - . - . - CICS Encina
IBM ( IBM AIX Windows NT, IBM TXSeries), Tuxedo BEA Systems.
2.7. 2.4 , . . . , , .. , " ". 2. 107
http://openlib.org.ua/
. 2.5 , . , , . : , ; ; , , , , . , , . : ; ; , ; . , " " , . ,
. , . - . , . . , - . , . , . , . .
2.7.1. IRDS , , . . , , , , CASE-, , . 108 I.
http://openlib.org.ua/
, . , . . (Information Resource Dictionary System IRDS). IRDS ,
, . , , , . . , IRDS , IRDS- DB2, IRDS- Oracle DB2. IRDS . , - (,
), IRDS . IRDS (International Organization for Standardization ISO)
[172], [174]. IRDS , : ; ; . IRDS , , . , ; ; /; . , . QBE . , . (
) . / , IRDS- . IRDS . , , , - . IRDS , . 2.13. 2. 109
http://openlib.org.ua/
. 2.13. IRDS
ANSI-SPARC : , . . . , . , , , , . . , , , .. . . . , . , . :
DDL (Data Definition Language) DML (Data Manipulation Language).
DDL , DML .110
!.
http://openlib.org.ua/
, , , . : , . , . "-", , - , , . , , , , . , . "/" ( ), , . , .
(-) , , , , (On-Line Transaction Processing - OLTP). : , , , . . "
", . . IRDS (Information Resource Dictionary System) ISO, . .
2.1. 2.2. 2.3. 2.4. 2.,5. 26. . ANSI-SPARC. . ? . . , . 2.5 , ?
. 111
2.
http://openlib.org.ua/
2.7.
, 2.5. 2.8. , "/". , . . 2.9. (-)? (OLTP)? 2.10. .
2.11. , . , . ? ? . ? 2.12. , . , . , . ? 2.13. , . , . , . , .
2.14. , 2.13, "/"? , ?
112
I.
http://openlib.org.ua/
SQL: SQL: QBE : Access Oracle
115 137 163 211 255 283
http://openlib.org.ua/
http://openlib.org.ua/
... . . . . . , , . " " " ". , .
. 15-20 ( 50 ), 25%. , , . . (. F. Codd) 1970 . (). () . () . .
, , , (.. ). . . , .
, 3.1 -
http://openlib.org.ua/
. 3.2 . 3.3 , . 3.4 , , , , . , 5, 6 21, SQL (Structured Query
Language ), , 7 QBE (Query-By-Example), . 14-17 . , . DreamHome,
10.4 .
3.1. . . (. F. Codd) 1970 " " [65]. , , , [58]. . . , , , . , .
, , .. . ( 13.) . , . 1970- IBM , , (Astrahan), "System R", [9]. .
, , , , , , . - . , System R : 116 II.
http://openlib.org.ua/
SQL ( "S-Q-L", () "See-Quel"), ISO (International Organization
for Standardization) ; , 1970- 1980- , DB2 SQL/DS IBM, Oracle
Oracle Corporation. , , INGRES (Interactive GRaphics REtrieval
System), ( ) , System R. INGRES , System R. INGRES, . INGRES
Relational Technology Inc. ( INGRES II Computer Associates)
Intelligent Database Machine Britton Lee Inc. Peterlee Relational
Test Vehicle IBM, , [305]. , System R INGRES. , , , . 1970- - 1980-
. , , , . Access FoxPro Microsoft, Paradox Corel Corporation,
InterBase BDE Borland, R:Base R:Base Technologies. , . , IDMS
Computer Associates, CA-IDMS/SQL . , , Model 204 Computer
Corporation of America ADABAS Software AG, , , [70], - [294],
[121]. , 24-27, .
3.2. , . , , , , . , . 3. 117
http://openlib.org.ua/
3.2.1. . . , .; , . , , .. ANSI-SPARC, 2.1. , ( ), . . , ;1 . ,
, . , . , Branch, faranchNo ( ), street (), city () postcode ( ).
Staff (), staff No ( ), fName (), IName (), position (), sex (),
DOB ( ), salary (), branchNo ( ). . 3.1 Branch Staff. , , branchNo
. . . . . , . . 3.1 Branch S t a f f . , , . , , . , . , , . , , ,
( , ). . , , , . 118 II.
http://openlib.org.ua/
3.1. Branch Staff branchNo street city postcodefi
BranchNumbers StreetNames cityNames Postcodes Sex DatesOf
Birth
; 4, 1 ' ' - ' ; 25 ; 15 ; 8 ; 1, 1 1 ' ' F ; l-Jan20, dd-mmm-yy
; 7 , 6000.00-40000.00
sx
DOB
salary
Salaries
Branch
branchNo 005 BOOT 004 002
street 22 Deer Rd 16 Argyll St 163 Main St 32 Manse Rd 56 Clover
Dr
city London Aberdeen Glasgow Bristol London
postcodeSW1 4EH
AB23SU01 1 9QX
S.
BS991NZ NW106EU
=2
Staff
staffNo fName (Name position SL21
sex
DOB
salary branchNo 30000 12000 18000 9000 24000 9000 BOOS 007
SG37SG14 SA9 SG5 SL41
John Ann David Mary Susan Julie
White Beech Ford Howe Brand Lee
Manager Assistant Supervisor Assistant Manager Assistant
F M F F F
1-Oct-45 IO-Nov-60 24-Mar-58 19-Feb-70 3-Jun-40 13-Jun-65
005
. 3.1. Branch Staff
3.
119
http://openlib.org.ua/
. . , , . Branch , . , , , . ( (intension)). , , . (extension),
(state) , . . , , Branch, . 3.1, , , , . , , .. , . 1 (unary) ( ).
(binary), (ternary), - (-). . . , . . . . , . . , . , ,
(normalization). 13.
, , , . (file), (records), (fields). , . . 3.2 , . 1 20 II.
http://openlib.org.ua/
3.2. 1 2
3.2.2. . , , DI D2 , D!= {2,4} D 2 = {1,3,5}. ( D2XD2) , D l t
D2. , Dlf D3. :DpOj = { (2,1) , ( 2 , 3 ) , ( 2 , 5 ) , (4,1) ,
{4,3} , ( 4 , 5 ) }
. , R, .R = { (2,1) , (4,1)}
, , . , , R , 1, R : R = { (,) |xeD 1 ( yeD 2 y=l} , S, . S : S
= { (,) | x e D 1 ( y e D 2 =2} :S = {(2,1)}
. D l t D2 D 3 > D^xD2xD^ , , D lt D 2 , D3. . :D! = { ( 1 ,
3 ) } , D2 = { ( 2 , 4 ) } D a = { ( 5 , 6 ) } DiXD^XDa = {(1,2,5),
(1,2,6), (1,4,5), (1,4,6), (3,2,5), (3,2,6), (3,4,5), (3,4,6)}
3.
121
http://openlib.org.ua/
. , . Db D 2 , ..., Dn. : DiXDzX. . .xD n = { ( d 1 ( d 2 , dj
l^eD^djeDa, . - . ,d n eD n } :
. - . , , , .
3.2.3. , . " . , . , 1( :;, ..., D l t D 2 , ..., Dn { :D l f A,
:D 2 , . . .,A n :D r .}. R, S, . , R n- (A^d^ : 3 2 , . . . ,A n
:d r .}, d 1 eD 1 ,d 2 eD 2 , . . . ,dneDr.. - . , (d 1 ( d 2 , . .
. ,dj , . , , . , . 3.1, Branch branchNo, street, city postcode .
Branch , BranchNurnbers, StreetNames ,, , :{ ( 0 0 5 , 2 2 Deer Rd,
London, SW1 4 E H ) }
: {(branchNo: B005, street: 22 Deer Rd, city: London, postcode:
SW1 4EH)} . Branch , . , . , , . 122 II.
http://openlib.org.ua/
. , . . . R!, R3, ..., Rn , ( ) R :R = Rj. , R 2 , - - . , R
n
3.2.4. . , . () . . . , .. . . . ( .) Branch, . 3.1. , . , . , ,
, , , ( 13.) , , . branchNo BranchNumbers , , . . , (005, 22 Deer
Rd, London, SWl 4EH) . , . , city postcode, . , (, 005 004); . . (,
) . , . 3. 1 23
http://openlib.org.ua/
. . , , . , . . , -. , . , . . , (1, 2) (2, 1). , , . , , . , .
, , .
3.2.5. , . ( ), , . (superkey). , . . . , , , , . . , , ^ . R .
. R . . . . , . Branch, . 3.1. city (, 124V:
II,
http://openlib.org.ua/
). . , DreamHome , ( branchNo) ( Branch), branchNo . , postcode
. Viewing (), . (clientNo), (propertyNo), (viewDate) , , (comment).
(clientNo) . , (propertyNo) , . , (clientNo) (propertyNo) .
clientNo propertyNo . , , (viewDate). , . , , . , -, , . - , . " ";
-. , . , . 3.1 , Staff IName, . , White, White IName . . , . -, . ,
. , , , . , , . Branch branchNo, postcode. viewing , clientNo
propertyNo, . 3. 125
http://openlib.org.ua/
. , "; ( , ) .. , . , branchNo Branch Staff , it . Branch
branchNo , Staff , . Staff branchNo . , branchNo Staff , ..
branchNo, (Branch). ( .) , .
3.2.6. . DreamHome, , : Branch (branchNo, street, cizy,
postcode) S t a f f ( s t a f f N o , fName, IName, position, sex,
DOB, salary, branchNo} PropertyForRent (propertyNo, street, city,
postcode, type, rooms, rent, ownerNo, staf fNo, branchNo) Client
(clientNo, fName, IName, telNo, prefType, maxRent) PrivateOwner
(ownerNo, fName, IName, address, telNo) Viewing (clientNo,
propertyNo, viewDate, comment) Registration (cJlientNo, branchNo, s
t a f f N o , dateJoined)
, ( ) . () . , , . . 3.3-3.9 . 3.3. DreamHome. BranchbranchNo005
007 004 002
street 22 Deer Rd 16 Argyll St 163 Main St 32 Manse Rd 56 Clover
Dr
city London Aberdeen Glasgow Bristol London
postcodeSW1 4EH
AB23SUGil 9QX
BS99 1N2NW10 6EU
1 26
II.
http://openlib.org.ua/
3.4. DreamHome. StaffstaffNoSL21SG37
fName John
[Name White Beech Ford Howe Brand
position Manager Assistant Supervisor Assistant Manager
Assistant
sexM M
DOBl-Oct-45 lO-Nov-60
salary30000 12000 18000
branchNoBOOS
AnnDavid Mary Susan Julie
B003B003 B007 BOOS BOOS
SG14
24-Mar-58 19-Feb-70 3-Jun-40 13-Jun-65
SA9 SG5SL41
1 IF
9000 24000 9000
Lee
.5. DreamHome. PropertyForRent propertyNo
street 16Holhead 6 Argyll St 6 Lawrence St 2 Manor Rd 18 Dale Rd
5 Novar Dr
city Aberdeen London Glasgow Glasgow Glasgow Glasgow
postcodeAB7 5SUNW2
typeHouse',. !
rooms rent owner staff No No
branch NoB007 BOOS BOOS
14PL94
6 i 3 5 4
650 400 350 375 600 450
C046 C087 C040 C093 COS7 C093
SA9
SL41
PG4PG36
Gil 9QXG32 4QX G12G129AX
Flat House Flat
SG37 SG37
BOOS
PG21 PG16
SG14
3.6. DreamHome. ClientclientNoCR76 056 CR74 CR62
fName John Aline Mike Mary
IName
telNo0207-774-5632 0141-848-1825 01475-392178 01224-196720
prefType Flat Flat House Flat
maxRent425 350 750 600
KayStewart Ritchie Tregear
.7. DreamHome. PrivateOwnerownerNo046
fName
IName Keogh Parrel Murphy Shaw
address 2 Fergus Dr, Aberdeen AB2 7SX 6 Achray St, Glasgow G32
9DX 63 Well St, Glasgow G42 12 Park PI, Glasgow G4 OQR
telNo01224-861212 0141-357-7419 0141-943-1728 0141-225-7025
JoeCarol Tina Tony
087040 093
3.
127
http://openlib.org.ua/
3.8. DreamHome. ViewingclientNo CR56 CR76 CR56 CR62 CR56
propertyNo14PG4 PG4
viewDate 24-May-Ol 20-Apr-Ol 26-May-Ol 14~May-01 28-Apr-Ol
comment too small too remote no dining room
14
PG36
.9. DreamHome. RegistrationclientNo CR76 CR56 CR74 CR62 branchNo
005 staffNoSL41
dateJoined 2-Jan-Ol 11-Apr-OO 16-Nov-99 7-Mar-OO
007
SG37 SG37SA9
3.3. . 2.3, : , , , . , . , . , , , , . . , , .
3.3.1. . , / . ( NULL) "". , , . NULL . NULL . , 128 .
http://openlib.org.ua/
NULL - . NULL , . " NULL", NULL , , " NULL" . , . 3.8 Viewing
Comment , . NULL - , , . -1. , Viewing hasCommentBeenS.upplied ( )
Y (Yes), , N (No) . . NULL . - , , , , , .. : . NULL , , [74],
[75], [77]. NULL . [77] NULL , , , , , NULL [87]. .
3.3.2. . , (. 2.1). 3.4. . , , NULL. , , . , . NULL , , , . ,
branchNo Branch, Branch , NULL branchNo. Viewing, (clientNo)
(propertyNo). Viewing , NULL clientNo propertyNo, . 3. 129
http://openlib.org.ua/
, . -, , , ? -, ? , Viewing (. . 3.8), : " ". comment. , , NULL
( PG36 PG4 CR56). , NULL . [76], [92].
3.3.3. . . , ? ! HULL. , branchNo Staff , branchNo Branch. 025 ,
Branch , 025. NULL , . , , - .
3.3.4. . , . , . , 20 , , , s t a f f , 20 . , . 6 16. 130
II.
http://openlib.org.ua/
3.4. 2 ANSI-SPAKC . "" (view) . , (virtual relation), .. , , (,
). , ( ) , , . , , . 6.4 SQL.
3.4.1. , , . I . , ),"; , . . . , -^ .; . , , . f ' , , ' , . -
" . ' , . ''.'-. , " '
, . , ( ). . , . , .. , , , . , . , . 6.4.
3.
131
http://openlib.org.ua/
3.4.2. . , . - , . , . . , (. 4.1), , . , , . . Branch , , .
Branch Staff Manager. s t a f f salary. , , ( branchNo) (Branch
Number), . , . , (. 2.1.5). , . , , , . , , . 6.4.7, .
3.4.3. , . , . , 132 II.
http://openlib.org.ua/
, . , . , . , . , . : , . [119].
Y^-IHIHfHRBH
, 15-20 (50 ), 25%. ; , . . . . . - , . , , , , , . : , , , , -
. , . , , , - . ( ), , . , . . ( ) , . 133
3.
http://openlib.org.ua/
(NULL) , . , . , , NULL. , () . , . . [3.1.
3.2. 3.3. 3.4. 3,5.
3.6. 3.7.
: ) ; ) ; ) ; ) ; ) ; ) . ? . ? . . " "? ? , . , . ? .
,.,. .Hotel
Room (roomNo, hoteINg, type, price) Booking (hotelNo, guestNo,
dateFrom, dateTo, roomNo) Guest (gueatNo, guestName,
guestAddress)
(hotelNQ, hotelName, city)
134
II.
http://openlib.org.ua/
Hotel , hotelNo . Room , (roomNo, hotelNo) . Booking ; (hotelNo,
guestNo, dateFrom). , Guest , guestNo. 3.8. . , , 3.9. , . , . . ,
. , , , . 3.11. , . , , .
3.
135
http://openlib.org.ua/
http://openlib.org.ua/
^ ...
" ". . . . (Data Manipulation Language DML).
. 2.3, ( ), . , . , , [66J . () , , . , , , , , . , , , .. ( ).
, . . , , . . , , . . , , , , .
http://openlib.org.ua/
4.1 , 4.2 : . 4.3 . DreamHome, . 3.3-3.9. 5, 6 21 SQL
(Structured Query Language ) , . 7 QBE (Query-By-Example ), , .
4.1. , . , , . ( , ), . . , , , , . , , , , ,, . . . [404]. , .
[67] , . , (selection), (projection), (cartesian product), (union)
(set difference), , . , (join), (intersection) (division), . . 4.1.
, . , . R S , = { 1( , . . ., ) = (bj, 2 , . . ., ) . 138 II.
http://openlib.org.ua/
ffxfi
a a b b
12 3 1 2 3
) RUS
)
)
RDS
-S
.*; s
)
) 7-
)
) ) ) W
V+W
b b ) ( )
12 1 2 1
. 4.1.
4.1.1. : . 4.
139
http://openlib.org.ua/
( )0^()- R , () R, ().
4.1. , 10000 ." s a l a r v a l Q Q Q O \ t )
s t a f f , salary>!0000. , s t a f f , salary 10000 . . 4.1.
(AND), v (OR) - (NOT). 4.1. Staff salary > 10000staffNoSL21
fName JohnAnn
IName White Beech Ford Brand
position Manager Ass .slant Supervisor Manager
sexF F
DOB
salary 30000 12000 18000 24000
branchNo BOOS B003 BOOS BOOS j
l-Oct-45 10-Nov-60 24-Mar-58 3-Jun-40
SG37SG14SG5
David Susan
1
-.,. .J[R).
; R ! , R, " . -.
4.2, staffNo, fName, INametf salary.
n.t af Ha,fName,IName,salary ( S t a f f ) , s t a f f N o ,
fName, IName salary S t a f f , . . 4.2.
140
II.
http://openlib.org.ua/
4.2. Staff staffMo, fName, IName salarystaffNo
fNameJohn
IName White BeechFord Howe Brand
salary30000 12000 18000 9000 24000 9000
SL21SG37
AnnDavid Mary Susan
SG14SA9 SG5
SL41
Julie
Lee
4.1 .2. . . , , , .
. '' , : ' 'clientHo,propert;yNo, comment
. 4.7. , . 4.6. Client Viewing ( ) Client. clientNoCR76 CR76
CR76 CR76 CR76 CR56 CR56 CR56 CR56 CR56 CR74 CR74 CR74 CR74 CR74
CR62 CR62 CR62 CR62 CR62 John John John John John Aline Aline Aline
Aline Aline Mike Mike Mike Mike Mike Mary Mary Mary Mary Mary
fName
IName
Viewing .client No CR56 CR76 CR56 CR62 CR56 CR56 CR76 CR56 CR62
CR56 CR56 CR76 CR56 CR62 CR56 CR56 CR76 CR56 CR62 CR56
propertyNoPA14PG4 PG4
commentToo small ( ) Too remote ( ) No Dining room ( ) Too small
( ) Too remote ( ) No Dining room ( ) Too small ( ) Too remote ( )
No Dining room ( ) Too small ( ) Too remote ( ) No Dining room (
)
KayKay
KayKay Kay
PA14
PG36PA14PG4
Stewart Stewart Stewart Stewart Stewart Ritchie Ritchie Ritchie
Ritchie Ritchie Tregear Tregear Tregear Tregear Tregear
PG4
PA14
PG36PA14PG4 PG4
PA14
PG36PA14PG4 PG4
PA14
PG36
144
II.
http://openlib.org.ua/
4.7. Client Viewing ( ) Client. clientNoCR76 CR56 CR56 CR56
CR62
fNameJohn Aline Aline Aline Mary
I NameKayStewart Stewart Stewart Tregear
Viewing .clientNoCR76 CR56 CR56 CR56 CR62
propertyNoPG4
comment Too remote ( ] Too small ( )
PA14PG4
PG36
PA14
No dining room ( )
. . , ( 10000}
, , . (3), "", , , :S t a f f (S) {} (Branch(B) .city='London')
(.branchNo=S.branchNo)
, Branch , branchNo, branchNo S S t a f f , city ' London'. (V),
" ", , , :(VB) (.city * 'Paris')
, Branch city ' P a r i s ' . :() ( F ( X ) ) ^ ~ ( V X ) ( ~ (
F ( X ) > > tVX) ( F < X > ) = ~ = F2{X)) = ~(VX) ( - (
F i t X ) ) = -OX) ( - ( F i t X ) ) v ~{F2(X)>) v~{F2(X)J)
: ~()(.city ='Paris') , . , V 3; . , 4. 153
http://openlib.org.ua/
, (|). , S S S t a f f . {S.fName, S.IName | Staff (S) ()
S.branchNo) .city = ' L o n d o n 1 ) } (Branch(B) (B.branchNc
=
, , . . :{Si.aj, S 3 .a 2 , ..., S n .a n ( F(SL, S2 , SJ } ;
ra>n
S 17 S2,..., S n ,. . ., Sm , a^ , Si, a F ( ) , . R ( S i ) ,
Sj , a R . Si.! 9 Sj.a 2 , Si Sj , ! , S i T 2 , Sj, 6 (, >, =,
*); ^ , 9 . S i - a j 9 , 3 , , Sit ! 6 . . . F! F2 , , (Fi/\F2),
(FjVFjj) (-Fi), . F X, () (F) (VX) (; .
4.12. . , 25000 .
(S.fName,S.IName|Staff(S)5.position='Manager'.salary>25000} . ,
. {S S t a f f ( ) ( ) ( P r o p e r t y F o r R e n t ( ) ( P . s
t a f f N o = S . s t a f } P.city='Glasgow1)} 154 II.
http://openlib.org.ua/
staf fNo PropertyForRent , . : " , , PropertyForRent , , city
'Glasgow'". , , . : " PropertyForRent, city 'Glasgow', Staff". , ,
., , . {5.fName,S.IName|Staff(S) (~ ()(PropertyForRent(P)
(S.staffNo=P.staffNo)))}
, :{S.fName,S.IName|Staff(S){(Vp)(-PropertyForRent(P)v
~(S.stafNo=P.staffNo)))}, , .
(C.fNarae,C.lName|Client()((3V)()(Viewing(V) PropertyForRent(P}
(C.clientNo=V.clientNo) (V.propertyNo=P.propertyNo) P . c i t y = '
G l a s g o w ' } ) }
, ", 'Glasgow'", ", Viewing ' Glasgow' "., , , .
{.city|Branch(){-()(PropertyForRent(P).city=P.city))}
, 4.4.. , , .
{.city]Branch()(()(PropertyForRent(P).city=P.city))} , 4.5.. , ,
.
4.3 . , , , 4. 155
http://openlib.org.ua/
. , , Branch, PrcpertyForRent ( ). , , , . , , .
, , . , , , S t a f f :{S|-Staff(S)}
. , , , , ; dora(E). , , . , , S t a f f . , , , . , , Staff (..
, ). , , . , , RANGE. [93]." 4.2.2.
, . , , , . : {di, d2 d, I F t d i , d2 dj); m > n
dj, d2,..., dn,..., dm (), a F{d 1 ( d2, . .., dj . , . 156
II.
http://openlib.org.ua/
R (d l 7 d 2 , . . . , d n ) , R di . di dj, di dj 9 (, =, ?*);
di dj , 0 . di 9 , d t , di 9 . . . F2 , , (] ), (F^yF;,) (~Fj), .
F^ X, () (F) (Vx) ( F ) .
4.13. : (3d1( d2 d n ) (3d,) , (3d 2 ) , (3dJ
. , 25000 .{ f N , IN J (3sN, posn, sex, DOB, sal, b N ) ( S t a
f f ( s N , f N , IN, posn, sex, DOB, sal, bN} posn = 'Manager' sal
> 2 5 0 0 0 ) }
, 4.12, , , (). Staff (sN, fN, . . ., bN} , . posn = 'Manager'
Staff .position = 'Manager'. . posn s t a f f Staff {posn). , posn
, , Staff (sN, fN, IN, posn, sex, DOB, sal, bN), position, s t a f
f . , ( posn sal). , , .{sN, f N , IN, posn, sex, DOB, sal, bN |
{3sNl, cty)
( S t a f f { s N , f N , IN, posn, sex, DOB, sal, bN)
PropertyForRent(pN, st, cty, pc, typ, rras, rnt, oN, sNl, bNl} ( s
N = sNl) cty = ' G l a s g o w ' ) } 4. 157
http://openlib.org.ua/
:{sN, f N , IN, posn, sex, DOB, sal, bN | ( S t a f f ( s N , f
N , IN, posn, sex, DOB, sal, bN} 1 PropertyForRent (pN, st,
'Glasgow , pc, typ, rms, rnt, oN, sN, b N l ) ) }
cty PropertyForRent 'Glasgow', sN, , Staff, PropertyForRent.. ,
- . {fN, IN | (3sN) { S t a f f { s N , f N , IN, posn, sex, DOB,
sal, bN} (~ (BsNl) (PropertyForRent(pN, st, cty, pc, typ, rms, rnt,
oN, sNl, bNl) (sN = s N l ) ) ) ) } . , .. { f N , IN | (3cN, cNl,
pN, pNl, Cty}
(Client(cN, fN, IN, tel, pT, mR) Viewing(cNl, pNl, dt, crat}
PropertyForRent(pN, st, cty, pc, typ, rms, rnt, oN, sN, bN) [cN =
cNl} {pN =. pNl) cty'= 'Glasgow')} . , , . {cty | (Branch(bN, st,
cty, pc) ( ~ ( B c t y l J (PropertyForRent(pN, stl, ctyl, p e l ,
typ, rms, rnt, oN, sN, bNl) (cty = c t y l } ) ) } E , , . {cty |
(Branch(bN, st, cty, pc) (3ctyl) (PropertyForRent(pN, st1, ctyl,
pel, typ, rms, rnt, oN, sN, bNl) (cty = c t y l ) ) } . , , . {cty
| {Branch(bN, st, cty, pc) v PropertyForRent(pN, stl, cty, pel,
typ, rms, rnt, oN, sN, b N ) ) }
, , , , , , , . , , . 1 58 II.
http://openlib.org.ua/
4.3. , , . : . , . . SQUARE [37], SEQUEL [53] , SQL. SQL 5, 6
21. . , . QBE (Query-By-Example) [331]. 7. (Fourth-Generation
Language 4GL), , (. 2.2 ). , .. , (Fifth-Generation Language 5GL).
.
, , . , , . , .. ( ). . , , , . , , , , , , . , , : , , , . , ,
, . 4. 159
http://openlib.org.ua/
, . : . , . , , , , . , . ( ). , , , .
4.1. 4.2.
4.3. 4.4.
4.5. 4.6. 4.7.
? ? : ) ; ) . . , . , (-, , , ). , . , . . ( ) . , . . , .
Hotel, 3. 4.8. , : ) 1{1 (Room) )) O H otel.hotelNo -
Room.hotelNo ( I ! o t e l X
Room)5 0 (RoOTTl)
) llhotelName (Hotel
) )
160
I E .
http://openlib.org.ua/
) Guest => -i-jmn-aooi- (Booking) )
> H otel.hotelNo - Room.hotelNo (O"price > 50 (Room) )
^Booking .guestNo Guest .guestNo GUSt) -S-
1'guestName, hoCelNo (BOOKing
flhotelNo (Ocity > 'London' (Hotel) )
4.9.
, 4.8. 4.10. , :) {H.hotelName | H o t e l ( H ) A H . c i t y =
' L o n d o n } ) {H.hotelNarae | H o t e l ( ) (3R) R.hotelNo R .
p r i c e > 5 0 ) } (Room(R) H.hotelNo =1
) {H.hotelName J Hotel (H) () (3G) (Booking(B) G u e s t ( G )
H.hotelNo = B.hotelNo B.guestNo = G.guestNo 1 G.guestNarae = 'John
S m i t h ) } r) {H.hotelName, G.guestName, Bl.dateFrom,
B2.dateFrom | Hotel(H) Guest(G) Booking(Bl) Booking(B2) H.hotelNo =
Bl.hotelNo G.guestNo - Bl.guestNo B2.hotelNo = Bl.hotelNo
B2.guestNo = Bl.guestNo 2. dateFrom Bl. dateFrom}
4.11. , 4.10. 4.12. , , ) . 6} 20 . ) , . ) Grosvenor . ) ,
Grosvenor. ) Grosvenor , , , . ) Grosvenor ( guestNo, guestName
guest Address). 4. , Grosvenor, . ? 4.14. , . ? , , 4.1. 4. 161
http://openlib.org.ua/
http://openlib.org.ua/
SQL: ...
Structure Query Language (SQL) . SQL. SQL. SELECT. SQL, : WHERE
, ; ORDER BY;
SQL; GROUP BY; ; ; (UNION, INTERSECT, EXCEPT).
INSERT, UPDATE DELETE. 3 4 . , , Structured Query Language
(SQL), . SQL (ANSI) 1986 , 1987 (ISO) [170]. SQL , , . , SQL , , ,
, , -
http://openlib.org.ua/
, . SQL, ISO. - . , SQL .
5.1 SQL , . 5.2 , SQL. 5.3 SQL, , . 6 SQL, , , . 21 SQL : , SQL
. 27.4 , SQL - ( SQL3). SQL . ( ), 4. SQL. SQL , 4. . 3.33.9
DreamHome.
5.1. SQL SQL, , .
5.1.1. SQL : ; , , ; . , , . , , , .. , 164 II.
http://openlib.org.ua/
. SQL . SQL , , . SQL, ISO, : DDL (Data Definition Language), ;
DML (Data Manipulation Language), . SQL3 SQL ; - . , IF ... THEN
... ELSE, GO TO, DO ... WHILE , . ( ) ( , ). ( ) SQL . , SQL. SQL ,
21. SQL3, 1999 , 27. SQL . , , , . , SQL , , SQL . , . , , CREATE
TABLE ( ), INSERT (), SELECT (). : CREATE TABLE S t a f f ( s t a f
f N o VARCHAR(S), salary D E C I M A L ( 7 , 2 ) ) ; INSERT INTO
Staff VALUES ('SG16', IName V A R C H A R ( 1 5 ) ,
'Brown', 8300);
SELECT staffNo, IName, salary FROM StaffWHERE salary >
10000;
SQL , (), , . SQL [173], [176], , .
5. SQL:
165
http://openlib.org.ua/
5.1.2. SQL 3, ( SQL) 1970 . . ( IBM -). 1974 . , , , "Structured
English Query Language", SEQUEL. 1976 , SEQUEL/2; SQL SEQUEL - . -
SQL "", "--". 1976 SEQUEL/2 IBM , "System R" [9]. . , SQL, SQUARE
(Specifying Queries as Rational Expressions), System R. SQUARE ,
[37]. 1970- , , Oracle, Oracle. , , SQL. INGRES, QUEL. , SQL, . ,
SQL , INGRES . 1981 IBM SQL/DS ( DOS/VSE). 1982 VM/CMS, 1983 MVS,
DB2. 1982 (ANSI) RDL (Relation Database Language), , IBM. 1983
(ISO). SQL. ( RDL 1984 , SQL.) , ISO 1987 , . , , , , , . , [89],
[90], [92]. , . , ( , , ), , , . 1989 ISO , [171]. 1992 166 II.
http://openlib.org.ua/
, ISO, SQL2 ( SQL-92) [173]. , SQL. , SQL3 [176], 1999 . - ,
27.4. , , . , SQL , . . . , , ISO. , , SQL, . SQL . SQL IBM, . ,
SQL, ,
5.1.3. SQL SQL , . , NDL (Network Database Language), CODASYL, .
SQL SQL, , , , . SQL , . (, System Application Architecture (SAA)
IBM), (, /Open, UNIX), SQL (Federal Information Processing Standard
FIPS), . SQL Access Group SQL, . SQL . ISO "Information Resource
Dictionary System" (IRDS) (. 2.7.1) "Remote Data Access" (RDA). , ,
5. SQL: 167
http://openlib.org.ua/
. , . SQL, , OnLine Analytical Processing (OLAP).
5.1.4. ISO SQL , , , , . SQL ISO. , , SQL , 3. , SQL , SELECT ,
, .
5.2. SQL SQL , SQL. SQL , , . SQL . , , . , , ( ) , , , .. . ,
SQL , ; , (;). SQL . , , . , , , . , ' S M I T H 1 , ' Smith 1 , .
SQL , SQL . . . , . -:: , , . SQL BNF (Backus Naur Form -). 168
.
http://openlib.org.ua/
, . , . ( ) , a b | . , {}. , []. ( . . . ) , { } [ , . . . ] .
, , . ( ) DDL, DML. DML DDL. DML . DDL .
5.3. SQL DML: SELECT ; INSERT ; UPDATE ; DELETE . SELECT DML,
SELECT . , , , , . INSERT, UPDATE DELETE SQL. SQL DreamHome, .
3-33.9. DreamHome : Branch Staff (branchNo, street, city, postcode)
(sjiajE f No, fName, IName, position, sex, DOB, salary, branchNo)
PropertyForRent (propertyNo, street, city, postcode, type, rooms,
rent, ownerNo, s t a f f N o , branchNo} Client (clientNo, fName,
IName, telNo, prefType, maxRent) PrivateOwner (ownerNo, fName,
IName, address, telNo) Viewing (clientNo, propertyNo, viewDate,
comment)
5. SQL:
169
http://openlib.org.ua/
DML, , , "". , SQL. , SQL ( 6.1.1). , , , . , . . INSERT INTO
PropertyForRent(propertyNo, street, city, postcode,type, rooms,
rent, ownerNo, staffNo, ranchNo) 1 1 1 1 V A L U E S ( ' P A 1 4 '
, 46 Holhead , 'Aberdeen , 'AB7 5SU , 'House , 6 , 1 1 650.00,
'C046 , 'SA9 , ' B 0 0 7 ' ) ; rooms , rent . . .
5.3.1. SELECT . , , , (. 4.1), . SELECT SQL. SELECT :^SELECT
[DISTINCT; [ ALL] .{ * I [columnExpression IAS newName]]
[,'...'}'}
"FROM TaJbleWame '{alias] [ , . . - ] . [WHERE condition]., ,v
[GROUP BY columnwise] [HAVING condition] : ; QRDER'BY columnList] '
columnExpression . TableName ( ), . a l i a s , TableName. SELECT .
FROM. . WHERE. . GROUP BY. , .
170
.
http://openlib.org.ua/
HAVING. . SELECT. , . ORDER BY. . SELECT . SELECT FROM , .
SELECT , , (. 4.1). , .
5.1. . , WHERE. , . : SELECT staffNo, fName, IName, position,
sex, DOB, salary, branchNo FROM S t a f f ; , SQL " " - (*).
:SELECT * FROM Staff;
. 5.1. 5.1. 5.1staffNoSL21
.
fName JohnAnn
IName White Beech Ford Howe BrandLee
position Manager Assistant Supervisor Assistant Manager
Assistant
sexM F MF F
DOB
salary 30000.00 12000.00 18000.00 9000.00 24000.00 9000.00
branchNo BOOS BOOS BOOS B007 BOOS BOOS
l-Oct-45 lO-Nov-60 24-Mar-58 19-Feb-70 3-Jun-40 13-Jun-65
SG37SG14SA9SG5
David Mary Susan Julie
SL41
F
1171
5. SQL:
http://openlib.org.ua/
5.2. ( staffNo), , .
SELECT staffNo, fName, IName, salary FROM S t a f f ; Staff ,
staffNo, fName, IName salary, . . 5.2. , . , (, Microsoft Access
staffNo). . 5.2. 5.2staffNoSL21
fName JohnAnn
IName White Beech Ford Howe BrandLee
salary 30000.00 12000.00 18000.00 9000.00 24000.00 9000.00
SG37SG14SA9 SG5
David Mary Susan Julie
SL41
5.. DISTINCT , . SELECT propertyNo FROM Viewing;
. 5.3. , , , (. 4.1.1), SELECT . DISTINCT. :SELECT DISTINCT
propertyNo FROM Viewing;
. 5,4.
172
II.
http://openlib.org.ua/
5.3. 5.3
5.4. 5.3 propertyNo14
PG4
PG36
5.4. , , . SELECT s t a f f N o , fName, IName, salary/12 FROM S
t a f f ; 5.2, , , . 12. . 5.5. 5.5. 5.4 staffNoSL21
fName JohnAnn
IName White Beech Ford Howe BrandLee
co!42500.00 1000.00 1500.00750.00
SG37SG14SA9 SG5
David Mary Susan Julie
2000.00750.00
SL41
( , ). SELECT SQL. 5. SQL: 173
http://openlib.org.ua/
, , . . , , , . , , !4. . , SQL . SQL (, !4), , SELECT. ISO ,
AS. SELECT :SELECT staffNo, FROM S t a f f ; fName, INarae,
salary/12 AS month!ySalary
monthlySalary, col4.
( WHERE) SELECT . , . WHERE. WHERE, , , . ( , ISO). . . . , . .
, . . , . NULL. , NULL ( ). WHERE , 4.1.1. .
174
II.
http://openlib.org.ua/
5.5. 10 000 . SELECT s t a f f N o , fName, IName, position,
salary FROM Staff WHERE salary > 10000; Staff salary > 10000.
, Staff, salary 10 000 . . 5.6. 5.6. 5.5 staffNoSL21
fName JohnAnn
IName White Beech Ford Brand
position Manager Assistant Supervisor Manager
salary30000.00
SG37SG14SG5
12000.0018000.00 24000.00
David Susan
SQL , . 5.7. 5.7. ( ISO) ( )
!=
AND, OR NOT, , ( ). . . . NOT AND OR. AND OR. . 5. SQL: 175
http://openlib.org.ua/
5.6. . SELECT * FROM Branch 1 1 WHERE city = 'London OR city = '
G l a s g o w ;
, (city = 'London') (city = 'Glasgow'), WHERE OR. . 5.8. 5.8.
5.6branchNo 005
street22 Deer Rd 163 Main St 56 Clover Dr
city London Glasgow London
postcodeSW1 4EH Gil 9QX
002
NW106EU1
5.7. (BETWEEN/NOT BETWEEN) 20 000 30 000 ,
SELECT staffNo, fName, IName, position, salaryFROM Staff WHERE
salary BETWEEN 2 0 0 0 0 AND 3 0 0 0 0 ;
BETWEEN . 20 000 30 000 . . 5,9. 5.9. 5.7staffNoSL21SG5
fName John Susan
IName White Brand
position Manager Manager
salary30000.00 24000.00
, (NOT BETWEEN), , . BETWEEN SQL, . : SELECT staffNo, fName,
IName, position, salary FROM S t a f fWHERE salary >= 20000 AND
salary 350; , 350 , WHERE. , , COUNT. . 5.16. 5.16. 5.13 count
5.14. COUNT(DISTINCT), 2001 . SELECT COUNT(DISTINCT propertyNo)
AS count FROM Viewing WHERE date BETWEEN ' l - M a y - 0 1 1 AND '
3 1 - M a y - O l 1 ; , 2001 , WHERE. , , COUNT. , , DISTINCT . .
5.17. 5.17. 5.14 count
5.15. COUNT SUM . SELECT COUNT(staffNo) AS count, SUM(salary) AS
sum FROM Staff WHERE position = 'Manager'; 5. SQL: 183
http://openlib.org.ua/
WHERE. COUNT SUM. . 5.18. 5.18. 5.15 count2
sum54000.00
5.16. MIN, MAXnAVG , .
SELECT MIN(salary) AS min, MAX(salary) AS max, AVG(salary) AS
avg FROM S t a f f ; , WHERE . MIN, MAX AVG, salary Staff. . 5.19.
5.19. 5.16
min90.0 000
max3000 00.0
avg1000 70.0
5.3.4. ( GROUP BY) , . . . SELECT GROUP BY. , GROUP BY, , ,
SELECT, . , GROUP BY, . ISO , SELECT GROUP BY . SELECT GROUP BY
SELECT . , SELECT : ; ; ; , . 184 II.
http://openlib.org.ua/
, SELECT, GROUP BY, , . GROUP BY , SELECT. GROUP BY WHERE, , , .
ISO , . NULL , .
5.17. GROUP BY , , . SELECT branchNo, COUNT{staffNo} AS count,
SUM(salary) AS sum FROM Staff GROUP BY branchNo ORDER BY branchNo;
s t a f f N o salary GROUP BY, SELECT . branchNo SELECT - GROUP BY.
. 5.20. 5.20. 5.17 branchNo 8003 005 007 count3 2 1
.
sum54000.00 39000.00 9000.00
. 1. Staff . . , . 5.1. 2. , , salary, . . 3. , branchNo.
5. SQL:
185
http://openlib.org.ua/
' branchNo
staffNo SG37SG14 SG5 SL21 SL41SA9
salary 12000.00 18000.00 24000.00 30000.00 9000.00 9000.00
COUNT(staffNo)
SUM(salary) 54000.00 39000.00 9000.00
005 005 007
3 2 1
. 5.1. , SQL SELECT ( 5.3.5). :SELECT branchNo, (SELECT C O U N
T { s t a f f N o ) AS count FROM S t a f f s
WHERE s.branchNo = b.branchNo), (SELECT SUM(salary) AS sum FROM
Staff sWHERE s.branchNo = b.branchNo) FROM Branch b ORDER BY
branchNo;
, Branch, , , .
( HAVING) HAVING GROUP BY , , . HAVING WHERE , . WHERE , ,
HAVING , . ISO , , HAVING, GROUP BY . HAVING , , ; WHERE . (,
WHERE.) HAVING SQL - , HAVING, , .
186
II,
http://openlib.org.ua/
5.18. HAVING . SELECT branchNo, COUNT(staffNo) AS count,
SUM(salary) AS sum FROM Staff GROUP BY branchNo HAVING
COUNT(staffNo) > 1 ORDER BY branchNo; , , , , . , HAVING. .
5.21. 5.21. 5.18 branchNo 005
count3 2
sum5000 40.0 3000 90.0
5.3.5. SELECT, SELECT. () SELECT () . WHERE HAVING SELECT , . ,
SELECT INSERT, UPDATE DELETE (. 5.3.10). . , , .. . , . 5.13 5.14.
, . , , . 5.15 , . , , IN.
5. SQL:
187
http://openlib.org.ua/
5.19. , , 1 463 Main St . SELECT staffNo, fName, IName, position
FROM Staff WHERE branchNo = (SELECT branchNo FROM Branch WHERE
street = '163 Main S t ' } ; SELECT (SELECT branchNo FROM Branch
...) , '163 Main S t ' . ( , .) , . , SELECT , ' B O O V . , 1 '163
Main St . SELECT : SELECT staffNo, fName, IName, position FROM
Staff WHERE branchNo = 'B0031; . 5.22. 5.22. 5.19 staffNo
SG37SG14SG5
fNameAnn
IName Beech Ford Brand
position Assistant Supervisor Manager
David Susan
, . , (.. =, , =, ) WHERE HAVING. .
5.20. , , , . SELECT staffNo, fName, IName, position, salary -
(SELECT AVG(salary) FROM S t a f f ) AS salDiff FROM Staff WHERE
salary > (SELECT AVG(salary) FROM S t a f f ) ; , 'WHERE salary
> AVG (salary) ', 188 II.
http://openlib.org.ua/
WHERE . , , SELECT, , . , , 17 000 . SELECT , . SELECT :SELECT
staffNo, fName, IName, position, salary - 17000 As salDiff FROM S t
a f f WHERE salary > 17000;
. 5.23 5.23. 5.20staffNoSL21 SG14SG5
fName John David Susan
IName White Ford Brand
position Manager Supervisor Manager
salDiff 13000.00 1000.00 7000.00 ,
. 1. ORDER BY, SELECT. 2. SELECT , , EXISTS (. 5.3.8). 3. , FROM
. , FROM , ( ). 4. , , . , , salary.SELECT s t a f f N o , fName,
IName, position, salary FROM S t a f f WHERE (SELECT AVG(salary)
FROM Staff) < salary;
5.21. IN , , '163 Main st1. SELECT propertyNo, street, city,
postcode, type, rooms, rent FROM PropertyForRent
5. SQL:
189
http://openlib.org.ua/
WHERE
staffNo
IN
(SELECT s t a f f N o FROM S t a f f
WHERE brancliNo = (SELECT branchNo FROM Branch WHERE street =
'163 Main S t ' ) ) ; , , , 463 Main S t ' . , , , . =. IN. , , . .
5.24. 5.24. 5.21 propertyNoPG16 PG36 PG21
street5 Novar Dr 2 Manor Rd
cityGlasgow Glasgow Glasgow
postcodeG129AX G324QXG12
typeFlat
rooms4 3 5
rent450 375 600
Flat
18 Dale Rd
House
s
5.3.6. ANY ALL ANY ALL , . ALL, , . ANY, , - ( ) . , ALL , ANY .
ISO SOME, ANY.
5.22. ANY SOME , ' '.
WHERE salary > SOME(SELECT salary FROM Staff WHERE branchNo =
'B003');
SELECT staffNo, fName, IName, position, salary FROM Staff
, ' 1 , , (. 5.20), , 190 II.
http://openlib.org.ua/
SOME/ANY. {12000, 18000, 24000}, , ( 12 000). , . , . 5.25.
5.25. 5.22 staffNoSL21 SG14SG5
fName John David Susan
(Name White Ford Brand
position Manager Supervisor Manager
salary 30000.0018000.00 24000.00
5.23. ALL , ' '. SELECT staffNo, fName, INarae, position, salary
FROM S t a f f WHERE salary > ALL{SELECT salary FROM Staff WHERE
branchNo = 'BOG3');
.
. , ' ' , , . ALL. . 5.26. 5.26. 5.23 staffNoSL21
fNameJohn
IName White
position Manager
salary 30000,00 ,1
5.3.7. : . . , . SQL , . .
5. SQL
191
http://openlib.org.ua/
, , . ' , . FROM , , WHERE , . , , FROM. . , , . , . , , .
5.24. , . SELECT c.clientNo, fName, IName, propertyNo, comment
FROM Client c, Viewing v WHERE c.clientNo = v.clientNo; Client,
Viewing, . SELECT , . , (clientNo) , , . , . ( clientNo Viewing.) {
). ' ' , Client. , clientNo. .clientNo=v.clientNo. . , 4.1.3. .
5.27. 5.27. 5.24 clientNoCR56 CR56 CR56 CR62 CR76fName Aline Aline
Aline
IName Stewart Stewart Stewart Tregear Kay
propertyNoPG36 PA14PG4
comment too small no dining room too remote
Mary John
PA14PG4
192
II.
http://openlib.org.ua/
, " " (1:*), - (. 11.6.2). , Client Viewing, . Viewing () Client
(), Client () Viewing (). , , . 3.2.5 , "-" . , , , , , . - SQL , .
5.24 Client (. clientNo) Viewing (v. clientNo). SQL : FROM Client
JOIN Viewing v ON .clientNo = v.clientNo FROM Client JOIN Viewing
USING clientNo FROM Client NATURAL JOIN Viewing FROM FROM WHERE.
clientNo, clientNo.
5.25. , - , , . SELECT s.branchNo, s . s t a f f N o , fName,
IName, propertyNo FROM Staff s, PropertyForRent p WHERE s . s t a f
f N o = p . s t a f f N o ORDER BY s.branchNo, s.staffNo,
propertyNo;
, , . . 5.28. 5.28. 5.25branchNo StaffNoSG14
fName DavidAnn Ann
IName Ford Beech BeechLee
propertyNo PGi6
BOOS 007
SG37 SG37SL41SA9
PG21PG36 PL94PA14
Julie Mary
Howe
5. SQL:
193
http://openlib.org.ua/
5.26. , - , , , , . SELECT b.branchNo, b.city, s.staffNo, fName,
IName, propertyNo FROM Branch b, S t a f f s, PropertyForRent p
WHERE b.branchNo = s.branchNo AND s . s t a f f N o = p . s t a f f
N o ORDER BY b.branchNo, s . s t a f f N o , propertyNo;
Branch, Staff PropertyForRent, . Branch Staff b.branchNo=*s
.branchNo, . Staff PropertyForRent s. staff No=p. staff No. , . .
5.29. 5.29. 5.26branchNo city Glasgow Glasgow Glasgow London
Aberdeen staff MoSG14
fName DavidAnn Ann
IName Ford Beech Beech
propertyNoPG16PG21
005007
SG37 SG37SL41SA9
PG36 PL94PA14
Julie Mary
LeeHowe
, SQL FROM WHERE:FROM (Branch b JOIN S t a f f s USING branchNo)
AS bs JOIN PropertyForRent p USING s t a f f N o
5.27. , , SELECT s.branchNo, S.staffNo, COUNT(*) AS count FROM S
t a f f s, PropertyForRent p WHERE S . s t a f f N o = p . s t a f
f N o GROUP BY s.branchNo, s . s t a f f N o ORDER BY s.branchNo, s
. s t a f f N o ;
, , . Staff PropertyForRent 194 II.
http://openlib.org.ua/
staffNo FROM/WHERE. , , GROUP BY. , ORDER BY. . 5,30. 5.30. 5.27
branchNo 8005
staffNoSG14 SG37 SL41
count1 2 1
007
SA9
1
, (. 4.1.2). , , . , . WHERE, SQL . , ISO SELECT, :-."SELECT
[DISTINCT. | ALL] {* j columnList] FROM tableNamel CROSS JOIN 2
5.24, client Viewing clientNo, , . 3.6 3.8, 20 (4 Client x 5
viewing = 20 ). 5.24 , WHERE. , SELECT, . 1. , FROM. 2. WHERE, , .
. 3. , SELECT, . 4. SELECT DISTINCT, -. 5. SQL: 195
http://openlib.org.ua/
, 3 4 , , SELECT. 5. ORDER BY, .
, . , . . ISO , (. 4.1.3). , . , Branch PropertyForRent, . 5.31
5.32. 5.31. Branch"! branchNo 004 002 bCity Glasgow Bristol
London
5.32. PropertyForRentlpCityAberdeen London Glasgow
() SQL:SELECT b . * , p . * FROM Branchl b, PropertyForRentl p
WHERE b . b C i t y = p . p C i t y ;
. 5.33. 5.33. Branchl PropertyForRentl branchNo 002
bCity Glasgow London
propertyNoPG4PL94
pC'rty Glasgow London
196
II.
http://openlib.org.ua/
, , , . , , . , . : , . .
5.28. , , , .
, :SELECT . * , . * FROM Branchl b LEFT JOIN PropertyForRentl p
ON b . b C i t y = p.pCity;
. 5.34. , , (), (). NULL. 5.34. 5.28branch No bCity Glasgow
Bristol London propertyNoPG4NULL
pClty Glasgow NULL London
004 002
PL94
5.29. , , , .
, :SELECT b . * , p . * FROM Branchl b RIGHT JOIN
PropertyForRentl p ON b.bCity = p.pCity;
. 5.35. , , () , () . NULL. 5. SQL: 197
http://openlib.org.ua/
5.35. 5.29 branchNo NULL B003 B002 bCity NULL Glasgow London
propertyNoPA14PG4
pCity Aberdeen Glasgow London
PL94
5.30. } , , , .
, :SELECT . * ( . * FROM Branchl b FULL JOIN PropertyForRent p
ON b.bCity = p.pCity;
. 5.36. , , , . , , NULL. 5.36. 5.30branchNo NULL
bCityNULL Glasgow Bristol London
propertyNoPA14PG4
pClty Aberdeen Glasgow NULL London
004 002
NULL PL94
5.3.8. EXISTS NOT EXIST EXISTS NOT EXISTS . TRUE FALSE. EXISTS
TRUE , . , EXISTS FALSE. NOT EXISTS , EXISTS. EXISTS NOT EXISTS , .
, :(SELECT * FROM . . . )
198
II.
http://openlib.org.ua/
5.31. EXISTS , . SELECT staffNo, fName, IName, position FROM
Staff WHERE EXISTS(SELECT * FROM Branch b WHERE s.branchNo =
b.branchNo AND city = 'London'); : " , Branch , branchNo, , City
'London'". . , EXISTS TRUE. . 5.37. 5.37. 5.31 staffSL21 SL41
No
fNameJohn Julie
INameWhite Lee
positionManager Assistant
, , s.branchNo=b.branchNo, , . , , SELECT * FROM Branch WHERE
city='London' TRUE. : SELECT s t a f f N o , fName, IName, position
FROM Staff WHERE true; : SELECT staffNo, fName, IName, position
FROM S t a f f ; , , : SELECT s t a f f N o , fName, IName,
position FROM S t a f f s, Branch b WHERE s.branchNo = b.branchNo
AND city = 'London 1 ;
5.3.9. ( UNION, INTERSECT EXCEPT) SQL (union), (intersection)
(difference), . 5. SQL: 199
http://openlib.org.ua/
, , (), () , , , , . , , , . . 5.2. , , . , , .. . , , . , , . ,
, , SMALLINT.Bns
-s
)
)
)
. 5.2. (, ) , ISO, UNION, INTERSECT EXCEPT. : opera tor .[ALL]
{CORRESPONDING [BY {columnl [, ...]}
CORRES POND ING BY . CORRESPONDING, 3Y , , . ALL, . SQL
INTERSECT EXCEPT, a EXCEPT MINUS.
200
II.
http://openlib.org.ua/
5.32. UNION , , . (SELECT city FROM Branch WHERE city IS NOT
NULL) UNION {SELECT * FROM Branch WHERE city IS NOT NULL) UNION
CORRESPONDING BY city
(SELECT city FROM PropertyForRent
(SELECT * FROM PropertyForRent
WHERE city IS NOT NULL);
WHERE c i t y IS NOT NULL);
, , . . 5.38. 5.38. 5.32 cityLondon Glasgow Aberdeen Bristol
5.33. INTERSECT , , . (SELECT city FROM Branch) INTERSECT
(SELECT c i t y FROM PropertyForRent); (SELECT * FROM Branch)
INTERSECT CORRESPONDING BY city (SELECT * FROM
PropertyForRent};
, , . . 5.39. 5.39. 5.33 cityAberdeen Glasgow London
5. SQL:
201
http://openlib.org.ua/
INTERSECT: SELECT b . c i t y FROM Branch b, PropertyForRent
pWHERE b . c i t y = p . c i t y ;
SELECT DISTINCT city FROM Branch bWHERE EXISTS(SELECT *
FROM PropertyForRent p WHERE p . c i t y = b . c i t y ) ;
SQL , .
I 5.34. EXCEPT , , , (SELECT city (SELECT * FROM Branch) FROM
Branch) EXCEPT EXCEPT CORRESPONDING BY city (SELECT city (SELECT *
FROM PropertyForRent); FROM PropertyForRent); , , , . . 5.40. 5.40.
5.34 city Bristol -
EXCEPT: SELECT DISTINCT city FROM Branch WHERE city NOT IN
(SELECT city FROM PropertyForRent); SELECT DISTINCT city FROM
Branch b WHERE NOT EXISTS (SELECT * FROM PropertyForRent p WHERE
p.city = b.city);
5.3.10. SQL , , . , SELECT. SQL, . INSERT , UPDATE , . DELETE .
202 II.
http://openlib.org.ua/
( INSERT) INSERT. . INSERT : # INSERT . INTO TableName ^VALUES
TableName ( ) , ( 6.4). colunmList ( ) , , . coIumnLisC . , , ,
CREATE TABLE. INSERT , NULL , DEFAULT ( 6.3.2). dataValueList ( )
columnList: ; , da ta Val uebist columnList, dataValuel/ist
columnList ..; dataValueList . 5.35. INSERT... VALUES staff , .
INSERT INTO Staff VALUES('SG16', 'Alan', 'Brown', 'Assistant 1 , '
M 1 , DATE '1957-05-25', 8300, ' B 0 0 3 ' ) ; , . , (, ' A l a n '
) .
I 5.36. , staff , : staffNo, ftfame, IName, position, salary
branchNo.INSERT INTO Staff (staffNo, fName, IName, position,
salary, branchNo) VALUES { ' S G 4 4 1 , ' A n n e 1 , 'Jones', ' A
s s i s t a n t ' , 8100, ' ' } ;
5. SQL:
203
http://openlib.org.ua/
, , . , , . , INSERT : INSERT INTO Staff VALUES ( ' S G 4 4 1 ,
'Anne 1 , ' J o n e s 1 , ' A s s i s t a n t 1 , NULL, NULL, 8100,
NULL, ' B G 0 3 . ' ) ; , sex DOB NULL.--.. -". J
INSERT . : INSERT INTO . TableWame -'.-SELECT .--.- : ^^^^
TableWame columnList , . SELECT SELECT. , , , . , INSERT, . 5. 37.
INSERT ... SELECT , Staff PropCount, , : Staff PropCount (staff No,
fNarie, IName, propCount) staff PropCount , staff PropertyForRent.
INSERT INTO StaffPropCount {SELECT s.staffNo, fName, IName,
COUNT(*) FROM Staff s. Proper t ForRent p WHERE s.staffNo p. staff
No GROUP BY s.staffNo, fName, IName} UNION(SELECT s t a f f N o ,
fName, INa-ne, 0 FROM S t a f f WHERE s t a f f N o NOT IN (SELECT
DISTINCT s t a f f N o FROM PropertyForRent) ) ;r
, , . UNION, , . , , . 204 II.
http://openlib.org.ua/
UNION, SELECT , count 0. . 5.41 StaffPropCount . 5.41. SQL 5.37
staffNoSG14 SL21 SG37SA9 SG5
fNameDavid
INameFordWhite
propCount
102 1 0 1
John
AnnMarySusan Julie
Beech
HoweBrand
SL41
Lee
, SQL UNION INSERT.
( UPDATE) UPDATE . : ^UPDATE. SET calumnNamel = dataValuel
[WHERE searchCondition] columnNameS '*= dataValueS
TableN&me , (. 6.4). SET , . WHERE . , . WHERE , , ,
searchCondition. dataValuel, dataValue2t... .
5.38. UPDATE 3%.
UPDATE Staff SET salary = salary*!.03; S t a f f , WHERE .
" 5. SQL:
205
http://openlib.org.ua/
5.39. UPDATE 5%. UPDATE Staff SET salary = salary*!.05 1 WHERE
position = ' M a n a g e r ; WHERE , . salary , salary =
salary*!.05.
5.40. UPDATE (BtafNo='SGl4 ') 18 000 . UPDATE Staff SET position
= 'Manager', salary = 18000 WHERE staffNo = 'SG14';
( DELETE) DELETE . : '''DELETE FROM TableName :[WHERE
searchConditionJ INSERT UPDATE, TableName , (. 6.4).
searchCondition , . . , , DROP TABLE (. 6.3.3). WHSRE , , ,
searchCondition,
5.41. ( DELETE) PG4. DELETE FROM Viewing WHERE propertyNo =
'PG4'; WHERE ,, ' PG4 ', . 206 II.
http://openlib.org.ua/
5.42. ( DELETE) vie