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

SQL

ALTER


SQL

Head First SQL


Lynn Beighley

Wouldn't it be dreamy
if there was Q book that
could teach me SQL without making
me want to relocate to a remote island
in the Pacific where there are
no databases? It's probably
nothing but a fantasy...

O REILLY
Beijing Cambridge Farnham Kln Sebastopol Tokyo

SQL

^^ '
-
-- -

2012

32.973.2-018.1
004.434
41

.
41

SQL. .: , 2012. 592 .: .


ISBN 978-5-459-00421-2
,
. SQL .
,
, .
,
.
, Head First O Reilly
, .
32.973.2-018.1
004.434

OReilly. .

.

ISBN 978-0596526049 .

ISBN 978-5-4594)0421-2

Authorized Russian translation of the English edition of


Head SQL O'Reilly Media, Inc. This translation is pub
lished and sold by permission of O'Reilly Media, Inc., the
owner of all rights to publish and sell the same.

, 2012
,
, 2012

, .
, .

-,
. ,
,
.

NRL
LANL. Flash
.

.
Yahoo!,
. ,
, -
.
, Head First,
,
.
, ,

.
,
.
.

3 .

25

37

SELECT;

87

D ELETE UPDATE:

153

193

ALTER:

231

SELECT:

267

311

;
?

373

409

10

, :

445

11

, :

481

12

519

I:

549

II: MySQL

567

III;

575

(^ ]^ ( )

80. ,
- ,
. :
,
.
, 301?
?

26

27

29

31

32

34

35

u ttf>.IIuUbi


? ,
25%, ... ,
, ... , .
, ,
, .
.

10

38

43

44

...

46

48

49

53

: CRE1ATE TABLE

55

56

, SQL

57

- my_contacts

58

59

60

64

66

68

INSERT

70

INSERT

73

INSERT

77

78

SELECT

79

N U LL

81

NOT N U LL DESC

83

DEFAULT

84

85



, .
SELECT ,

, .
WHERE, AND OR
.

88

SELECT

91

* ?

92

98

99

100

101

INSERT

102

105

107

114

117

120

122

125

127

AND OR

130

IS N U LL N U LL

133

LIKE:

135

135

AND

139

...

140

IN

143

NOT IN

144

NOT

145

150

11


? !
, DELETE UPDATE,
, .
UPDATE , DELETE ,
. ;
,
.

12

154

155

156

160

162

DELETE

163

DELETE

165

DELETE

166

INSERT-DELETE

169

DELETE

174

DELETE

178

UPDATE

180

UPDATE

181

UPDATE INSERT-DELETE

182

UPDATE

183

188

UPDATE

190

192

U j^oeKm uj^oBaH ue


. ; ,

s e le c t ,

in s e r t , d e le t e

u p d a te .

Ho

,
WHERE:
.

4. . ,

1,

1, ,
?

194

198

202

204

208

209

210

211

212

215

216

CRILATE TABLE

217

*5^

218

219

CREATE TABLE

220

L 2, 3

222

226

ALTER TABLE

227

228

13

ALIHl

?
, . ALTER
, ,
. ,
! ,
,
, .


,
. ,
!

14

232

237

238

239

241

242

243

ALTER CHANGE

244

SQL

245

! !

249

location

256

257

258

263

UPDATE SET

264

266

I^ C fflu J eHHbie


, ,
, WHERE.
, SELECT WHERE .
,
.

Da t a v iu q
V lD Q d

268

269

270

271

UPDATE CASE

274

276

281

282

ORDER BY

285

286

ORDER

289

ORDER

290

291

DESC

293

295

SUM

297

GROUP BY

298

AVG GROUP BY

299

MIN MAX

300

COUNT

301

SELECT DISTINCT

303

LIMIT

306

LIMIT

307

310

15

]^ 1


.
, .
,
.
, , ,
.

_111.
1
..1

|_1|^

10^ -

1
(^$11

1_1**
1
1110_1<^

16

(1|1

^\

11_11
1!)

312

324

325

clown_tracking

326

328

333

334

339

: --

339


--

340

: --

341

: -

342

345

: --

346

349

- 1...

351

352

354

355

355

356

360

, 2...

361

(^!)

366

_115?

367

370

^ *

?
!

, , ,
.
,

. ,
, .
, !
, ...

374

375

377

()

378

379

380

381

382

() CREATE, SELECT
INSERT

382

CRE1ATE, SELECT INSERT

383

AS?

384

385

386

387

.388

393

394

397

398

405

407

17


, , .
,
.
.

, .
,
. ( ,
!)

410

1 11 )1('

411

412

414

416

417

; .

418

419

421

424

427

428

429


: IN, NOT IN

43.S

438

NOT EXISTS

439

EXISTS NOT EXISTS

440

() i'pera

442

443

444

. BHytv\peHHULi
WHERE co lu m n =

18

-
i
^
(SELECT co lu m n FROM t a b l e )

^ , CoI3bi


,
. ,
, ,
.

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

)1.'^

______

0'\(,^

job. deiired

446

, ...

447

448

453

454

...

457

458

459

460

461

463

464

465

466

467

UNION ALL

468

469

INTERSECT EXCEPT

470

, ...

471

471

472

477

478

480

6 (5.

19

^, 1 ]|=' u
O rfs


,
, , SQL,
. ,

, ,
.
. , 1.

dataville
Savin gs & loan

20

482

483

N U LL

484

485

CHECK

486

CHECK gender

487

489

491

492

493

494

497

498

CHECK OPTION

501

, ...

502

503

504

505

506

508

509

SQL

510

511

MySQL

512

513

516

1)


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

520

521

root

523

524

525

GRANT

526

GRANT

529

REVOKE

530

GRANT OPTION

531

536

538

538

WITH ADMIN OPTION

540

CREATE USER GRANT

545

546

547

548

SQL ... ,

bashful

548

doc

dopey

grumpy

happy

J L

sleepy

sneezy
21


( )

1 -, .
(
. ,
, . ,/;
, ...
... . !
1.
2. ;1 ^
3. ALL, ANY S01V1E
4.
5.
6.
7.
8.
8. (
9.
10. PH P/M ySQ L
BEFORI BES1H BIHMY BIT BOOUUM BRUDTH
CASCADED CASE CAST CATALOG CBAR

X CLASS CLOe CLOn COLLATK

DATA DATE DAT DEALLOCATE DEC DECIMAL DECLARE DEFAOLT DBFEBMBLB DERRKXD DELETE
DEREF DESC DESCRIBE DESCRIPTCA DESTROX DESTTOCTOH DICTICMAIIT DlAOlOeTICS
DISCOMMECT DISTINCT DCMAIM DOUBLE DROP DTNMDC
EQOALS ESCAPE EVERT EXCEPT 10
FALSE FBTCH FIRST FLOAT FOR FOREIG FOUWD FLL
BAVUW ROST 3R

NAP IKCIFIES MXIFT


NAMES NATIONAL NATURAL ttCHAB NCLC tIBH N
08JICT o r OFF OLD ON ONLY ORM OPBRkllOM 01 Ot CflDIMU.ITT

SAVEPOINT SCHEMA SCROLL SCOPE SEARCH SECOND SECTIO SELECT SEgOEHCE SESSION
SESSIOM_USER SIT SETS SIZE SMAU.INT SOME SPACE SPECIFIC 81 SQL SQLEZCEPTICM
SgLSTATE SQUIARMIMS START STATE 8TATSMT STATIC STW CTCM ETTHI_PHOt
n_KD R TIMBtQ(IE_NIMOTE T
TRAILING TRAMSACTtON TRAMSLATIOM TREAT TRIGGER TRUE
UNDER mttOM qMIQOE___________________________
VALOE VALOES VAtCHAR VARIABLE VIEW
NHEM NHXMBVER NHERZ NRITE

!2

1335



, ,
MySQL.
!

568

568

MySQL Windows

569

MySQL OS X

.572

8 0
80,
. ,
!

23

1^ ^ ^ .
. . ^
- $ ^ ?

?
.

Oracle, MS SQL MySQL?
, ?
,

,
?
,
?

1.-'

SQL


*^ .

... .

?
...

SQL
?

SQL?
- ?
,
? , ,
SQL ,
?

... .

[ 6^-
.]
'

26





, -
, ~
.

?
- ?

,
. ,
, - . ,
.
,
? ,
,
.
. ,
.
, ? ,
.
?
. .
.

.
592 ,
.

...

, ! !
,
, , .
.
, ...
.

. " - - " '

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

27

'^ * , .
- ? - , .
.
, ,
- , . ,
.

Head First:
. ,
,
( 89%
). ,
. ,
, .
.
,

( )
40%.
, .
. ;
?
. ,
. ;
, .
,
.

( ) . , ;
, .
, , , .

. .
. ,

. , .
, - . ,
: , , ,^
, ! ,
,
, -
.

28

:

, . .
. , .




...

, , ,

. ,
.
,
.
. , .
,

.

, SQL ,
?
,
. .
,
, .
: ,
... , .

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

29

Bom :
,
, . 1024 .
, ,
.
: ,

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

t o y s . to y

b e y s .b
bey

hula hoop

balsa glider ^

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

30

^
^

Davey
Bobby

toy soldiers

Beaver

harmonica

Ricliie

baseball cards >

,
,
, .
.
,
. ,
;
.

------

,

^
^ > ^

. .
;
, , . .

. ,
.

- .
,
. , -
.
,
.


. -
, .

- .
, ,
- .

, .

,
.
.


.

,
.


.
\

.
: .
! .
.
(
)
\'0 ,
.
.
, ,
, .
, .

. (
,
)
.

,
.
. .
.

, .
!

.
-, !

. , | ... ,
1
:(.

31


, . ,
, .
,
.
SQL,
SQL .
, , ,
SQL.
SQL, .
, . ,
, .

.

,
SQL.
,
, , , ,
. ,
, 95%
.
.

SQL.
; Standard SQ L, MySQL, O racle, MS SQ L Server,
PostgreSQL, DB2... .
, ,
SQ L
MySQL. MySQL. ,
.
, ? ,
, .

.
.
, ,
. .

32

.
; ,
. , .
,
, ,
.
.
200 ,
. ,
, , .
,

.
,
.
h t t p : //www. h e a d f ir s tla b s . com/books/ h fsq l/
.
,
, (
). ,
.
SQL.
SQ L,
, SQ1. , -
,
.
MySQL ( SQL) Windows.
SQL .

, ,
! SQL-,
.
h t t p : //www. h e a d f ir s tla b s . /sql_hands_on/


^ ^ o oa.



,
,
.
.
.
15
,
,
,
.
,
, , ,
.
-


. ,

, , ,
.

,
- O nion

34

Flavored Rings
,
.
,
,
MCSE,

(-).

-,
-
. ,

.

.
,
, ,
DVD.

,
, ,
,
SQL.




Head First.

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

5


- ,
. ,
- .
, ,
.
,
, - .
, .
,
!
-1''

O R eilly
. -
,
. , ,
.
,
.
. ,

, . , !
,
,
. ,
.
liep 'Ta .

35

1 ]^10^

?
, 25% , ... ,
, ... ,
. , ,
, .

.


.
, , ,
, .
:

.

, ,
. ...

38


? ?

39

?

, ?

.
, .

,
,

.

40


.
, .
,
, .

1>
: >/'?/1 4
.

!^

^
1^ 1 !

-<>1

^1&1.

: ,
,

: ,

^-.

: ,

__
'^

^
-,

^<:

\
\

-,

an3elina@starbuzzcoltee.com

\ : ,
:

41

.
, .
, , .

I
.....^..{?.._
: 1 0 / ^ 1 ^?4

^- ,

@ ^ 5 -- 5 .

,

,

dontbothertSbreakneckpiz.a.

: , *
, /.6

: ,

: ,


.


.

. ^
> -,

^^

...................................

.........

^ . .............


:
/ / 17

.................................
[||0^

: ,^

42

:.1 1




:
,
.


.
, ,
:

----

1 4 /8 /1 4 7 4

^-

'

- ,

im p ,


,
:

fc foZnu^ I

/ / 7

I ""

II

'

||

j -,

/agliiaaSstarfenzzeoffee.cow

fcpafoma

, ,) ( [


Excel. SQL
? ?

II.

annie@boards-

1-7-1962

dontbother@

10-9-1964

- ,

breakneck

r-us.com

pizza.conn

soukup@
breakneck

1-7-1966

-,

pizza.com

angelina@
5tarbuzzcoffee.com

19-8-1979

- -

>

43

?
,
,
. SQL,
, ,
. - .

,

SQL .

, ,
, 1, ,
-
, .

\
-
.

, .

44

45


...
/
,
.

\,

.
,
,
.

/\^


?
. ,

: . , .
.


1^ .

46


.


. ,
: ,
, , ,
]@15--.8..

[| |1 . ^
]= ^
,
]=*. ^ ^
|>, *]=* *,
.

Starhuzx Coffee
2 .3 /4

Ouncan's Donuts

2.SM

^\

8 :s&

^ ^

5
2 6 /4

2 1 :3 4
-

shop
9
2 5 /4

47

1*

5 ! )11 ^

.
j e lly _ d o u g h n u ts

hop

lime

dale

rating

Starbuzz Coffee

7 :4 3

2 -5 /4

Duncan's Donuts

g :5 6

4/25

Krispy King

: p m

4 / 6

Duncan's Donuts

1 -0 :3 5 p m

4 / 4

^3

6

. ,
:

5
'i^y^snacks'
.

my_snacks



.
V__

48

,!

22:35

24/4

Starbuzz Coffee

-7-43

23/4

KrtspyKmg

2V39

26/4

;56

25/4

Stvbuzz Coffee

8
4

1^
a S j ju U b i

, .
( ) ,
. .

.
. ,
.

----------fir s f_ n a m e

la s f_ n a m e |1

1/

N .

a d d re s s

c ity

s ta le

id _ n u n i


().

.
^

ff ir s t_ n a m e

11_

a d d re s s

||

s la te

id .n u ln

49

,
?

.
.
.
.
.

.
>

1/8/1-7

s r : =

- (.

43)

^
I

I ....... I
-

I:
----- ^
f

- ,

an3elina@starhuz7Co{tee.

&

......

fc

^ ^
.

last_name

firsl_name

email

birthday

profession

status

interests

seeking

annie@boards-us.com

1-7-1962

,
,

dontbother
yahoo.com

10-9-1966

fprose
yahoo.com

2-12-1975

, IX

angel79@
gmail.com

19-8-1979

-
,



,,

.

50

. ,
.

lib ra ry _ d b
.

books

books

() :

library_patron
():

libraryJpatron

bank db
5> . ^
customer_info
():
bank_account
( ):

bank a cco u n t
o n lin e s to r e db
5 - .
p r o d u c t_ _ in fo
product_info
():

= h ^ g ,_ o a r t

shopping_cart
():

51

. ,
.

lib ra ry _ d b
.

books

books

(^) : , -, ,


library_patron
() :

1 i b r _ t r o n

...

bank db
.

customer_info
() :

...

'' ' ...........................


bank account
():

, ,

bank acco u n t

o n lin e s to r e db
- .

product__info
product info
()
s h o p p in g

52

r^cart

shopping_cart
() :

, ,

!
SQ L ().
.
MySQL :
I File

Edit Window Help Command^^

Welcome t o th e SQL m o n ito r. Commands end w ith ; o r \g.


Type ' h e l p ; ' o r '\ h ' f o r h e lp . Type '\ c ' to c l e a r th e b u f f e r .


.
.
,
.


SQL ,.

.

g r e g s _ l i s t .

CREATE DATABASE gregs_list;


CREATE
p a ta b a s e

^<
1



;
(
).
1

File Edit Window Help CommandMeBaby

> CREATE DATABASE g r e g s _ l i s t ;


Query OK, 1 row a f f e c t e d ( 0 .0 1 s e c )


5
,
.

MySQL
,

() .
MySQL II.

o C lIlo P o JK H b l!

53

USE gregs_list;




g r e g s JlS t!

I File Edit Window Help USEful

> USE g r e g s _ l i s t ;
D a ta b a se ch an g ed

_
,
?

SQL ,
.
.
SQL

.

,
.

---------------!

,
?


.
.
,
.
:

g r e g s _ lis t

G r e g s lis t
g r e g s L is t
CREATE DATABASE
.
?



, SQL .

,
.

:
CREATE DATABASE g r e g s _ l i s t ;

(CREATE DATABASE)
( g r e g s _ l i s t ) .

54


'_81?
?


SQL.
,
.

;
CREATE DATABASE.
?

;
.

gregsList ?

.
.

g r e g s L is t ,

,
,
m yC o n ta cts,

( 80,1
!).

: CREATE TABLE
,
,
. ,
,
.
,
.
,
,
.

doughnut_li s t



^
.

^
^

.
^

dou9hnel_name

doaghnal_lype

Blooberry

Cinnamondo

Rockstar

Carameller

Appleblush

!



.

^ ^-<0 ^


^
.

CREATE TABLE doughnut_list

1^
.

doughnut_name VARCHAR(IO)
doughnut_type VARCHAR(6)

;
5

.

. .
V A R C A R (VA R a e )
' ^ . ^ ( 6 ) -

,
6 .

55

, ?
gegs_list?

1(1
?
.
CREATE TABLE.

la s t najvie
fir s t n a m e
em a il
(birthday

profession

C R E A T E T A B L E

location

& ...

status

interests
seeking

/
lasl_name

firsf_iiame

email

birthday

prefcssion

iocalien

talus


. ?

56

interests

seelcing

, $01
,
. 1 .

.

1
CREATE TABLE
. ,
CREATE TABLE. ,
.

CREATE TABLE my_contacts


(

las t_name V A R C H A R (30),


first_name V A R C H A R (20),
email V A R C H A R (50),
birthday DATE,
profession V A R C H A R (50),
location V A R C H A R (50),
status V A R C H A R (20),
interests V A R C H A R (100),
seeking VARC H A R (100)

57

C R E A T E
T A B L E .

CREATE TABLE my_contacts

'my_contacts'

last_name VARCHAR(30),

last_name', ''
,}

first_name V A R C H A R (20), , 'firsts


', .4,'4

2-0

''

email V A R C H A R (50),

'email',
1. 1, 5 0

']_5@
1^.'

birthday DATE,

'birtWday',

'1 2 0 -0 5 -0 '

profession V A R C H A R (50), 'profession', ''


SO

location V A R C H A R (50),

'location',
6, 1-, 5 0

' - ,
'

status V A R C H A R (20),

'status',
20

' '

interests V A R C H A R (100), 'interests',


seeking VARC H A R (100)

', '

'seeking',
10 0

''

,
-,

) ;

1-00

- my.contacts
, ,
CREATE TABLE ' . ,
.
:

1 1 B y _ c o n t e ta (l e t_ n a M VARCHAR () , f ir e t _ n A M ((), M i l VARCHAR (5 0 ) , b i r t h d a y DATE, p r o C a a i o VAROIAA(SO), iM M tle n VAROIAR(SO), a tA tu a VARCBAR(20) , i n t n a t a

,
RETU RN ;, ,
:
l a s t _ n a m e VARCHAR (3 ) ,
la s t n a m e

58

VARCHAR( 3 0 ) !

(100) . 1|

,
.

,
!


I h ie td il

Window Help AIIDone

> CREATE TABLE my c o n ta c ts


:
RETURN
; ^
5/\
.

->

la s t_ n a m e VARCHAR( 3 0 ) ,

->

f ir s t _ n a m e VARCHAR( 2 0 ) ,

->

e m a il VARCHAR( 5 0 ) ,

->

b i r t h d a y DATE,

>

p r o f e s s io n VARCHAR( 5 0 ) ,

->

l o c a t i o n VARCHAR( 5 0 ) ,

->

s t a t u s VARCHAR( 2 0 ) ,

->

i n t e r e s t s VARCHAR( 1 0 0 ) ,

->

s e e k in g VARCHAR(1 0 0 )

->

) ;

Q u e ry OK, 0 row s a f f e c t e d

( 0 . 0 7 sec)

,
VARCHAR DATE?

-
.
,
. V A R C H A R
.
,
. ,
...

,
,
VARCHAR DATE.

59


.
. VARCHAR DATE
; .
/W T ( INTEGER)
,
,
.

CHAR

D K ( peCIMAL>

Ki^o ... , ~

o lc c U e e w x p o

^^< .

Hue
^V^OHOC^W^^

J3LOI3
ouAu^u

.

DATETIME
TIMESTAMP

.
(.

TIME

1.

DA
- 0(5
.

VARCHAR 1 ^
5 5 .

^ ,


.
^

, 6,
.

-.
.

60

1
... .

11

p r ic e

5678.39

DE C{ 6 , 2 )

zip code

5 10

atom ic
w eight


( 6 )

comments


( 255 )

q u a n tity

ta x r a t e

3.755
Head First SQ L

, .
. ,
? ...

book t i t l e

gender

phone
number

2105552367

s ta te

a n n iv e rsa ry

11/ 22/ 2006

(james won

m eeting
t. i me

( )

CHAR(1 )

D ATE
IN T

10:30 a.m. 4/ 12/ 2020


'

'^ :.10
>1
BLOB?

(, .
VARCHAR CHAR ( , 256 . BLOB
.
f)ti:ibi
. , BLOB |() ,

VARCHAR CHAR (
).


INT DEC?

!
.


.

? ?

, .

,

.
SQL in Nutshell
(O'Reilly) ,

.

61

KT9

... .


1 0 ,
VARCH
.
) im,l
CHAR
.

Uam cmoA6i(a

p ric e

5678.39

DEC(5,2)

z ip _ c o d e

5 10

V A R C H A R ( I O ) < ------ ^

a to m ic
w e ig h t


( 6 )

4 -.O O Z (b O Z

(1 0 , 6 )

comments


( 255 )

, .

. , ?
...

BLO

q u a n tity

INT

ta x r a te

3.755

(4 , Z )

b o o k _ title

Head First SQL

V A R C H A R (S O )

gender

CHAR(1)

phone
number

2105552367

C H A R (IO )

s ta te

C H A R (Z )

a n n iv e r s a r y

22/ 11/ 2006

D A TE

games won

1 S

IN T

m e e tin g
tim e

( )

PATETIME

10:30 4/ 12/ 2020

TIMESTAMP

. DATETIME
.

62



.

,


.


,
.
.
,
, c re a te
DATABASE.

c re a te ta b le
.
: CHAR,
VARCHAR, BLOB, INT, DEC, DATE DATETIME.

.

USE database,

.

, ,
_\'\5^?
, .

, .
,
m y _ c o n t a c t s , DESC
:

DESC my_contacts;

I File Edit Window Help DescTidy

> DESC my c o n t a c t s ;

0<11 >

63

DESC
:

^ ;

' 1 " 'window Help DescTidy

> DESC my c o n t a c t s ;
I Column

I N u ll

+ ------------------------

I K ey I D e f a u l t

I E x tra

---------------------- +------------+ ---- + --------------

------------+

1 la s t_ n a m e

1 v a rc h a r(3 0 )

1 YES

1 NULL

1 fir s t

1 v a rc h a r(2 0 )

1 YE S

1 NULL

1 e m a il

1 v a rc h a r(5 0 )

1 YE S

1 NULL

1 b ir th d a y

1 d a te

1 YE S

1 NULL

1 p r o f e s s io n

1 v a r c h a r (S O )

YE S

1 NULL

1 lo c a t io n

1 v a r c h a r (S O )

1 YE S

1 NULL

1 s ta tu s

1 v a rc h a r(2 0 )

1 YE S

1 NULL

1 in t e r e s t s

1 v a r c h a r ( lO O )

1 YES

I NULL

1 s e e k in g

1 v a r c h a r (1 0 0 )

1 YES

1 NULL

name

9 row s i n

set

(0 .0 7

s ec )



.
?

y T V P M
?

?

64

g e n d e r
. ?
; . ,
!

b irth d a y

USE

da te

gregs_list

first_name V3^RCHAR(20)
last name

VAR CHAR (30)

in t e r e s t s VARCHAR(100)
seekin g VARCHAR(100)

p ro fe s s io n VARCHAR( 50 )
lo c a tio n VARCHAR( 50 )

CREATE TABLE niY_con t a c t s ^

,
CREATE TABLE SQL
gender!
>

65

f^ T E


.

/

gencier.
.

DATABASE

'

USE gregs_li3 t ^
contacts

...

profession VARCHAR(50)
location VARCHAR(50 ),

6! !^. ^
V 'R E A TE TABL-B'^ , ,

status

^, ?

fyai'^'-vo
< &

interests VARCHAR(100),
seeking VARCHAR(100)

----

- ! .\'\1
, ,
^. :
I File

----

) ;

Edit Window Help OhCrapI

> CREATE TABLE m y _ c o n ta c ts

->

g en d er.

' co .
,
}.

->

la s t_ n a m e VARCHAR( 3 0 ) ,

->

f ir s t _ n a m e VARCHAR( 2 0 ) ,

->

e m a il VARCHAR( 5 0 ) ,

->

g e n d e r C H A R ( l) ,

>

b i r t h d a y DATE,

->

p r o f e s s io n VARCHAR( 5 0 ) ,

->

l o c a t i o n VARCHAR( 5 0 ) ,

->

s t a t u s VARCHAR( 2 0 ) ,

->

i n t e r e s t s VARCHAR( 1 0 0 ) ,

->

s e e k in g VARCHAR(1 0 0 )

->

) ;

ERROR 1 0 5 0

66

( 4 2 S 0 1 ) : T a b le

'm y _ c o n t a c t s ' a l r e a d y e x i s t s

BoTljoCbi

?

5:

1
,
.
;. ,
301.

,
gender,
,
.

seeking
^RCHAR(IOO) , ?


?
?

! seeking
. ,
, .

--------^

! ,
. 1\1
, ,
.

CREATE TABLE
? SQL
(,
T extE d it),
.

.

.



. ,

.

>

67

,
. :

.U

>5

(5>1-

...^

DROP TABLE my_contacts;


'

I File Edit Window Help ByeByeTabie

> DROP TABLE m y _ c o n ta c ts ;


Q u e ry OK, 0 row s a f f e c t e d

(0 .1 2

sec)

DROP TABLE
, ,

.

, .

CREATE TABLE:

1File

Edit Window Help Success

> CREATE TABLE m y _ c o n ta c ts


->
->


^(?^

68

(
la s t_ n a m e VARCHAR( 3 0 ) ,

->

f ir s t _ n a m e VARCHAR( 2 0 ) ,

->

e m a il VARCHAR(SO),

>

g e n d e r C H A R ( l) ,

->

b i r t h d a y DATE,

->

p r o f e s s io n VARCHAR( 5 0 ) ,

->

l o c a t i o n VARCHAR( 5 0 ) ,

->

s t a t u s VARCHAR( 2 0 ) ,

>

i n t e r e s t s VA R C H A R (IO O ),

>

s e e k in g VARCHAR(1 0 0 )

-> )
Q u e ry OK , 0 row s a f f e c t e d

(0.05

sec)

DROF
TABLE

!

SQL,
, ?.
,
, ,
.
, ,
.
.

:
CREATE DATABASE, USE DATABASE, CREATE TABLE, DESC,
DROP TABLE, CHAR, VARCHAR, BLOB, DATE, DATETIME,
DEC, INT

11

.
.
/.
.
.
, .
, .
.
.
, .
? .
.
.

. ^ -

69

^ M u K p *o C K n o M

, .

?


INSERT.
,
.
, .
,
,
INSERT.

)<
-JS E R T

^..
^^-C on tacts)

,
. -
,

first_name, last_name,
email . .


(
(

).

INSERT INTO _6 (, 2,...)


VALUES ( '' '2

-, ,

.

,

.


.



,

( , ' ').

(

/
).
^

:
, .

70


IN S E R T ,
.

first name

' '

status

' '

seeking

'1980-05-09'

gender

' '

birthday

' '

last name

' He

location

' '

interests

' - ,

profession

' j ill_ a n d e rs o n @ b re a k n e c k p iz z a . com'

email

' ,

'

'

'

aa n h iu e

71


INSERT,
.

first name

' '

status

' '

seeking

'1 9 8 0 - 0 5 - 0 9 '

gender

''

birthday

' '

last name

' '

location

^ ^

72

DATE


.

5/\.

:
^
.

interests

'-, '

profession

' j ill_ a n d e rs o n @ b re a k n e c k p iz z a . com'

email

', '

INSERT
RETURN
-

1^ ^71.

/ INSERT INTO my__contacts

______
______
(last_name,
first^name,
email, gender, birthday,
profession, location, status, interests,
C!A 1r4 n r r \
seeking)

VALUES

('', '', 'jill__anderson@


breakneckpizza.com',
'',
breakneckpizza.com' , '
-, '1980-05-09',
xi^ou-- ,
'', '-, ', ' '
', ^', '') ;



>^
.

^:1- VARCHAR.
R LO B .

!
I
*
1

'
^

.
. ,
, .
. :

73

,
CHAR, VARCHAR, DATE BLOB
INSERT. ,
(, DEC IN T )
?

.
INSERT
.
: d o zen s
p r i c e .

dozens
INT.

price
EC(4,Z ):


INSERT INT0\^oughnut_purchase
^
(donut_type, dozens, topping, price)
VALUES
C c \ 3 f

'sprinkles', 3.50);
dozens
price
!

74


,
.
IN SER T.
, , .

INSERT INTO my_contacts


(last_name, first_name, email, gender, birthday, profession, location, status,
interests, seeking) VALUES ('', '', 'jill_anderson@breakneckpizza.com',
'', '1980-05-09', '', ' ', ', ', '');

?
:

INSERT INTO my_contacts


(last_name, first_name, gender, birthday, profession, location, status, interests,
seeking) VALUES ('', '', 'jill_anderson0breakneckpizza.com', '',
'1980-05-09', '', '-, ', ' ', ', ', '');

?
:

INSERT INTO my_contacts


(last_name, first_name, email, gender, birthday, profession, location, status.
Interests, seeking) VALUES ('', '', 'jill_anderson@breakneckpizza.
com', '', '1980-05-09', '' '-, ', 'He ', ', ',
'');

?
:

INSERT INTO my_contacts


(last_name, first_name, email, gender, birthday, profession, location, status,
interests, seeking) VALUES ('', '', 'jill_anderson@breakneckpizza.
com', '', '1980-05-09', '', '-, ', 'He ', ', ',
');

...................................................................................... 5

...................................................................
...............................................................................

75

660

,
.
IN S ER T. ,
, .

INSERT INTO niy_contacts


(last_name, first_name, email, gender, birthday, profession, location, status,
interests, seelcing) VALUES ('', '', 'jill_anderson0brea]cneckpizza.com',
'', '1980-05-09', '', 'He ', ', ', '');
13 ecivit> 15& location, -

? location. ^

^ .

: 1 1 3 6 ( Z 1 S 0 1 ) : 6,8 !^

.U

INSERT INTO my_contacts

. ^ :
.

(last_name, first_name, gender, birthday, profession, location, status, interests7^\\


seeking) VALUES ('', '', 'jill_anderson@breakneckpizza.com', '',
'1980-05-09', '', '-, ', ' ', ', ', '');
_

,,

cmoAOi^a e m a i l . ^

, email .

: 5 1 1 3 6 ( Z 1 5 0 1 ) : - ' ^ ^
( 1).
INSERT INTO my_contacts
(last_name, first_name, email, gender, birthday, profession, location, status,
interests, seeking) V7LLUES (' ', '', 'jill_anderson0breakneckpizza.
com', '', '1980-05-09', '' '-, ', ' ', ', ',
' ') ;


profession location.
^

: 5 1 1 3 6 (2 .1 S 0 1 ):
( 1),
INSERT INTO my_contacts
(last_name, first_name, email, gender, birthday, profession, location, status,
interests, seeking) VALUES ('', '', 'jill_anderson0breakneckpizza.
com', '', '1980-05-09', '', '-, ', 'He ', ', '
');

: > 5 6 4 (4ZOOO): SQL.


MySQL
, " 4

76

INSERT
INSERT , .


,
!

INSERT INTO ny_contacts


(interests, first_name, last_naine, gender, email, birthday,
profession, location, status, seeking)
VALUES


.

.

.

(', ', '', '', '',


'jill_anderson@breakneckpizza.com', '1980-05-09', ''
'-, ', ' ', '');


,

. ( , . 73.)

INSERT INTO my_contacts


VALUES
('', '', 'jill_anderson@breakneckpizza.
com', ' ' , '1 9 8 0 - 0 5 - 0 9 ', '', '-, ',
' ', 'Kasnc, ^^', '');


,


!

INSERT INTO my_contacts


(last_name, first_name, email)

^VALUES
/ ('', '', 'jill_anderson@
I breakneckpizza.com');

I '

WIM*

iCHuu

,
,

?

>

77


VALUES:

m y _ c o n ta c ts
:

___

~
',
.
'

''
'patpost@breakneckpizza

flo4yv\aAt>oH

^\, NJ
patpostShreakneckpizzAiXOVVK

6> 3HA4WW,
- U o A H e 5

''

'

,
.
,
.

', NJ '

f t ?

" , 51


m oZ T o
.

INSERT INTO my_contacts


/
(first_name, email, profession, location)
VALUES
('', 'patpost0breakneckpizza.com',
'', ', NJ ');
I File

Edit Window Help MoreDataPlease

> INSERT IN TO m y _ c o n ta c ts ( f i r s t _ n a m e , e m a i l , p r o f e s s i o n ,
l o c a t i o n ) VALUES ( ' ' , 'p a t p o s t 0 b r e a k n e c k p iz z a .c o m ',

'', ', N J ');


Q u e ry OK,

78

1 ro w a f f e c t e d

(0.02

sec)

SELECT

, ? DESC
,
.
, ,
SELECT.



...
^

..
:

SELECT * FROM my__contacts;


,
SELECT.


2.
.

. ,
.

, ,
, n u l l . ,
?

>

79

SG jj :

NULL

Head First: , N ULL.


, .
,
. , ,
.
NULL: ? ,
, ! , ,
, , ?
Head First: , ...
, ...
NULL: , ,
, .
Head First: ?..
NULL: ,
.
,
. ,
f i r s t name
my c o n ta c ts ".
Head First: ,
?
NULL: , ! !
...
.
Head First: ,
,
?
NULL: ! .
, -
NULL. N U LL
. N ULL,
NULL,
N ULL !
?

80

Head First:
. ,
. ! , ?
NULL: , . ,
.
,
.
,
, .
.
.
Head First: ,
. NULL
.
NULL: ,
.
,
.

.
Head First: ,
?
NULL: ! !

: N ULL .
.
Head First: -
.
NULL: . ,
.

NULL 6
11
. ,
? N ULL
, . ,
N ULL .

CREATE TABLE my__contacts


NOT NULL
.

last_name VARCHAR () NOT NULL,


first name VARCHAR (20) NOT NULL
) ;




IN S E R T. '\

, .


CREATE TABLE m y _ c o n ta c ts

(
last_name VARCHAR(30) NOT NULL,
first name V A R C H A R (20) NOT NULL,
VARCHAR (50)
gender CHAR(l),
birthday DATE,


my_contacts CREATE
TABLE.
NOT NULL? ,

NULL, .
;
.
,


.

profession V A R C H A R (50),
location V A R C H A R (50),
C^ggEus VARCHAR (2dT7l:>
interests V A R C H A R (100),
seeking VA R C H A R (100)
) ;

81


CREATE TABLE my_contacts
(
'last_name V A R CHAR(30) NOT NU L L >
first_name V A R C H A R (20) NOT NULL,
email VARCHAR(50),
gender CHAR(l),


m y _ c o n t a c t s
CREATE TABLE.
NOT NULL?
,
NULL, .
;
.
,

.

birthday DATE,
profession V A R C H A R (50),
location V A R C H A R (50),
status V A R C H A R (20),



NOT NULL.

interests VARCHAR(IOO),
seeking V A R C H A R (100)

8 6
.
.
-. . ...

er.Au ,
,
. N U L L .

82

NOT NULL 6 DESC


my c o n t a c t s ,
( NOT NULL:
I

File Edit Window Help NoMoreNULLs

CREATE TABLE m y _ c o n ta c ts

(
la s t_ n a m e VARCHAR(3 0 )

NOT NULL,

f ir s t _ n a in e VARCHAR(2 0 )
e m a il VARCHAR(5 0 )


. ,

(^

NOT NULL

NOT NULL,

NOT NULL,

g e n d e r C H A R (l) NOT NULL,


b i r t h d a y DATE NOT NULL,
p r o f e s s io n VARCHAR(5 0 )
l o c a t i o n VARCHAR(5 0 )
s t a t u s VARCHAR(2 0 )

NOT NULL,

NOT NULL,

NOT NULL,

i n t e r e s t s VARCHAR(IOO) NOT NULL,


s e e k in g VARCHAR(1 0 0 )

NOT NULL

Q u e ry OK, row s a f f e c t e d

(0.01

sec)

> DESC my c o n t a c t s ;

------------------ .+---------------------- - + ---Column

1 Nu
N u ll

1 Type

.X
T
la s t_ n a m e

1 v a r c h a r (3 0 )

1 NO

f ir s t _ n a m e

1 v a rc h a r(2 0 )

1 NO

>.

e m a il

1 v a rc h a r(5 0 )

1 NO

gender

1 c h a r (1 )

1 NO

b ir th d a y

1 d a te

1 NO

p r o f e s s io n

1 v a rc h a r(5 0 )

1 NO

lo c a t io n

1 v a rc h a r(5 0 )

1 NO

s ta tu s

1 v a r c h a r (2 0 )

1 NO

NO

null.

in te r e s ts

1 v a r c h a r ( lO O )

1 NO

s e e k in g

1 v a r c h a r ( lO O )

1 NO

10 row s i n

set

I Key

I D e fa u lt

! E x tra

(0.02

sec)
>

83

DEFAULT u no
-
,
DEFAULT. , DEFAULT,

.
.

CREATE TABLE d o u g h n u t _ li s t
(


.


NOT NULL,

1 .

doughnut_name VARCHAR(10) NOT NULL,


doughnut_type VARCHAR(6) NOT NULL,
doughnut_cost DEC(3,2) NOT NULL DEFAULT 1.00

);


doughnut_cost,
INSERT
.


3 :
.

d o u g h n u t_ l s t

doHghnuf_name

deughnul^type

deughiiHl.cosf

Blooberry

2.00

Cinnamondo

1.00

Rockstar

1,00

Carameller

Appleblush

/ '

7
,
Cinnam ondo,
Rockstar Caram eller
doughnut_cost-

84

-. 1

1.40

DEFAULT


.

1.


desc .

d ro p ta b le
. !


. ,


in s e r t ,
.
NULL ,
.
, n u ll,
IS NULL,
NULL.

,
.

CREATE TABLE
!

,
in s e r t ,
NULL.
n u l l ,
NOT NULL
.
DEFAULT

,
.

n u ll

d ro p ta b le

U NOT NULL

,
,
!? n u l l

HWX. NOT NULL
.

in s e r t

Y~oM<

DEFAULT


;
,
.
*

SQL,
, ?.
,
, . ,
.
, ,
.
.

:
CREATE DATABASE, USE DATABASE, CREATE TABLE,
DESC, DROP TABLE, CHAR, VARCHAR, BLOB, DATE,
DATETIME, DEC, INT

.
.
/
.
.
, .
, .
.
.
, .
? .
.

11
P E C , INT
PROP TABLE

............................ '^.'.^''
CHARf%)

JE

...........'^'Si
^

CREATE DATABASE
INT
BLO
CREATE TABLE
CREATE DATABASE
ETIME

PESC
CREATE PATABASE,
U S E P T A B S E .......................

PROP TABLE

86

2 m


, .
SE L E C T
, ,
.
W H E R E , A N D OR
.


-
m y _ c o n ta c ts . .

-.
,
SELECT 1.

SELECT * from my__contacts ;



...
-mo.

* ^ jj^ e f a .

]=*

! m iJ_coii(acIs ^ c m januile
U >|>

88

.1 2

^.

> !\

,,

! . ^

, , ( | .

>

89

J p e ro M .

Q n iB e i

1 1

, : Anne_Toth@leapinlimos.co,

ce^ff ]"*,


_]11, "^hh
(^ |>
,

U a A j e ca

em J^o

, : anneh@ bO ttO m sup.com

. : >^&^;^(.^
5 , : anneunt@hreakneckpizza.co^^

nonmi^i.



.
,
-
, , .
,
...

: , <Anne_Toth@leapinlimos.com>
From: <greg@gregslist.Gom>
Subject: Starbuzz?

,
. .

; , <anneblunt@breakneckpizza.com>

: , <anneh@bOttOmsup.com>

From: <greg@gregslist.com>

From: <greg@gregslist.com>

Subject: Starbuzz?

Subject: Starbuzz?

, - ! , , ,
- .
. -
.
: Parker, Anne <annep@starbuzzcoffee.com>
From: Greg <greg@gregslist.com>
Subject: Starbuzz?

JTVPM
8 0 1
,
f ir s t _ n a m e
?

90

, ! ,
. [
, .

SELECT
( 1<! SELECT
( , .
WHERE,
. , ||| , .
WHERE ,
I 1 I . ;t_nam e ' '.

Mii.iK =

, .
|.1 .
[/ ?!


: ^ RETURN, ,
,' :
. first

, ~
>'-.

/
SELECT * FROM my contacts
IRE first__name = '';
|.

I I'VBA,
I,
^-o.ceu.

WHERE
,


-
SQL

first^namx.
,

.

tirst^ n am .e.

;1()
|., ir s t_ n a m e ' '.
I*1

I Window ' ^^

SELECT * FROM niy_contacts WHERE first_name = 'Anne' ; ,


I lt_nanie i first_name I email

1
1
1

1 gender | birthday | location

1 Anne Toth@leapinlimos.com |
1 am86@objectville.net
1
1 anneh@bOttOmsup.com
|
1 annep@starbuzzcoffee.
anneblunt@breakneckpizza.ccm|
I anne99@objectville.net |

1 NULL
i NULL
i NULL
1 NULL
I NULL
1 NULL

1 -,
1 , WA
1 -,
I -,
1 -,
1 -,

I
|
1
CA1
CA1
|
1

_ + ---------------------------------

rows in set (3.67 sec)


/1^


SELECT

91

, ,
* ? ?

* ?
( * )
.

SELECT * FROM my_contacts


WHERE fi ^ t name = '';

S E L E C T *
, - '
^
.

--------------1]|1


?
-
?

, .
,

92

,
,
.

, ,
,
?

yj- SQL
) .

^
. ;

SELECT SQL.

Head First Lounge . ,


1, .
drinks.
easy_drinks , .

e a s y d r in k s

main

amounti

second

amounts

directions

1.5

,
,

1.5

0.75

,
,

1.5

0.75

1.5

0.75

1.5

1.5

. a m o u n t i u ^
.
-------------------------^

OmBero

. ]|.

.
5
2 1 ]= !


n u l l .
. 151.

93

cAW

[goAfcii
CW/^

l.0CM0^^P^^

easy_drinks
' . ,

SELECT * FRC1 easy_drinks WHERE main = '';

?...................................................................................
SELECT * FROM easy_drinks WHERE main = ;

?...................................................................................
SELECT * FROM easy_drinks WHERE amount2 = 6;

?...................................................................................
SELECT * FROM easy_drinks WHERE second = " ";

?...................................................................................
SELECT * FRCM easy_drinks WHERE amounti < 1.5;

?...................................................................................
SELECT * FROM easy_drinks WHERE amount2 < '1';

?...................................................................................
SELECT * FROM easy_drinks WHERE main > '';

?
SELECT * FROM easy_drinks WHERE amounti = '1.5';

94

... :
. , ,
. !
,
.

, .
.
,
1.1.

: , .

... , , , .

95

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


, _1,

.

SELECT * F R ^ easy^drinks WHERE main = '';

/V

"V ___________ . o S p a m u ^ e

? ( { 0 . 6 . ^ . .......................... ____________________ _a nOCmpo<pt?iSELECT * FROM easy_drin]cs WHERE main = ;

Xm... ,
? . . ..................(_^^^

SELECT * FROM easy drinks WHERE amount2 = 6;

_________---------

A
OIA

.L,^^C

--

?. .. .. 3..(?..>[0................... 1 ^
SELECT * FROM easy_drinks WHERE second = " ";

?
SELECT * FRCM easy_drinks WHERE amounti < 1.5;

?..S o m ...................................................
SELECT * FROM easy_drinks WHERE amount2 < '1';

? ^(5 ^, /
SELECT * FROM easy_drinks WHERE main > '';

? ,

^
WHERE-

SELECT * FROM easy_drinks WHERE amounti = '1.5';

? . , , , >, 1

96

: , ...

< ^ 1

WHERE main = ;
... , , , .

WHERE second = " ";


..

WHERE amount2 < '1';


* . -
11^.

WHERE amounti = . 5

'

,
.
DEC I N T ,
. , .

97


W HERE,
.
.

in t e c :;e r )

..
ce-zda

.
>^ /V

( .
PEC 1M A ^^

BLO

'^ 1 , '
'nM ESJA ^;p

6 - -

^1^0.

''^''!

VARCHAR

'-

A MW

CHAR

PEC

VARCHAR

INT

PATE
PATETIME, TIME, TIMESTAMP
BLO
98


CHAR, BLOB, DATE
TIME
.
1
1
DEC
INT
.


.
.;1 ;


2 ^ ^ io n fla v o r e d r in g B .c o ^
:

: ,

INSERT INTO my_contacts

^^^

VALUES

(,', steve0onionflavoredrings.com,'',
'1970-01-04\ '
' , NJ', ' ',
'', ', ');
11<) - .
. .

I File

Edit Window Help AliensI

> INSERT INTO m y _ c o n ta c ts VALUES ( ' ' , ' ' , ' s te v e 0


o n i o n f l a v o r e d r i n g s . c o m ', ' M ' , ' 1 9 7 0 - 0 4 - 0 1 ' , ' ' , ' '
, NJ ' , 'H e ' , ' ' , ' ,
' ) ;

^\
: '>

: X *

WTVPM

, ?

99

,
? -
anocTpoqpoMH INSERT...


! ,

VARCHAR, CHAR DATE. ' ;
, .
.

/-

1 " -" V


.
, .

,

.

, ,
INSERT .

I File


:

^ (NSERT.<

Edit Window Help TakeTwo

> INSERT IN TO m y _ c o n ta c ts VALUES ( ' ' , ' ' , ' Steve@


o n io n f l a v o r e d r i n g s . c o m ', ' M ' , ' 1 9 7 0 - 0 1 - 0 4 ' , ' ' , ' '
, NJ ' , 'He ' , ' ' , ' ,
' ) ;

>
ERROR 1064 ( 4 2 0 0 0 ) : You h a v e an e r r o r i n y o u r SQL s y n t a x ;
c h e c k t h e m a n u a l t h a t c o r re s p o n d s t o y o u r SQL s e r v e r v e r s io n ;
f o r t h e r i g h t s y n t a x t o u s e n e a r ' , - ', 'H e
' , ' ' , ' , ' ) ;
' a t lin e

,
.

100


1',< VARCHAR, CHAR BLOB,
, , ,
<1 .
.

INSERT INTO my_contacts


(location)
VALUES
('' ');


SQL

<^0 ,

. < .

.
'
{ !

?

,
?


(, VARCHAR, CHAR,
Ml,OB TIM ED ATE. , ,
.

. ,
.

. 801 ,

,
.


DEC INT?


; , I
.

,

?

, . ,
SQL
(,
).

SQL
SQL,

.

>

101

INSERT
,
, ..


peuiHTb )' (
i n s e r t ),
:

INSERT INTO my_contacts


VALUES

,
\ ,
^,

, .
.

('', ' ,'steve0onionf lavoredrings^__^-^


com', '', '1970-01-04', ' ' ,
NJ ',' ', '',',
');

INSERT INTO my_contacts

.
VALUES
('',' ', 'steve@onionf lavoredrings^.^^
com', '', '1970-01-04', ' ,
NJ',' ','',',
');

W lA iT V P M

?

102

----------------------------------------------------------------------------------------------------------------- , , - noi|)*i
- .-

J\\<.<

w h e r e . ,
, .

.

SELECT * FROM my_contacts


WHERE
location = , N J ;

. *

103

, , - w h e r e . ,
, .

_
I

'1 -

SELECT * FROM my_contacts


WHERE
location = '' ;

SELECT

FROM my_contacts
:
.

WHERE

location = ' \

, NJ';

S ELECT * FROM my_contacts


:

WHERE

II
location =

104

snaGci 2

, N J ;


, , SELECT
.

SELECT *
.
?
?

s e l e c t
, .
,
. ,

,
.

l1o n p o 6 v u m 'e T ca M u
w uo Livre

SELECT, ,
.
( easy drinks . 93)

*
,.

SELECT drink^name, main, second


FROM easy_drinks
WHERE main = '';

105

1,'

6 VU

.

selec t,

d r in k n a m *

m c iiii

e c e n d


SELECT * FROM easy__drinks;
I File Edit Window Help



.

.

MessyD^p^y"

> SELECT * FROM e a s y _ d rin k s ;


------------------------ +---------- -----------------!"*"! ! -------- ------------------------------------- ----------------- +------------------I amounti I second
drink name
amount2
d ir e c tio n s
+------------------------------- +----------------------------------+----------------+----------------------------------+----------------+-------------------

------------------------------------------------------------------------------ +

I
I
I
2 .0 1 ]
7 . 0 0 |

I
I
I |
3 .0 | |
6 . 000
0 |
, |
I
I 1
|
1 .5 |
|
0 . 7 5 |
,
|
I
I 1
I
I
|
1 .5 |
5 . 0 0 |
,
|
I
I
I
I
|
2 .0 |
|

6 . 00 |
,
|
I
I
I
i
1 .5
-5 |
I
|
5 . 0 0 |

|
I
I
I
|
2 .0
. |
I
|
1 . 000
0 |
,
|
I
I
I
I
1 .5 I
|
1 . 000
0 |
, ,
|
I
I
|
15 |
|
0 . 7 5 |
, ,
1
I
1 |
1 .0 1
|
1 . 0 0 |
,
1
I
|
|
1 .5 |
|
0 . 7 5 |
,
|
'*'ZZZZ~~ZZ------------- Z~*~~ZZ'Z-----Z~~ZZt~Z~ZZZ~Z~'*--------------------------------------------------- -----------------------------I I rows in s e t ( 0 . 0 0 sec)

106

Vti


, ,
.
, WHERE
,
. ,
SQL.

SELECT drink_name, main, second


FROM easy_drinks;

...M w c y s u m b

,


.

Edit Window Help JustEnough

> SELECT drink_name, m ain, second FROM e a sy _ d rin k s;


I second
I drink name
I
+----------------------------1
1
1 |
1 1
|
1
1
1
1 1
1
1
1 1
1
1
1

1
1
1
1
1
1
1
|
1
1
1
|
I
1
1
1
1 1
1
|
1
1
1
|
+----------------------------- _+ ----------------------------- .+----------------------------------- +
11 rows in s e t ( 0 . 0 0


,
.
.
SQ L
, .

107

^ - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


e a s y _ d r inks?
SELECT :

SELECT drink_name FROM easy_drinks


WHERE
main = ' ';
SELECT , .
e a s y _ d r in k s

108

4 _

m a in

1 11

se co n d

a m u n l2

d ir c li n

1.5

,
,

1.5

0.75

,
,

1.5

0.75

1,5

0.75

1.5

1.5

SELECT

SELECT
WHERE

SELECT
WHERE

SELECT
WHERE

SEL E C T .
WHERE

SELECT,
.

d.3/ib!ue

109


!'

SELECT
WHERE

SELECT ,
.

dirink^name FROM easy_drinks


second = ']. ';

SELECT

dnnk_na\me FROM easy_drinks

WHERE

a m ountZ = 7;

SELECT

drink_nam e FROM easy_dhnks

WHERE

directions - ' ']

. ,
d rink_nam e FROM easy_drinks
SELECT
~
WHERE
d n n k _ n a m e = '';
^ .
.................................................................................................. ^'^"^_ .
.

SELECT,
.

SELECT drink_nam e FROM easy_drinks


WHERE main = ' ';

SELECT drink^name FROM easy_dnnks


WHERE second = '';

S ELECT drink_nam e FROM easij_drinks


WHERE directions = ' '-,

110

S E l E C T

,
,
,
.


WHERE
.

.


(
SELECT *,
).

* s e le c t
.

^
1]>1
?
SELECT * ?

,
*.
, .

,
.
- ?

501.
-.

, Microsoft Word?

, Word
,
. (PC) TextEdit
().

, ,
, ,

111

, ...

U ...
,
SELECT.
, 10.

,

.

doughnut_ratings
lin e

date

rating

1*

Starbuzz Coffee

7:43

2 3 /4

Duncan's Donuts

8:56

2 5 /8

Duncan's Donuts

19:58

2 6 /4

Storbuzz Coffee

22:35

2 4 /4

Krispy King

21:39

2 6 /9

Starbuzz Coffee

7:48

2 3 /4

10

Krispy King

20:56

25/11

|^

V.

1^
rating ,
, location
.

SELECT location, rating FROM doughnut_ratings


m iE R E

type = ';


... ,
,
.

location

rating

Duncan's Donuts

Starbuzz Coffee

Krispy King

Storbuzz Coffee

10

^ u n ( ^ ' s Dj^nutji^

112


type.

S tL E C T

... u
:

SELECT location, type FROM doughnut_ratings


WHERE

^
\

rating = 10;


_
3 ^^ , a , location
.


.
location

yp*

Starbuzz Coffee

Krispy King

Starbuzz Coffee
D m can^D cM utS y.


,
.

Keijc


.
,
...

113


10

A N D .
.

8bidpamt>
, locatioyi-

SELECT location

FROM doughnut_ratings
WHERE type = 'c
T
AND
AND
ycAoi" WHERE.
rating = 10;
. A N D .
, ,
10,
< .
.
location

rating

Duncan's Donuts

Starbuzz Coffee

Krispy King

Starbuzz Coffee

10

Starbuzz Coffee
Krispy King
Starbuzz Coffee

114

a 2

location

AND
location

1.-
.

,
.

type

Starb u zz C o ffe e

,
?

my_contacts,
. ,
. .

.

,
.

115

my c o n t a c t s , .
, .
.

]4:

10^ !

SELECT email
\^HERE profession - 'cqmpu^^

,
.


profession
' '.
^

S ELECT last_name, first_name, location


FROM my_contacts
WHERE birthday - '1 7 5 - -OS';

.

, -.

SELECT last^namCj first_name, email


FROM ,<(^!^-Cpntacts

WHERE location = [-
AND firstjnam e - '';

116

SELECT


, e a s y d r in k s
, ,
. :


.
SELECT drink_naine FRCM easy_drinks
WHERE
\-\anuw\Ku,
main = '1 '
.
AND
1 , 5
amounti = 1.5;
I File Edit Window Help MoreSoda

> SELECT d rin k _ n a m e FROM e a s y _ d r in k s WHERE m a in =

' ' AND

a m o u n ti = 1 . 5 ;
I d r i n k name
I

+--------------------------------- +
3 rows i n

set

( 0 . 0 0 sec)

SELECT drink_name FRCM easy_drinks


WHERE
Hanm^v\KUj
^
main = ''

-2- .
AND
V __ ^ amounti = 2;
I

File Edit Window Help EvenMoreSoda

> SELECT d rin k _ n a m e FROM e a s y _ d r in k s WHERE m a in =

' ' AND

a m o u n ti = 2 ;
d r i n k name

1 ro w i n

set

(0.00

sec)

I*

117

' ^

,

_1,
1 ...
, ...

e a s y _ d rin k s

4_

main

second

directions

1.5

, ,

1.5

0.75

, ,

1.5

0.75

1.5

0.75

1.5

1.5

118

:::; 2

St.


;
, 1.75
3 .
:

SELECT drink__name FROM easy__drinks


WHERE
main = '
AND

>
,^ ,

1 ;

I File Edit Window Help DoltOnce

> SELECT d rin k _ n a m e FROM e a s y _ d r in k s

WHERE m a in =

' ' AND

a m o u n ti > 1 ;
d rin k _ n a m e




4 row s i n

set

( 0 . 0 0 sec)

A
AND?

'>

119


WHERE
=.
>,
.
.

=
. , ,

.

.

=. ,
.

\

.

.
,
.
m

Z "

, w h e re
? ,
?

120

S E L E C T


, ,
.
,
.


.
.
,
.

,

.


: ,
,
.

.
,
.

.

,
.

>

121


.

.
d r i n k _ i n f
.$3.50, 50 .

-
-)-

d r in k

K.aAopuuHocmt>

in f o

__:_____

cost

carbs

color

ice

calories

8.4

33

2.5

3.2

12

3.5

8.6

35

2.5

5.4

24

5.5

42.5

171

3.2

32.1

135

3.6

4.2

17

14

50

4 ,

2.8

7,2

30

2.6

21.5

80

3.8

4.7

19

ELEC T d r i n k

nam e FROM d r i n k

WHERE

in f o

;
^3.5-0 .
, $ . 5 0 .

cost > = 3 .5
AND
c a lo r ie s

<

50;

: ,
SO .

,

AND. ,
.

122

; 2

- ^
. ,
. .

,
33 .

:
, 4
, .

: .................................................................
, 80 .

:
,
, !

^'.v;>/e >

123

- ^

. ,
. .

,
33 .

S ELECT cost FROM d n n k j n f o


............................................. W H E R E ' i c e ...............................
............................................. A N D .......................................................

color = 'yedovj'
"AND......................
cfWes > 3 3 ;'

$4 0 0

, 4
, .

SELECT rink_nam e, color FROM d r in k jn fo


W HERE

carhs < = 4
.................. AND ......................................................................................

............... ..................................................................................
:...........
, 80 .

S ELECT cost FROM d r in k jn fo


............... WHERE ..................................................
.C(]lorjes >= 8 0 ; .................................................................. ^

fS .S O , $ 3 .Z O , fZ .& O

Ho
, ?

,
?

,
, !

SELECT drink_nam e, color, ice FROM d r in k jn fo


""w h e r e ................................................ .............. ..........................................
" c o s t >= ' :8 - ........^ 5 ^ :::::::::"............ ...
.................................................................... ..................................................................... /
.................................................................... ,
, ,
: , ,
! _
........................................................... .

124

SELECT


(CHAR VARCHAR)
. .
, , ;
, .

drink info
_

coat

carb s

c o lo r

c a lo r ie s

8,4

33

2.5

3.2

12

3.5

8.6

35

2.5

5,4

24

5.5

42.5

171

3.2

32.1

135

3.6

4,2

17

14

50

2.8

7,2

30

2.6

21,5

80

3.8

4,7

19

SELECT drink_name
FROM drink_info
WHERE
drink_name >= ' '
AND
drink name <

' ';

,

, nepM^fi
.


.
,
.

125


.
.

I File

Edit Window Help..

> SELECT d rin k _n am e FROM e a s y _ d r i n k s WHERE m ain = ' '


+ -------------------------+
I drink_nam e
|
+ ------------------------- +
I
I
+------------------------- +
1 row i n s e t

(0.02 sec)

> SELECT d r in k name FROM e a s y d r in k s WHERE se co n d = ' ' ;


d r in k name

1 row i n s e t

( 0 .0 1 sec)
?
.

drink info
|1 1 _

<0 * 1

c o lo r

c a lo r lo s

8,4

33

2,5

3.2

12

3.5

8.6

35

2,5

5.4

24

5,5

42.5

171

3.2

32.1

135

3,6

4.2

17

14

50

2,8

7.2

30

2.6

21,5

80

3,8

4,7

19

126

:: 2

StFi.bCi


.
, .
, .
eetr'.hAm/Pie
> SELECT d rin k _n am e fro m e a s y _ d r in k s
WHERE m ain = ' '
s e c o n d = ' '
I d r in k name
I

1
+

I
+

2 row s i n s e t

(0.02 sec)

^
SELECT
OR, SELECT:

SELECT d r in k _ n a m e
m a in =

WHERE

' ' ;

SELECT d r in k _ n a m e
m a in =

FROM e a s y _ d r in k s

FROM e a s y _ d r in k s WHERE

' ' ;

SELECT.

127

- ^

SELECT
OR, SELECT.

SELECT d r in k _ n a m e FROM e a s y _ d r in k s WHERE


m a in =

-
.-.

m a in =

' ' ;

^0 OR
, ^1^ ,


^,,

(
)-

SELECT.

SELECT dn'nk_name FROM easy_dnnks


WHERE
m ain - ' '
OR
main = ';

128

,
.

SbLECT

OR
, ,
AND?

AND 0R!
,
AND.

, 0R.
? .

OR

)
_____

______

B o I lp jC b i

AND OR
WHERE?

,
. AND
OR.

129

AND Im: OR?

AND om OR
('.
1 , AND OR.

d o u g h n u t_ r a tin g s
location

lime

type

rating

comments

Krispy King

8:50

date
27/9

10

Duncan's Donuts

8:59

25/8

NULL

Starbuzz Coffee

19:35

24/5

Duncan'sponuts

19:03

26/4

SELECT ty p e FROM d o u g h n u t_ ra tin g s


, .

Aa

WHERE l o c a t i o n = 'K r is p y K in g ' AND r a t i n g = 1 0 ;

WHERE l o c a t i o n = 'K r is p y K in g ' OR r a t i n g = 1 0 ;

WHERE l o c a t i o n = 'K r is p y K in g ' AND r a t i n g = 3 ;

WHERE l o c a t i o n = 'K r is p y K in g ' OR r a t i n g = 3 ;

^ ^ ^ ^ o 6 n a d eH u u,

WHERE l o c a t i o n = 'S nappy B a g e l ' AND r a t i n g = 1 0 ;

WHERE l o c a t i o n = ' Snappy B a g e l ' OR r a t i n g = 1 0 ;

WHERE l o c a t i o n = ' Snappy B a g e l ' AND r a t i n g = 3 ;

WHERE l o c a t i o n = ' Snappy B a g e l ' OR

130

ra tin g = 3 ;

SELECT

| cejnifi ^VUERE
^|]) U 01^. ^
ijcjioBuu onj>eAejiuine, >11 .

SELECT ty p e FROM d o u g h n u t_ ra tin g s

P63y

WHERE l o c a t i o n

'K r is p y K in g ' AND

r a t i n g <> 6 ;

WHERE l o c a t i o n

'K r is p y K in g ' AND

ra tin g = 3 ;

WHERE l o c a t i o n

'S nappy B a g e l ' AND

WHERE l o c a t i o n

'K r is p y K in g ' OR

ra tin g > 5 ;

WHERE l o c a t i o n

'K r is p y K in g ' OR

ra tin g = 3 ;

WHERE l o c a t i o n

'S nappy B a g e l ' OR

r a t i n g >= 6 ;

ra tin g = 6 ;

| ,

J*e3yjlbmaina .

131

QmBem

* cejuff

U QJ^. ^

^>,

SELEC T t y p e FROM d o u g h n u t _ r a t i n g s

WHERE l o c a t i o n

= 'K r is p y K in g ' AND

r a t i n g <> 6 ;

WHERE l o c a t i o n

= 'K r is p y K in g ' AND

ra tin g = 3 ;

WHERE l o c a t i o n

= ' Snappy B a g e l ' AND

WHERE l o c a t i o n

= 'K r is p y K in g ' OR

ra tin g > 5 ;

J NULL,

WHERE l o c a t i o n

= 'K r is p y K in g ' OR

ra tin g = 3 ;

WHERE l o c a t i o n

= ' Snappy B a g e l ' OR

r a t i n g >= 6 ;

ra tin g = 6;

NULL

]^ ,
.

NULL.
N U L L .
- , N U L L ,
NULL .

132

SELECT

IS NULL NULL
^ ,
NULL, .
NULL ?

V ._____

____

d r in k

in f o

d riiik .n a iM *

cost

carbc

1er

ca le rie s

NULL

14

NULL

50

2.9

7.2

NULL

NULL
.

NULL .
SELECT d r in k _ n a m e FROM d r i n k _ i n f o

WHERE
c a lo r ie s

= '> 4

,

M U L L
.

He
;

SELECT d rin k _ n a m e
FROM d r in k _ in f o

SELECT d r in k _ n a m e FROM d r i n k _ i n f o

ui'

e re

WHERE

' /-/e ; NULL

a
.

c a lo r ie s

SELECT d r in k _ n a m e FROM d r i n k _ i n f o
WHERE
c a lo r ie s

^ ----- " , NULL



.


c a lo r ie s IS NULL; NULL
p
^

-


, 15 NULL,
.

--------------------------------------------------B o I^ C b i
, NULL
IS NULL. , , ?

:
J . ,
WHERE .
, N U LL;
SELECT c a l o r i e s FROM d r i n k _ i n f o
WHERE d rin k _ n a m e = ' ';

I calories

+---------------I NULL
+ -------------

133

6 ...
m y _ c o n ta c ts
, . ,
, :

SELECT * FROM i t ^ _ c o n t a c t s

OR !

-v_

WHERE
lo c a tio n

' - , CA'

OR
lo c a tio n

----=

' - ,

CA'

' - ,

CA'

' ,

CA'

' , CA'

' , CA'

' - ,

CA'

' ,

CA'

' - ,

OR
lo c a tio n
OR
lo c a tio n
OR
lo c a tio n
OR
lo c a tio n
OR
lo c a tio n
OR
lo c a tio n
OR
lo c a tio n
OR
...

134

CA'

SELECT

LIKE:
.
,
OR, ,
, LIKE,

.
L IK E :

SELECT * FROM my_contacts


WHBKE location LIKE '%CA<
-


L IK E
.,
.
,
, (
).

\ ^ ^^


,
location, ^
^ .

135

LIKE

LIKE
L IK E
. %
.

SELECT f ir s t _ n a m e
WHERE f ir s t _ n a m e
'

FROM m y _ c o n ta c ts
L IK E

'% '

^ 5 ^ -


,


, ,
. .

,
L IK E ,
(_)
.

SELECT f ir s t _ n a m e
WHERE f ir s t _ n a m e
^

136

FROM m y _ c o n ta c ts
L IK E


,

K'UM^
. .

S E L E C T

!
1

WHERE L IK E
.
?
. L IK E
.

WHERE

WHERE title LIKE 'SQL%';

l ik e

'% ^

137

!
WHERE L IK E
.
?
. L IK E
.

flHEBE s t a t e

l ik e

cow _nam e L IK E

'-%'

'

s i e ';

WHERE t i t l e

L IK E

' SQL%' ;

SQL

W H E R E word LIKE

rh y iiie _ w o rd L IK E

% . ;

WHERE f i r s t nam e

1 *"^*

WHERE word LIKE

138

S E t C )

AND

,
.
,
30 60 ?

d r in k

in f o

4 1 _

cost

carbs

ice

ca lo rie s

8.4

33

2.5

3.2

12

3.5

8.6

35

2.5

5.4

24

5.5

42.5

171

3,2

32.1

135

3.6

4.2

17

14

50

2.8

7.2

30

2.6

21.5

80

3.8

4.7

19

SELEC T

d r in k _ n a m e

FROM

d r in k _ in fo

W HERE

c a lo r ie s

> = 30

^ ^

AND

c a lo r ie s

<=

60;

^ ^


,
:
3 0 ,
<

139

BETW EEN

...

BETWEEN.
,
. : BETWEEN
(30 60). BETWEEN
<= >=, < >.

SE L E C T d r i n k _ n a m e F R O M d r i n k _ i n f o
M IE I

calories BETWEEN 30 AND 60;



3 0 &0 .

[ pile Edit Window Help MediumCalories

> SELECT drink_name FROM drink_info


raERE
calories BETWEEN 30 AND 60;
1_

140


,
,
.

SELECT

,
, 60
30 .

BETWEEN . ,
, .

, ?

SELECT d r in k _ n a m e
c a lo r ie s

FROM d r i n k _ i n f o

WHERE

BETWEEN 60 AND 3 0 ;

>

141

- ^
'066

,
, 60
30 .

SELEC T drink_nam e FROM d r in k jn fo


,

............. ........................................... ^^,^.<::.^<?. . ./?.^.^.-.


calories < 3 0 OR calories > 6 ;
___ ,

3 0 .
BETWEEN . ,
, .

SELECT drink_nam e FROM d r in k jn fo


WHERE
drink_nam e BETWEEN ' ' AND 'O';

,
/\, .
, ?

SELECT d rin k _ _ n a in e FROM d r i n k _ i n f o


c a lo r ie s

WHERE

BETNEEM 6 0 AND 3 0 ;

,
.':^.'^... . .................................................................

, 60 30.
, 60 30.
BETWEEN , ,
.

142

SELECT

IN
, ,
. ,
.
_ .
,
.

SELECT d a te _ n a m e
FROM _

WHERE
r a tin g

'

OR

' . ^ : ^ ^ .

OR

b la c k b o o k
1 1 _11

119

,
1 . 1
.
,
.

3a iN

SELECT d a te _ n a m e
.
FROM b l a c k b o o k

WHERE
r a t in g

IN

( ' ' ,

' ' ,
' ' ,
* ' ) ;

143

N O T IN

NOT IN
, ,
. ,
- .
,
, IN NOT.
NOT IN ,
.

SELECT date_name
FROM black book
WHERE
r a t in g

NOT IN
, 'mam .

NOT IN

,,

(' '
' '
'
) ;

File Edit Window Help

NOT IN

,

, ,

.

BadDates

> SELECT date_name FROM black_book


WHERE
rating NOT IN {'',
'', '', '');

I d ate name

NOT IN IN?

6 rows in s e t ( 2 . 4 3 sec)

144

SELECT

NOT
NOT
IN , BETWEEN L IK E .
, NOT WHERE.
.

SELECT d r in k _ n a m e
WHERE NOT c a r b s


NOT

A N P

SELECT d a t e

FROM d r i n k _ i n f o

BETWEEN 3 AND 5 ;

nam e fr o m

b la c k b o o k

WHERE NOT d a te _ n a m e L IK E

n u c J a Z Z a n d

NOT d a t e

nam e L IK E

'A%'

'E%'

AMP OR.

^
) 1
, NOT

NOT NULL?

WHERE. NOT IN?

; . ,
, NOT WHERE, , NULL,
.
:
:
SELECT * FROM easy_drinks

SELECT * FROM easy_drinks

WHERE NOT main IS NULL;

WHERE NOT main IN (' ');


SELECT * FROM easy_drinks
WHERE main NOT IN ('',

:
' ');

SELECT * FROM easy_drinks


WHERE main IS NOT NULL;

NOT ( )?

A AND OR?

' , .
=.
:

AND OR NOT
:

SELECT * FROM easy_drinks


WHERE NOT drink_name <> '';

SELECT * FROM easy_drinks


WHERE NOT main = ''

SELECT * FROM easy_drinks


WHERE drink name = '';

0:.

AND NOT main = ' ';

145

..

w h e r e , .

AND, OR, NOT, BETWEEN, LIKE, IN, IS NULL .

SELECT d rin lc _ n a m e fr o m
WHERE NOT a m o u n ti <

SELECT d r in k _ n a m e
WHERE NOT i c e

WHERE NOT c a l o r i e s

1 .5 0 ;

FROM d r i n k _ i n f o

' ';

SELECT d r in k _ n a m e

146

e a s y _ d r in k s

FROM d r i n k _ i n f o
< 20;

w h e r e , .

AND, OR, NOT, BETWEEN, LIKE, IN, IS NULL .

SELECT d r in k _ n a m e

fr o m

WHERE NOT a m o u n ti <

e a s y _ d r in k s

1 .5 0 ;

SELECT dn'nk_name FROM easy_dn'nks


WHERE amounti- >= l.S O ;

SELECT d r in k _ n a m e
WHERE NOT i c e

FROM d r i n k _ i n f o

' ' ;

SELECT dn'nk_name FROM d r in k jn fo


WHERE ice = 'H';

SELECT d r in k _ n a m e FROM d r i n k _ i n f o
WHERE NOT c a l o r i e s

< 20;

SELECT drink_nam e FROM d r in k jn fo


WHERE calories >= 2 0 ;

148

SELECT

SELECT d r in k _ n a m e
WHERE m a in =
OR m a in =

FROM e a s y _ d r in k s

' '

' ';
,

....................................................................................... 6 main SBLECT d r i n k FROM e a s y _ d r i n k s


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

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

2 ^ 4

WHERE m a i n BETWEEN '' AND ; R



............................................................................... .

SELECT d r in k _ n a m e FROM d r i n k _ i n f o
WHERE NOT c a l o r i e s

0;
...............

select d M ^

.....................

SELECT d r in k _ n a m e
WHERE NOT c a r b s

FROM d r i n k _ i n f o

BETWEEN 3 AND 5 ;

S ELECT drink_nam e FROM d r in k jn fo


WHERE carbs < 3
OR.........................................................................................................

....carhs,>,St .......................................................................................

SELECT d a te _ n a m e

fr o m b la c k _ b o o k

WHERE NOT d a te _ n a m e L IK E
AND NOT d a te _ n a m e L IK E

'A%'

' B% ' ;

SELECT date_nam e FROM black_hook


WHERE date_nam e NOT BETWEEN 'A ' AND '5';

149

s q l


2,

GNJ

.
III.

= < > < > < = > =

\ ^^

I S NULL

a^v

\ \


NULL.

\ 1^-

^) VI

*-

^
yvO
- " "
0

,1-

'^ '

hO-

,^ >

:
'

150

L ik e
I

SELECT


. 93

2 2

Head First Lounge . ,


1, .
drinks.
easy drinks , .

CREATE DATABASE d rin k s;


USE d rin k s ;
CREATE TABLE easy_d rin k s


^^
1^ -
.

(drink_name VARCHAR( 1 6 ) , main V3ACHAR(20), amounti D E C (3,1),


second VARCHAR(20), amount2 DEC( 4 , 2 ) , d i r e c tio n s VARCHAR(250)} ;

INSERT INTO easy_d rin k s


VALUES

He :
/ !

('', ' ', 1 . , ' > 1 , ' ,


, ) , (' ', ' ', 1 . 5 ,
' ' , . 7 5 , ' , ,
' ) ,

(' ', ' ', 1, ' ', 1, '


, '),
(' ' , '>', 1 . 5 , ' ', . 7 5 , ' ,
') ,
( ' ' , ' ' , 2 , ' ' , 7 , '
' ) ,
(51 ', ' ', 3, ' ', 6, '
, '),
(' ', ' ', 1 . 5 , ' ' , . 7 5 , '^ ,
' ) ,
(' ', ' ', 1 . 5 , ' ' , 5, ' ,
( ' } ,
(' ', ' ', 2 , ' ', 6, ' 1,
'),
(''', ' ' , 1 . 5 , '', 5 , '

2 , ' ', 1 , '

151

?
! ,
DELETE UPDATE, ,
. u pdate ,
DELETE

. ;
,
.


, ,
. c l o w n _ i n f ,
l a s t se e n .

%
15
.'5

154

'^11^
:

d e le te up d a te


. ,
, . ,
, .
ay^uI, .

, OLjHa

nam e

c lo w n

^ 181_

in f o

a c t i v i t ie s
,

, , ,

, , ,

, ,

, , ,

, , ,

, , ,

, ,

pJy

;11^

, - ,

L ^

------------

OAKLAND
HOSPITAL

MILLSTONE
M ALL

Dickson

1 % Park
5
1

Otracy- s
Eywt's
Mim

f Belmon t'^
Senior Center

m tr

155

- ^


SQL
clown in f . ,
; . 155.

INSERT INTO clownJnFo


VALUES
('', ' ', ',
^ ', ', '):

INSERT INTO clown jnfo


VALUES
('', ' ', ' , ,
', ', ');

^
<^ /\UKC0H.

- .

156

d e le te up d a te

c l o w n _ i n f
INSERT? .

nam e

181_8

a ppearance

a c tiv itie s

, , ,

, , ,

, ,

, , ,

, , ,

, , ,

, ,

, - ,

>

157

eo3bfu .


SQL
clo w n _in f . ,
INSERT.

VALUES
('', 'j '.
, ', ', ');

INSERT INTO clow njnfo


VALUES
(''. ' '. '. ,
', ', '};

JNSERr iNTO cIpwnJ.K^fo.


^
.

VALUES

', ', ^');

INSERT INTO clow njnfo


|? .

VALUES
(''. ' ', '. , '.
' ');

VALUES
^.9.^9'.;.

.O .??!;. '

j^a. , ', '').

1 58

d e le te upd a te

nam e

11_

a ppearance

a c tiv itie s

, , ,

, , ,

, ,

, , ,

, , ,

, , ,

, ,

, - ,

. ,

. ,

'

Mj -
,

87

, , ,

>

159


.
-
.
.
,
.
SELECT;

File Edit Window Help CalchTheClown

SELECT * FROM clown info WHERE name = ' ';

, ,

, ,

, ,

^ , ,

\ , ,

\ , ,

\, ,


?
, ?

160

d e le te u p d a te

-
,
.
.

, ,
.
,
,
.
, ,
.
,

,
( ).

,

.

161

,
,
, .
, .
, !
. ?
, , .
.
. ,
. ,
, .
, .

> 1
,
?

:
,
. ,

. ,
- .
, INSERT .
,
, ,
.

, .
?

.
. ,
.
.

, ,
.

162

?
?

. :

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

,
.
,
?

^
. , 301,
.
.
,
,
.

d e le te u p d a te

) DELETE
,
. ,
.
( )
, .
; D E L E T E .
W H E R E .
, , .
. .
nam e

181_

a ppearance

a c tiv itie s

, ,

, ,

, ,

,
,

, ,

, ,

, ,

, ,


,
. , ,
, .

WHERE

,

^
.

.

Jll

FROM

163

DELETE

1

,
. , , ,
.

S ELEC T ^ , .

d elete

<?-

FROM

,
.


^ . (^
Jbe

WHEBE

^^
W H E R E ,

) ,
.
DELETE

WHERE DELETE
,
SELECT.

164

d e le te up date

DELETE
DELETE.
, : ,
WHERE, .

DELETE FROM clown_info


WHERE
a c t i v i t i e s = '';
nam e

181_

, , ,

, , ,

, ,

, , ,

, , ,

, , ,

. , ,

, - ,

, ,

, ,

, - ,

, , ,

11>

'

1<

'S 3-)
CO

, d e l e t e
?

>

165

DELETE

DELETE
d e le te
.
d e le te
( where).
.
.

WHERE. WHERE
where s e l e c t (. 2);
2,
l i k e , i n , between .

:
DELETE FROM your t a b l e

--------- --------------------)> 1
NHEBE DELETE -
WHERE SELECT?

. WHERE ,
SELECT DELETE .
SELECT ,
WHERE,
DELETE ,
WHERE.

166

d e le te u upd a te

|jeAciriaBbJiie

WIPE

rj^yimbi

- ,

-
.

> 1

DELETE FROM d o u g h n u t _ r a t i n g s


( ).

WHERE l o c a t i o n

= 'K r is p y K in g ' AND

r a t i n g <> 6 ;

WHERE l o c a t i o n

= 'K r is p y K in g ' AND

ra tin g = 3 ;

WHERE l o c a t i o n

= ' Snappy B a g e l ' AND

WHERE l o c a t i o n

= 'K r is p y K in g ' OR

ra tin g > 5 ;

WHERE l o c a t i o n

= 'K r is p y K in g ' OR

ra tin g = 3 ;

WHERE l o c a t i o n

= ' Snappy B a g e l ' OR

r a t i n g >= 6 ;

ra tin g = 6;

doughnut_ratings
le c a li n

lim e

d a le

ty p e

r a tin g

cem m ent

Krispy King

8:50

27/9

10

Duncan's Donuts

8:59

25/8

NULL

Starbuzz Coffee

19:35

24/5

Duncan's Donuts

19:03

26/4

>

167

DELETE,

*111 ^

. WIEfiE- ^ ,
! -
!.

f JoBeAume 1 o m

D ELETE FROM d o u g h n u t r a t in g s


( ):

WHERE l o c a t i o n

= 'K r is p y K in g ' AND

r a t i n g <> 6 ;

WHERE l o c a t i o n

= 'K r is p y K in g ' AND

ra tin g = 3 ;

WHERE l o c a t i o n

= 'S nappy B a g e l ' AND

r a t i n g >= 6 ;

WHERE l o c a t i o n

= 'K r is p y K in g ' OR

ra tin g > 5 ;

WHERE l o c a t i o n

= 'K r is p y K in g ' OR

ra tin g = 3 ;

WHERE l o c a t i o n

= ' Snappy B a g e l ' OR

H em .

.

H em .
6 ;
.

ra tin g

doughnut_ratings
Iocalien

lime

d al*

type

rating

* 1

Krispy King

8:50

27/9

10

Duncan's Donuts

8:59

25/8

NULL

Starbuzz Coffee

19:35

24/5

Duncan's Donuts

19:03

26/4

/
^

^ N U L L ^
- , N U L L N U L L .

168

d e le te up date

INSERT-DELETE

. ,

, .


.

.
. 1 (5

,
nam*

IN SE R T

actlvili

, ,
,

( ),

IN S E R T IN T O c lo w n _ in f o
^
/
1!:>
.
VALUES
( ' ' , ' ?' , ' , <

, , ' , ' ' ) ;
nam e

last_*e en

appearance

a c tiv ltie s

, , -

INSERT

, ,
,

DELETE

D ELETE FROM c lo w n _ in f o
WHERE
a c t i v i t i e s = ' ,
AND nam e = ' ' ;

WHERE.

'


WHERE.

.
nam e

ia *l_ se e n

a ppearance

a c liv ilie s

, ,
,

169

- ^
INSERT DELETE

d r in k i n f .
.

d r in k

in f o

4 _

cesi

carba

lo r

U*

8.4

33

2.5

3,2

12

3.5

8.6

35

2.5

5.4

24

5.5

42.5

171

3.2

32.1

135

3.6

4.2

17

14

50

2.8

7.2

30

2.6

21.5

80

3.8

4.7

19

170.

170

de le te up d a te

drinkjnfo
<_

cost

carbs

color

calories

-v.
?
____

_________

__ >

, $2.50,
$3.50, $3.50 $4.50.

171

- ^

I N S E R T D E L E T E
d r i n k _ i n f o .
.

d r in k i n f o
4 _ *

cesf

carbs

c l r

ice

ca le rie s

8.4

33

2.5

3.2

12

3.5

8.6

2.5

5.4

5.5

42.5

3.2

32,1

3.6

4.2

14

2.8

7.2

2.6

21.5

3.8

4.7

170.

INSERT INTO d r in k jn fo VALUES ('', S .S , 4.5-,


''J ''^ 1 7 0 ) ;
DELETE FROM d r in k jn fo WHERE calories - 1 7 1 ;

INSERT INTO d r in k jn fo
VALUES ('', 3, 8 .4 , ' ', ' , 3 3 ) ,
('', 4 , 1 4 , ' ', '',, SO):
DELETE FROM d r in k jn fo WHERE color = '';

172

35
24
171
135
17
50
30
80

19

de le te up date

dnnkjnfo
dr^nk_name

carbs

cost
3

8.4
3.2
8.6
5.4
4Z .S
3 2 .1
4.2
14
7.2
2 1 .5
4.7

3.5
4.5
3.5
5.5
3.2.
3.6
4
2..S
2.6
3.8

X
TK .

7 .

color

calories
33

12
35
24
170
135
17
50
30
20
19

, .
To ii' ^ o

HO

ice

i^ .S O

^ '^0^ $3.SO


^.

^
. . . ,
( $ 3 . 5 0 H S O )

(
^ - $ z . s o $ 3 .s o ) .

, $2.50,
$3.50, $3.50 $4.50.

INSERT INTO d r in k jn fo VALUES ([ ', 4 .5 , 8 ,6 ,


'', ' ', 3 S );
DELETE FROM d r in k jn fo WHERE cost = 3,5-;
INSERT INTO d r in k jn fo VALUES (' ', 3 .5 , . , '',, 'Y', 1 ).
(' ', 3 .5 , 5 .4 , '', ' , 2 4 ) ;
DELETE FROM 'd rin k jn fo '\1^ cost = 'z. 's; .................................................
, i n s e r t !

>

173

DELETE
DELETE
,
. ,
;


INSERT
.


DELETE.
,
WHERE

.

^ IN S E R T IN T O c lo w n _ in f o
VALUES
( ' 1 ' ,
' ' ,
' , ,
, ' ,
' ') ;
nam e

1>1_>

a ppearance

a c liv ilie s

, , ,

, , ,

, ,

, , ,

, , ,

, , ,

, ,

, - ,

, ,

, ,

, - ,

, , ,

DELET3

1 1

, , ,

DELETE.
174

d e le te u p d a te

jj

cefuu ])n , U l ;

*
clown_mC> takle <3nj>aHuUe.
, ,
1<> ^*.

DELETE FROM clow n i n f o

]^ / , .

VIHERE last seen = ' ' ;

WHERE activities = '';

WHERE last_seen = ' '


AND name = ' ';

WHERE last_seen = ' ' AND


last_seen = ' ';

WHERE last_seen = ' ' OR


last_seen = ' ';

WHERE name = ' '


OR last seen = ' ';

menefb

175

DELETE,

]| ^ W UEfiE

)][J

. Qm^eiii

]) ,11. 1

clov^i_> taUe
. , , 1 1^^*.

^ ? ----- , .

DELETE FROM clovm_info

^ > .

WHERE last_seen = ' ';

.^ 9 ? .

.......


.
WHERE activities = '';

,
, _ . .................................

WHERE last_seen = ' '


AND name = 'Mr. H o b o ';

AND , o5a
.

V WHERE last_seen = '; '


AND last seen = ' ';

WHERE last_seen = ' '


OR last_seen = ' ';

WHERE name = ' '


OR last seen = ' ';

.... .^.?.. ...........................................


.
,
, ,
.

ELETE FROM clow njnfo

WHERE n a m e = '

AND last_seen <> ' ';

176

d e le te up d a te

, -
? ,
SELECT
,
WHERE.

!
,
1
,
SELECT.

WHERE, SELECT
, DELETE
WHERE.

,
,
.

- >

177

DELETE
DELETE .
' ,
; .
; INSERT-DELETE
.
:


,
SELECT.

^ S E L E C T .
, ,
.

SELECT FROM c lo v m _ in f o
WHERE
a c t iv it ie s = ' ';

1^.

1 '^

a ppearance

a c tiv itie s

, ,

INSERT.

(?

,,
Komoptiii

IN S E R T IN T O c lo w n _ in f o
I, m b.
VALUES
( ' , ' ' ,
' , , ' ,
' ,

/
178

la s t.s e e n

appearance

, ,

[ |^ , , !

' );

a c tiv itie s

de le te a up date

, DELETE
WHERE, SELECT
.

D ELETE FROM c lo w n _ in f o
WHERE
^
a c t i v i t i e s = ' ;


HERE

( 1 )

.

c tiv ilie *

, ,

.
*

ia s l_ s *c n

* *

a c tlv ili*

, ,

Q.

,

, ,

... ,
...

179

UPDATE

UPDATE
, INSERT DELETE,
.
.
,
, ,
.
SQ L UPDATE. (
) . SELECT DELETE,
( ) WHERE.
UPDATE:

UPDATE d o u g h n u t _ r a t in g s

SET

.

U 6 -

SE L E C T

' '

WHERE t y p e

PE LE T E .

' ';

SET , ,
=, , =.
type ' '.
WHERE , , type
' '.

d o u g h n u t _ r a t in g s
locotien

tiM

dat*

lyp

cemment*

Krispy King

8:50

27/9

10

Duncan's Donuts

8:59

25/8

NULL

Starbuzz Coffee

19:35

24/5

Duncans Donuts

19:03

26/4

\ ^|?

d o u g h n u t _ r a t in g s

180

location

time

date

type

rating

commeiits

Krispy King

8:50

27/9

10

Duncan's Donuts

8:59

25/8

NULL

Starbuzz Coffee

19:35

24/5

Duncan's Donuts

19:03

26/4

delete update

UPDATE
u p d a te
.
=
SET :
UPDATE your_table
SET _= '_ ',
_ = '_';

u p d a te
w here.

BoTjJbC bi
, WHERE ?

, SET,
.

SQL
=, .
?

. = SET
, = WHERE
, ,
.

, . .
,
, ,
,
Krispy King.

,
?

DELETE,
, WHERE
SELECT!

SET?

?

yj , .
SET, .

UPDATE doughnut_ratings SET type = '


' WHERE location = 'Krispy King';

>

181

INSERhVELETE

UPDATE INSERT-DELETE
UPDATE .
.

UKU
S T -

,
. '\.
.

..- ,
.

UPDATE table_name
SET ^ = __
WHERE __ = ^;

WHERE ,
^

' , )1 clown in fo .

''
>''^
. '
'.

,.:

182

UPDATE

INSERT/DELETE.


1^ clown info

UPDATE cl0wn__inf0
SET last__seen = '
WHERE name =
AND last seen = ;

delete update

UPDATE e
UPDATE
l a s t _ s e e n (' ')
' '.

U P D A T E c l o w n info
t :
SET l a s t _ s e e n = '
W H E R E n a m e = ' '
A N D l a s t _ s e e n = ' ' ;

name

last seen

appearanc*

aclivilies

, , ,

, , ,

, ,

BG

, , ,

, , ,

, , ,

, ,

, - ,

1^ _, (^

(
- ).
>

184

delete update

tame

11_

appearance

activities

, , ,

, , ,

, , ,

, , ,

, , ,

, - ,

name

^st_seen

appearance

, , , ,

., ,
,

, ,
,

, , ,

activities

185

- ^

"


.
UPDATE (
, ). ,
UPDATE.

..... .....................................................U,
W HERE

name

= '':

............................................................> 3 cmoAi-
.....................................................

SET appearance = . ,
'
WHERE = 'Snuggles';

^
.

.{J.FPATE . {ownJnfo
WHERE = '';

p!p.yy.4)Ji^fp.

- .

186

SET activities = ' '


WHERE = '';

UPDATE clownjnfo
SET last_seen = ' ^? '
WHERE = ' ';

delete update

na m e

la s t se e n

a p p e a ra n c e

a c tiv itie s

, , ,

, , ,

, ,

BG

, , ,

, , ,

, , ,

, ,

, - ,

1^'\

1$_$

, , , ,

, ,
,

, ,(

, , ,

, ,
,

, , ,

, ,

!^

, - , j

V & ^

( ^
^
_______ _

appearance

activities

^ "^

UPDATE. - . 1 5 5 .

>

187

UPDATE


, d r i n k i n f ?
$2.50 $3.50, $3.50 $4.50.

drink info
4 _

COSI

c a rb s

c o lo r

c a lo rie s

8.4

33

2.5

3.2

12

3.5

8.6

35

2.5

5.4

24

5,5

42.5

171

3.2

32.1

135

4.2

17

14

50

2.8

7.2

30

2.6

21.5

3.8

4.7

80
19

?
UPDATE
UPDATE :

UPDATE drink_info . $!
SET cost = 3.5
WHERE drink^name = ;
Z '

WHERE

.

188

delete update

189

UPDATE
c o s t . SQL
. , c o s t
1 , .
:

UPDATE drink_info
SET cost = cost + 1 ;
WHERE

1
,

( $ZSO $ 3 . 50 )-

drink_name=' '
OR
drink_name=' '
OR
drink name= ' '
'
'^

1>1

? ?

yj- , ,
.
,
, 1.


,
?

! .
,

.

. ,
,

UPDATE

.

190

? .

,
UPPER ()

. LOWER (),
,

UPDATE

.



.

delete update

,
. ,

.

,
.

,
.


.
?

.

191

sq l


3 .

SQL,
.
III.

DELETE

^
.
WHERE

.

SET

I ,

192

::: 3

]=*] ^


. ;
,
UPDATE.

S E L E C T , IN S E R T , D E L E T E

,

.

w here



.
, , .
, , .

^/^. fis h

in fo

F,sk r e c o r d ,

species

111

w eiglil

. salmoides

, 6

22 4

S. vitreus

25 0

0 . Clarki

41 0

P. Flavescens

, N1

4 3

L.Macrochirus

, 1

4 12

L. Osseus

50 5

5 3

P. annularis

, 5

E. americanus

, 1

1 0

C. auratus

6 10

0 . Tshawytscha

97 4

,

,
.

194

<^
^^ .
_____


,
, :
.

fis h



,
.

re c o rd s

1_

11_

111

sla t*

weight

date

GA

22 4

2 /6 /1 9 3 2

TN

25

2 /8 /1 9 6 0

NV

41 0

1/12/1925

..

NJ

4 3

1/5/1865

..

AL

4 12

9 /4 /1 9 5 0

50 5

3 0 /7 /1 9 5 4

MS

5 3

31/7/1957

IN

1 0

9 /6 /1 9 9 0

CA

6 10

17/4/1996

AK

97 4

17/5/1985 /

,
-.

195

- ^Jomvi

,
-.


.

.

,

LIKE.
SELEC T * FROM fishjnfo
WHERE location LIKE '7oNJ;

common

species

iocatien

w eiglil

p. Flavescens

, NJ

4 3

state.
SELECT


,


.

FROM fisi^_records

WHERE state = 'N J';

196

firsl name

iasl_name

common

iocalien

stale

weigiit

d ale

C.C.

NJ

4 3

1/5/1865

- ------------- !
, ,
?

.
.
,
(
) .

, .


.
, .

,

.
,

.


LIK E ?
?

LIKE
,

.
, LIKE

.

,

?

0:

.
,
.

,
.

,
-,
.

,
.


?

0:



, ,

,
.

UPDATE
,

.

,
,.


,

.

3 0 1 ,
. ,

5 0 1 ?

197


SQL
(). ,
*. ,
, : ,
,
.
,
.
, ,
,
.

t :r

1. ,
.

2. ,

.

3. ,

,
^

.

'^ .

* ,
. .

198

,
?
.

. ,
,
.
.

199

,
?
.

..----------

. ,
,
.
.

200


? ,
?

.

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

,

8 0 1 ?

>

201


? , ( )
. :
,
.

30 ,
,
. ,

.
:
.
,

1 ,
.

<

File Edit Window Help SimplePizzaFactoty

o rd e r number 1 address
1 59 N. A jax Rapids
1 849 SQL S t r e e t
1 2348 E. PMP P laza
1 1978 HTML H eights
1 24 S. S e r v le ts Springs
1 807 I n f i n i t e C ir c le
1 32 Design P a tte rn s P laza
i 9208 S . Jav a Ranch
1 4653 W. EJB E s ta te
1 8678 OOA&D Orchard
-+
> SELECT address FROM p iz z a d e l iv e r ie s WHERE o rd er num = 2 5 2 ;
246
247
248
249
250
251
252
253
254
255

address
32 Design P a tte rn s Plaza
1 row in s e t ( 0 . 0 4 sec)

202



. ,

,

.
.
.-

HOUSE

) ,
.
,
,
.

FOR SALE
BY

APP O IN TM E N T ONLY

V
I File Edil Window Help IWanlMyCommission

s tre e t_ n u m b e r
59
849
2348

'

^ ^

-+
1 s tre e t_ n a m e
I p ro p e r ty _ ty p e 1 p r ic e
-+ ------------------------------------------------- _ + ------------------------+ ------------1 N. A ja x R a p i d s

1 condo

1 SQL S t r e e t
1 E . PMP P l a z a
1 HTML H e i g h t s

1
1
1
1
1

1 189000
1 109000
1 355000
1978
1 134000
24
1 S . S e r v l e t s S p rin g s
1 355000
807
1 I n f in it e C ir c le
1 143900
32
1 D e s ig n P a t t e r n s P l a z a
1 h o u se
1 465000
9208
1 S . J a v a R an ch
1 h o u se
1 699000
4653
i SQL S t r e e t
1 a p a rtm e n t
1 115000
8678
1 OOA&D O r c h a r d
1 h o u se
1 355000
.+------------------------------------ _+------------------------+> SELECT p r i c e , p r o p e r t y _ t y p e FROM r e a l _ e s t a t e WHERE s t r e e t nam e =
I p r ic e

I p ro p e r ty _ ty p e

I 1 0 9 0 0 0 .0 0
I 1 1 5 0 0 0 .0 0

'S Q L S t r e e t '

I a p a rtm e n t |
I a p a rtm e n t 1

+
2 ro w s i n

a p a rtm e n t
h o u se
a p a rtm e n t
h o u se
condo

+ ----------------------set

(0.01

sec)

203


,
, .

1 .
?

2.


: , ,
, ?


,
!

3.

1)1

5:.

, ? ,
?

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

204

, :

,
.

- ^ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.
, .

1. , ,
.
, interests
my_contacts
.

2.
.

d jn irU ie >

205


'


.
, .

1. , ,
.

,
, :

<^0 ^^ ^
^^^ !

ingredients

fooO am e

, , , gpoMu,

, , ^

:
,

!
-^
.

2.
.
' -

1^ !

tr
teacher

studenti

___ ----- --------------- \------------_____


^ u cm ep

206

student2

'

^ Students

^ (
4

, , , , ,
( ) .

, . 83

, . 112

, . 155

, . 93

, . 194

>

207


,
SQL.
,
, .
,
,
. ,

!

, , , , ,
( ) .

, . 83

^<seeking>> ...........

, . 112 . easy_dn'nksj
<<acti'^ip'es>>
.

, . 155

^^^

. activities
" " )< 61<1 '1
^ ^^ 1..........................................................................................

, . 93

.
' ', ' ...........
Z. .........................................................................

, . 194 .
, 6

......................................................................... ^ . .........................................................

208

1.
,
.

2. ,
,
.


.

?


.

.
,
,
,
.

>

209


?

,
, a p p earan ce a c t i v i t i e s
.
.

c l o w n info



(7 -

!

nam e

1 1_

a p p e a ra n c e

1|1 *

, , ,

, , ,

, , ,

, , ,

, , ,

, ,

, - ,

^
. ,
ap p earan ce a c t i v i t i e s ,
l a s t seen.
.

GX1
GXI

210

1
, .

, .
, , .

IV!&,
.



,


.


,

.

,

?


,
, .

,
,
.


,
.

.



.
,
.
; ,

?
(

11_
()



;

.

8 .

1_
()

_
()

; .

' 1 , 8 ,

. . ... -


> 1

,

. , .
, 100%?

.

212


NULL
N U L L
,

N U L L .




N U L L ,
.


,
, .




,
.
,
.


?
, .
- , ?

213

,
,
, NULL
?


.
, ,
, .
, oopil ,
.

().
10,
, .
10 .
.

id

ia s t_ iia in

ffirs l_ iia m e

n ic k _ n a m e

5 , 1

,

5.

Jiff 15 1

SQL
( ,
1 0 ) ,
( ,
. .).
; 7
.

214


1|1

. , ? ?

! ,
;
.
7.

,
. -
1?

coInments
.
, ,

. ,


,
. ,

.



.
.
C R E A T E T A B L E .

UJTVPM
A ,
?

215


,
.

, 1.
SELECT - .
, 2.
.
, 3.
,
1 .
.

, .
, DROP TABLE,
1, ,
?

, .
.
:
.

,
.
...

216

CREATE TABLE
.
,
,
. ,
, , !
1.

CREATE TABLE my_contacts

^.

last_name VARCHAR(30),
first_name VARCHAR(20)
email VARCHAR(50),
gender CHAR(l),
birthday DATE,
profession VARCHAR(50)
location VARCHAR(50),
status VARCHAR(20),
interests VARCHAR(100)
seeking VARCHAR(100)

^ AU

c r e a t e t a b l e
? ?

217

CREATE

noka)ku <
,
D E S C R I B E m y c o n t a c t s ?
:

File Edit Window Help GregsListAgain

+----------------- .+--------------------------+ -----------+--------- +---------------- +-----------I Coluunn

I Type

I Null I Key I D efau lt I E x tra

+--------------------

1 YES 1
1 NULL
1 last_nam e
1 v a rc h a r(3 0 )
1 NULL
1 f i r s t name i v a rc h a r(2 0 )
1 YES 1
1 YES 1
1 NULL
1 email
1 v a rc h a r(5 0 )
1 gender
1 ch a r(l)
1 YES 1
1 NULL
1 YES 1
1 NULL
1 b irth d a y
1 d ate
1 p ro fe s s io n 1 varchar(SO )
1 NULL
1 YES 1
j lo c a tio n
1 v a rc h a r(5 0 )
1 YES 1
1 NULL
1 NULL
1 s ta tu s
1 v a rc h a r(2 0 )
1 YES 1
1 in te re s ts
1 varchar(lO O ) 1 YES i
1 NULL
1 seeking
1 varchar(lO O ) 1 YES 1
1 NULL
+------------------ .+ --------------------- -+----------+------- +----------- +

Ho CREATE, a .
, ,
.
SHOW CREATE_TABLE CREATE TABLE,
(
). :

SHOW CREATE TABLE my_contacts;

218


, . 217,
SHOW CREATE
TABLE m y _ c o n ta c ts . ,
CREATE TABLE, . 1
, ,
.


CREATE

'm y _ c o n t a c t s '

CREATE TABLE

(
la s t_ n a m e '

v a rc h a r(3 0 )

f ir s t_ _ N a m e '
e m a il'

c h a r ( l)

b ir th d a y '

d a te

p r o fe s s io n '
lo c a tio n '
s ta tu s '

s e e k in g '

d e fa u lt
d e fa u lt

E N G IN E = M y IS A M

d e fa u lt

d e fa u lt

v a r c h a r ( lO O )

DEFAU LT

N U LL,

N U LL,

d e fa u lt

v a r c h a r ( lO O )

N U LL,

N U LL,

v a rc h a r(5 0 )

v a rc h a r(2 0 )

N U LL,

d e fa u lt

d e fa u lt

v a rc h a r(5 0 )

in te r e s t s '

v a rc h a r(2 0 )

v a rc h a r(5 0 )

g e n d e r'

d e fa u lt

N U LL,

SQL ,


NULL (

).



,

NULL.

N U LL,

N U LL,

d e fa u lt

d e fa u lt

N U LL,

N U LL,

C H A R S E T = c p l2 5 1

T
He
, .


.

.
: '.^
.


,
^ .
>

219

CREATE TABLE

CREATE TABLE
, SHOW
CREATE TABLE.
.
c o n t a c t i d NOT NULL,
PRIMARY KEY,
c o n t a c t _ i c i .

CREATE TABLE my_contacts

(
^

c o n ta c t_ id
la s t_ n a m e


contact_
id,

.



,

.

IN T

c h a r ( l)

b ir th d a y

d a te

p r o fe s s io n
lo c a tio n
s ta tu s

s g te J fe irn g

d e fa u lt

v a rc h a r(2 0 )

NULL,

NULL,
d e fa u lt

d e fa u lt

d e fa u lt

v a r c h a r ( lO O )

NULL,

NULL,

NULL,

d e fa u lt

NULL,

v a r c h a r ( j r ^ O L j u ^ ^ g g a u l t NULL,
( c o n ta c t_ ld M


.
:
PRIMARY K EY

,

contact id.

220

NULL,

NULL,

v a rc h a r(5 0 )

(m iM M C K E Y

d e fa u lt

NULL,

d e fa u lt

d e fa u lt

v a rc h a r(5 0 )

in te r e s t s

d e fa u lt

v a rc h a r(2 0 )

v a rc h a r(5 0 )

g e n d e r

N U LL,

v a rc h a r(3 0 )

f ir s t_ n a m e
e m a il

NOT

, 5,

N U L L !
NULL




.

1^1
,
NULL.
?

! .
c o n ta c t _ id
. , INSERT
c o n ta c t i d 1,
2 .

PRIMARY

.
,
.
:
SHOW WARNINGS;
,
SQL
,
SHOW WARNINGS.
SHOW.
,
.

KEY
. ?

.

. ,
(, ,
).
,
,
, c o n ta c t _ id .


( ).

SHOW,
CREATE?

SHOW
:
SHOW COLUMNS FROM ta b le n a m e ;

, ,
.
SHOW CREATE DATABASE databasenam e;
SHOW CREATE <>,
.
SHOW INDEX FROM ta b le n a m e ;


SHOW CREATE TABLE? ,
?

,

. ,
,
SQL
( ).
, -
s e le c t.
:
s e le c t v a rc h a r (5 0 )
:
' s e l e c t ' v a rc h a r(5 0 )

, . ,

,
. , s e le c t
: ,
.

221

AUTO INCREM ENT

1, 2, 3 u

:
SQL

A U TO JN CREM EN T
( M S SQL

CREATE TA B LE m y _ c o n ta c ts
INPEX

(
- c o n ta c t id
I N T N O T N U L L A U T O I N C R E M E N T ,
6,
la s t_ n a m G v a r c h a r ( 3 0 )
d e fa u lt N U LL,

fir s t_ n a m e v a r c h a r ( 2 0 )
d e fa u lt N U LL,
M S SQL).

c o n t a c t i d
AUTO INCREMENT,
: 1 1, 2 2 . .

e m a il

v a rc h a r(5 0 )

g e n d e r

c h a r ( l)

b ir th d a y

d a te

p r o f e s s io n
lo c a tio n
s ta tu s

d e fa u lt

d e fa u lt
d e fa u lt

v a rc h a r(2 0 )

in te r e s ts

N U LL,
N U LL,

v a rc h a r(5 0 )

v a rc h a r(B O )

NU LL,

d e fa u lt

d e fa u lt

d e fa u lt

v a r c h a r ( lO O )

N U LL,

NU LL,

d e fa u lt

s e e k in g

v a r c h a r ( lO O )

d e fa u lt

P R IM A R Y

KEY

id )

(c o n ta c t

N U LL,

N U LL,

N U LL,




1 .

1.

.

.

INSERT,
?
?

, ?
.

222

create t a b l e ,
.
AUTO_iNCREMENT .

2 - SQL ,
CREATE TABLE.


, .
IN S E R T

IN T O

y o u r_ ta b le

VALUES (N U LL,

IN S E R T

IN T O

VALUES (1 ,

IN S E R T

IN T O

VALUES

( ' ' ,

IN S E R T

IN T O

VALUES

y o u r_ ta b le
' ',

IN T O

VALUES

(9 9 ,

firs t_ n a m e ,

la s t_ n a m e )

' ') ;

(id ,

firs t_ n a m e ,

la s t_ n a m e )

' ') ;

y o u r_ ta b le
' ',

y o u r_ ta b le

( ' ',

IN S E R T

(id ,

' ',

in s e r t .

' ') ;

(firs t_ n a m e ,

la s t_ n a m e )

' ') ;

y o u r_ ta b le
' ',

(id ,

firs t_ n a m e ,

la s t_ n a m e )

' ') ;

? ,
in s e r t .

your_tabie
id

First_name

last_name

>

223

create t a b l e ,
.
AUTO INCREMENT .

CREATE TABLE your_table


(
id INT NOT NULL AUTOJNCREM ENT,
fin t _ n a m e VARCHAR(ZO),
iast_name V A R C H A R (3 0 ),
PRIMARY KEY (id)
);
2* SQL ,
CREATE TABLE.


, .
IN S E R T
siA LU E S

IN T O

IN S E R T

IN T O

VALUES

(1 ,

IN S E R T

V ^^^U E S

IN S E R T
ALUES

y o u r_ ta b le

(N U L L ,

IN T O
( ' ' ,

IN T O

y o u r_ ta b le
' ',

IN T O

w w jjE s

fq q ,

firs t_ n a m e ,

la s t_ n a m e )

' ') ;

(id ,

firs t_ n a m e ,

la s t_ n a m e )

' ') ;

y o u r_ ta b le
' ',

' ') ^

y o u r_ ta b Ie

( ' ',

JNSERT

(id ,

' ',

in s e r t .

(firs t_ n a m e ,

la s t^ n a rm

' ') ;

y o u r _ L d b i f tt7
' ',

Iirs t_ n a m e ,

la s t_ n a m e

' ' ) ; ____________________________

p a 5omae.w\j
!^

? ,
in s e r t .

Ljourjtahie

224

id

first_name

last_name

,
,

,
!

--------- -------------------.

) 1

( NULL id )
, id NOT NOLL?


, AUTO_INCREMENT NULL
. , AUTO_INCREMENT
, .
.

, . ,
SHOW CREATE TABLE,
,
,
.


;
ALTER.
,
.
.
ALTER
,
5.

225

6 ^
AUTO INCREMENT
m y _ c o n ta c ts . ( ,
.)

5 Q

^ Q

S ^5 5I
Y
f

U 5

'^1

03
4J


I 03

m
(D 03

VO

m S ^.
X

J3

S
Q.
)
m
R

(U

S m
- ^

S i*;

03

Ct

J]

0Q

J3 X
m m
:

226

ALTER TABLE u
, . SQL,
U S E g r e g s _ l i s t
:
E d w J n d W Help A it^rtin

> ALTER TABLE m y_contacts


- > ADD COLUMN c o n ta c t_ id INT NOT NULL AUTO_INCREMENT FIRST,
- > ADD PRIMARY KEY (c o n ta c t i d ) ;

,


5 0 ,

.

.

Query OK, 50 rows a f f e c t e d ( 0 . 0 4 sec)


R ecord s: 50 D u p lic a te s : 0 W arnings: 0

!
, .
ALTER TABLE
?

c o n t a c t jd

,

File Edit
.

CO

,
,
SELECT * from my_contacts;

Window Help Alterations

1 c o n ta c t_ id 1 last_nam e
, 1_ _

1 first_n am e 1 em ail

1
1
1
1
1

1
1
1
1
1

r
1

1
2
3
4
5

1
1
1
1
1


c o ^ t a c t M Sydem ^p uceo m o

tLl

^' , ^
2 3
2 4 .
'
^

j
1
1
1
1

jill_anderson@ yahoo 1
j 0 s imuduck. com
aman21uv0yahoo.com
ed990mysoftware.com
jojo@yahoo.com
k.

H^^0u,

5^
^ c t j d 0 co n tactjd

.
;
.

? 5.
*

227

s q t


4.
,
!
III.

^ '
.

" "' ;<. -

- : ^

08-

I
!

create

* =

ta b le


,

.

I ,
^ .

, '' -w c r a w a w

/ ^ ^. p

^^^

228

;:/; 4

^^

. ,
a p p e a r a n c e a c t i v i t i e s ,
l a s t s e e n .
.

,

, , ,
, , ,
( / ), ( / )?
( / ) . .

,

, !

229


? , .
A L TE R ,
, . ,
!
, ,
, .

)
,
, .

, -

?

,
ALTER TABLE.
, ,
,

ALTER. ,
,
!

232

ALTER

ALTE R TABLE,
4.
ALTER TABLE
10 ? ,

.

ALTER TABLE my_contacts


ADD COLUMN contact_id INT NOT NULL AUTO_INCREMENT FIRST,
ADD PRIMARY KEY

(contact i d ) ;

ALTER TABLE:


AFTER. , ,
f i r s t name.
ALTER TABLE:

>

233

- ^
ALTER TABLE,
4.
ALTER TABLE
10 ? ,

.

ALTER TABLE my_contacts


ADD COLUMN contact_id INT NOT NULL AUTO_INCREMENT FIRST,
ADD PRIMARY KEY

(contact_id) ;

NOT NULL,
A U TO JN CREM EN T FIRST
.

ALTE R TABLE:

, ,
my_contacts.

................................................V ...................................................
............................................................................................. ,

APD COLUP^N pkone VARCHAR(IO);


..............

^
..................................... ................................................. -

^ ^ - ^

ALTER

.
-

^
.


AFTER. , ,
f i r s t _ n a m e .
ALTER TABLE:

ALTER TABLE my_contacts


A P P COLUMN p^one, y A R C H A R C lO )

AFTER first_name;
................... j ............. ^

........................................................

AFTER
. ,
51 ^.

234

AFTER <5 ^
- 7
.
^ .

ALTER

FIRST AFTER

BEFORE LAST.
SECOND, THIRD .


p h o n e
. ,
.
BEFORE MySQL ; F IR S T AFTER.

phene
a lt e r

ADD

centactJii

ADD

TABLE

centact_ld

ADD

TABLE

centact id

ADD

email

liiiene

VAR C H AR (1 0 )
last name

first name

VAR C H AR (1 0 )
phene

1 last_name

first_name

email

m y _ c o n ta c ts

C O LU M N p h o n e

ALTER

m ail

m y _ c o n ta c ts

C O LU M N p h o n e

ALTER

first name

TA BLE m y _ c o n ta c ts

C O LU M N p h o n e

ALTER

last name

contact id

VAR C H AR (1 0 )
last name

phene

firstn am e

email

TA BLE m y _ c o n ta c ts

CO LU M N p h o n e

VAR C H AR (1 0 )

'


,
.

;
, .

235

^
phone
. ,
.
BEFORE MySQL ; F IR S T AFTER.

F fR S T
phone

6,.

ALTER TABLE m y _ co n ta cts


ADD COLUMN phone VARCHAR ( 1 0 ) |
phoa*

CMtMct id

lal nam* I ffini nam*

m ail

ALTER TABLE m y _ co n ta cts


ADD COLUMN phone VARCHAR ( 1 0 )

f LAST


L A S T ,
p ho n e
.


FIFTH
.

|~T~|

ALTER TABLE n ^ _ c o n ta c ts
ADD COLUMN phone VARCHAR( 1 0 ) L
ALTER TABLE m y _ co n ta cts
ADD COLUMN phone VARCHAR(10)
cnlacl id

Iasi

first n

m ail

phene

ALTER TABLE iiQ r_contacts


ADD COLUMN phone VARCHAR (10)
ALTER TABLE in y _ co n ta cts
ADD COLUMN phone VARCHAR(10)

BKFORE
cntact_id

_name

phen^

J
| last_nam^ | first_nam^

ALTER TABLE n iy _ co n ta cts


ADD COLUMN phone VARCHAR(10)

phan^

236


SECOND
p h o n e
;



BEFORE (
last_name).

m ail

A F T E R last_name
phone
.
THIRD,
.
first.nam a

m ail

ALTER


ALTER




.
:



.

Dataville Alterations
:

CHANGE

- *

MO 0 IDY

- ^

ADD

- (

DROP-


,
.

* ,
.


( ADD)

Projekts
nw m ber
1

OculhiUe

237


!


!

,
.

'


,


.

/
1
^


^

0.(1/'1

Projekts
num ber

18| |11 {

c o n lra c te r o n fo b


,
.
.

DESCRIBE
, .
,
.

I File

Edit Window Help BadtablePesign

> D E SC R IBE P r o j e k t s ;

+------------------------------+-------------------- +--------- +--------+--------------+---------- +


I F ie ld

1 Type

I Null i Key I D efau lt | E x tr a |

+------------------------------+-------------------- +--------- +------- +-------------- +-----------+


I number
I int(ll)
I d e s c rip tio n o fp ro j I v a rc h a r(5 0 )
I co n tra cto ro n jo b
| v a rch ar(lO )
3 rows in s e t ( 0 . 0 1 sec)

238

I YES
| YES
| YES

|
|
|

I NULL
I NULL
I NULL

|
|
|

|
|
|

ALTER


,
A L T E R
.
A L T E R T A B L E .
p ro jek ts
.

ALTER
RENAM E

TA B LE
TO

p r o je k ts

p r o je c t_ lis t;

------/

13

P ^ o je c t _ li5 t - ,

.

?
,
.


.
, , ,
- .

239

?
,
.

^ .
( ,
5

,

.
,

.

con^name \

^ ,
^ ^ \ ^ ^
. < ^
(^ <31 ^
(^ '^ ^ - ^ ^

___________ J

est cost \

startjate \
con^phone I

240

ALTER


project_list
n um ber

4 < 1 11 1 |

c e n tra c le re n ie b

.
,
RENAME.

.

241


, .
ALTER
:
[>=>> number pro j_id
d e s c r ip t i o n o f p r o j
pro j_desc
c o n tr a c to r o n j ob
- con_name
e s t _ c o s t ,
con phone s t a r t d ate.

\j-'deiC p ro
projeCt_list j
n um ber

d escri p lio n o fp r !

5,
p ro jjd .

.

c o n lra c le ro n io b

fc orn .
x z
project_list

p re L W

242

- j . ni ab

p ro L d e s c

con_name

ttr

ALTER



,
. ,
.
.

I File Edit Window Help BadTableDesIgn

> D E SC R IBE p r o j e k t s ;

+------------------------------+-------------------- +--------- +--------+--------------+-----------+


I F ie ld

I Type

I N u ll

I K ey

I D e fa u lt

| E x tra

I num ber
I d e s c r ip tio n o fp r o j
I c o n t r a c t o r o n jo b

I in t(ll)
I v a rc h a r(S O )
| v a r c h a r (lO )

I YES
| YES
| YES

|
|
|

| NULL
| NULL
1 NULL

|
I
|

|
|
|

3 ro w s i n

sec)

+------------------------------+-------------------- +--------- +--------+--------------+-----------+

+------------------------------+-------------------- +--------- +------- +--------------+-----------+


set

(0.01

iTVPM
,
,
.

243

ALTER CHANGE

ALTER u CHANGE
Ha number p ro j _ i d
AUTO INCREMENT.
. , .
, .
CHANCE
COLUMN,
,
,
(
n u m b er.

,


.
)

ALTER TABLE project_list

p r o j j d
,

.




,
NULL.

CHANGE COLUMN proj_id INT NOT NULL AUTO_INCREMENT,


ADD PRIMARY KEY

('proj_id') ;

5
p r o jjd
.

^^ - - - - - - - - - - - - - - ^- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - .

I/O
GX1

244

ALTER

SQL
, .
d e s c r ip t i o n o f p r o j c o n t r a c t o r o n jo b
. ,
ALTER TABLE CHANGE COLUMN, .

^^^^scriptionofproi ^ ,

.

A LTER TABLE p r o j e c t _ l i s t

p roj^ desc

...


,



.

CHANGE COLUMN d e s c r i p t i o n o f p r o j p r o j _ d e s c VARCHAR( 1 0 0 ) ,


CHANGE COLUMN c o n t r a c t o r o n j o b

T

,
co n tra cto ro n jo b ,
, --

con__name VARCHAR( 3 0 ) ;
/'

... _ ,
.

...


.
,
, .

, ,

.
, ^) (1)
' '.
. ,
,
!

245

MODIFY

(,
),
, ? :
ALTER TABLE
CHANGE COLUMN myColumn myColumn NEWTYPE;

, ,
.
MODIFY.
,
.
,
pro j des
VARCHAR (120 ). :

A LTER TABLE p r o j e c t _ l i s t
M O D IF Y COLUMN p r o j _ d e s c VARCHAR( 1 2 0 ) ;
1_

,

!

'=
1]1
?
5
:^

: ALTER TABLE MODIFY COLUMN


p ro j_ d e s c AFTER con_name;
'

0:

^ ,
. ,
,
.


5 :'
I
?

0:

I , SELECT
. ,
;
:

SELECT columns, columnl FROM your_table;


:

SELECT columnl, column3 FROM your_table;


.

246

ALTER


.

, ?

p r o je c t_ lis t
p re iJ d

proi_d*8c

con_nam

1
2
3

, .
alter table , ;
.

p r o je c t_ lis t

247

/
'


.

, ?

p r o je c t_ lis t
p ro i_ id

pro|_<ies<

_ *

1
2
3

, .
alte r t a b le , ;
.

ALTER TABLE projectjtabie

J/

COLUMN con_phone VARCHAR(IO),



,

^
-

A P P COLUMN start^date PATE.


A P P COLUMN est_coSt PECIM AL(7,Z):

,
PEC 7 ,
Z .

p r o je c t_ lis t
p r U < i
1
2
3

248

proj_dl*sc

cen^nam e

con _ p h o n *

le rl_ d e t*

e t.c e !

ALTER

!
!
,
.
s t a r t _ d a t e .

,
.

,
. ,
.
,
ALTER.
,


. ,
,

.


501 s t a r t _ d a t e .
,
.

>

249

- |^

501 s t a r t _ d a t e .
,
.

ALTER TABLE projectJable


DROP COLUMN startjate;

PR O P. ,
'.

)6

,
, !


DROP COLUMN. ,
,
, ,
!
,
.

o C u io J b ^ K H b il

250

ALTER


,
. ,
!

,
alter
. ,
. ?
,

ALTER TABLE.

h o o p t ie
color

year

m ake

mo

how m uch

1998

Porsche

Boxter

17992.540

NULL

2000

Jaguar

XJ

15995

2002

Cadillac

Escalade

40215.9

c a r ta b le
c a r jd

VIN

m ake

m odel

co lo r

year

p rice

RNKLK66N33G213481

Porsche

Boxter

1998

17992.54

SAEDA44B175B04113

Jaguar

XJ

NULL

2000

15995.00

3GYEK63NT2G280668

Cadillac

Escalade

2002

40215.90

251


,
. ,
!

,
alter
. ,
. ?
,

ALTER TABLE.

hooptie
co lo r

mo

howmwch

1998

Porsche

Boxter

17992.540

NULL

2000

Jaguar

XJ

15995

2002

Cadillac

Escalade

40215.9

table

252

car id

VIN

m ake

m odel

co lo r

yoar

p rice

RNKLK66N33G213481

Porsche

Boxter

silver

1998

17992.54

SAEDA44B175B04113

Jaguar

XJ

NULL

2000

15995.00

3GYEK63NT2G280668

Cadillac

Escalade

red

2002

40215.90

ALTER

ALTER TABLE hooptie

^^bC K IB E


^ "

RENAME carjable,
ALTER TABLE carjable
ADD COLUMN carJd INT NOT NULL AUTOJNCREMENT FIRST,
ADD PRIMARY KEY (carjd),
-

ALTER TABLE carjable

6 m o d e l ,

co lo r > .

""

ADD COLUMN VIN VARCHAR(I6) SECOND,


CHANGE COLUMN mo model VARCHAR(20),<
MODIFY COLUMN color AFTER model,
MODIFY COLUMN year SIXTH, ^

1^~
y e a r AFTER
m o d el y e a r BEFORE p rice.

CHANGE COLUMN howmuch price DECIMAL(7,2);

>

253

)| 1
,
MODIFY,
. ?

,
?

, ?

^ J
. ,
,
,
, ,
.

ALTER TABLE your_table DROP PRIMARY KEY;

,
SQL ,
.
SELECT .

,
:

, :

AUTO INCREMEOT?

ALTER TABLE your_table CHANGE your_id your_id


INT(11) NOT NULL AUTO_INCREMENT;
,
?

A :

* . ALTER TABLE your_table CHANGE your_id your_id


INT(11) NOT NULL;
.
, AUTO_
INCREMENT, INTEGER
NULL.

change
, .
modify
.
drop column
.
rename .

254

>/7363 5


first ,last ,

BEFORE _, AFTER _,
SECOND, THIRD, FOURTH T .


ALTER

----------



,
- .
,
,
location.
------ ^

ALTER TABLE
.
ALTER TABLE
SELECT UPDATE,
,
.

SQL.
CREATE TABLE
m y _ c o n ta c ts .

CREATE TABLE m y _ c o n t a c t s
(

c o n ta c t_ id

IN T NOT NU LL AUTO_INCREM ENT

la s t _ n a m e VARCHAR( 3 0 )
fir s t_ n a m e

VARCHAR( 2 0 )

e m a i l VARCHAR( 5 0 )

<^pOKu - g e n d & r

d e f a u l t NULL,

C H A R (l)

d e f a u l t NULL,

d e f a u l t NULL,

d e f a u l t NULL,

4aZ m T e pT u4- b i r t h d a y
.

DATE d e f a u l t N U L L ,
p r o f e s s i o n VARCHAR( 5 0 ) d e f a u l t N U L L ,
lo c a tio n
s ta tu s

VARCHAR( 5 0 )

VARCHAR( 2 0 )

in te r e s ts

PRIM ARY KEY

d e f a u l t NULL,

ALTER TABLE.

d e f a u l t NULL,

s e e k i n g VARCHAR( 1 0 0 )

d e f a u l t NULL,

VARCHAR( 1 0 0 )

d e f a u l t NULL,

(c o n ta c t id )

. >

255

location
,
, l o c a t i o n
. ,
:
I File Edit Window Help LocationLocationLocation

> SELECT l o c a t i o n

FROM m y _ c o n t a c t s ;

lo c a tio n
, WA
, MS
J Ia c , NV
, CA
- , NY


location
my^contacts.

&

, WA

&

, MS
- , NV

- ,
- , NY
-

;
, ,
.
.


?
, ?

256

ALTER


l o c a t i o n my c o n t a c t s
: ,
.
.

,
,

City Name
,

.


l o c a t i o n s t a t e .

XX
,

.

ALTER TABLE,
m y _ c o n ta cts c i t y s t a t e .

(.z)iivH j n n s n h d i o d a a v
'(os)hlV H J^IVA
N i^ m o D a a v

sq.?v^viov-B\M 313V J. H3J-1V

257


.

state. ,
, city.
,
.

,

CHAR VARCHAR,

.



RIGHT () LEFT () ;

SELECT R IG H T ( l o c a t i o n ,

Z'


(
LEFT ).

2)

FROM m y _ _ c o n ta c ts ;


,.

,

.


SUBSTRING_INDEX ()
,
. ,
1_1 () ,
.

SELECT SU B S TR IN G I N D E X ( l o c a t i o n .


.

( ).
,
(
),
, .
258

1)

FROM my__cont a c t s ;

1 ,
.



.

ALTER


w uoijvro
.
)121 , varchar
CHAR.
.
, select .
SUBSTRING (, , ) ,
. .

SELECT SUBSTRING{'-, ', 5, 3);

UPPER () LOWER ()
.

SELECT UPPER('');

SELECT LOWER('');

REVERSE () .

SELECT REVERSE('');
LTRIM(TeKCT) RTRlM(TeKCT) ,
( ) ( ) .

SELECT LTRIMC ') ;

SELECT RTRIMC ') ;

LENGTH () .

SELECT LENGTH('-, ');


: , ;
, .

259

''

KTQ
l o c a t i o n
, c i t y s t a t e .
,
. SQL,
.

SUBSTRING__INDEX ()
SELECT
1. ,
.

LE F T
ADD COLUMN
2. .

AD JU ST
R IG H T
3. .

A LTER TABLE
DELETE

4. , 3,
.

IN S E R T
UPDATE

QmBeipbi Ha c.

260

262.

ALTER

, ,

. ,
UPDATE...

,
,

UPDATE
,

SELECT.
SQL .
,
.

261

4"

- ^ ?

lo c a t i o n
, c i t y s t a t e .
,
. SQL,
.

SUBSTRING__INDEX ( )
SELECT
1. ,
.

LEFT
ADD COLUMN
2. .
adjust

R IG H T
3. .

alter

DELETE

4. , 3,
.

IN S E R T
UPDATE

262

TABLE

ALTER

64
UPDATE?
.
.

UPDATE t a b le _ n a m e
SET = ;

c i t y s t a t e ,
RIGHT () UPDATE.

l o c a t i o n s t a t e .

UPDATE my_contacts
SET state = RIGHT(location, 2);

^
.

CU

locatioi^-


?
WHERE, 6 .


WHERE.
.

263

s q l

UPDATE SET

,
s t a t e .
my c o n t a c t s
lo c a lio ii

1
2

, NJ

-,

c ity

ta le


|((5>|-

SQL.

UPDATE m y _ c o n t a c t s
SET s t a t e

= R IG H T (lo c a tio n ,

2 );


Moiyr ;
SELECT,
UPDATE DELETE.

, ,
.
l o c a t i o n .
,
l o c a t i o n , ,
,
, .

UPDATE my_contacts

264


lo ca tio n
.

SET state = RIGHT(*4ecTep, NJ,2)


UPDATE my contacts


.


_
^
(

).

' .

SET state = 1(*, ',2)


^

UPDATE my_contacts

SET state = RIGHTCCaH-Mareo, ',2)

, .

ALTER

P ^

. 244.

. 210.
p r o je c t_ lis t

-u,
n u m b e r p r o j j d ;

^roj^ld

deserij^tionofproj

contractoronjob

>

265

sqi


5 ,

ALTER.
III.

lter table

- ^

1a lte r

H
alter

add

r !r f=

alter drop

yHKUUJ
<^^ ,
.

.

266

CHANGE

.
, ,
WHERE. ,
SELECT WHERE .

,
.



.

,
. ,
,
.

-;

From;
_ !
Subject:


,
.

V ID 9 Q


/, -
.
, ,

?
-

n e v i v jd

rating

m o v ie t a b l e

camscly

action

IW

cm

far.itid^

pnrclracnci

6-3-2002

5-2-2001

20-11-1999

19-4-2003

19-4-2003

5
6

PG

,

.

268

iifi ) C.V

5-2-2001

fiaciuupeue \>

^ ,
, .
,
, .
.

, )
.

. /
.


.
, ,
, /.
,
. , ,
, .
/
.
,
,
, .

------------------------------------------------------------------- ?
,
?

, >

269

^
, c a te g o ry ,
. ,
,
, .

'' :

'' :

'' :

category |

cooiedy |

category '

{ dtoi

category 'i

category

'' :

'' :

'' :

category ''

[ |_

'' :

'' :

category ''

' ':

c a r te e n ^

^ :

ra tin g | category ''

. .
,

270

category ''

, ,

SELECT



SQL UPDATE:
UPDATE m o v ie t a b l e SET c a t e g o r y == ' ' w h e re dram a =

' ';

UPDATE m o v ie t a b l e SET c a t e g o r y = ' ' w h e re comedy =


UPDATE m o v ie t a b l e SET c a t e g o r y = ' ' w h e re a c t i o n =
UPDATE m o v ie t a b l e

SET c a t e g o r y = ' ' w h e re g o re =

' ';
'';

' ';

UPDATE m o v ie t a b l e SET c a t e g o r y = ' ' w h e re s c i f i =


UPDATE m o v ie t a b l e SET c a t e g o r y *= '' w h e re f o r _ k i d s =
UPDATE m o v ie t a b l e SET c a t e g o r y = '' w h e re c a r t o o n =

' ';
' ';

' ' AND r a t i n g = '6';

UPDATE m o v ie t a b l e SET c a t e g o r y = '' w h e re c a r t o o n ' ' AND r a t i n g <> 'G ';

'Q'.

- ^

c a t e g o r y ;

m o v ie t a b l e
title

rating

drama

comedy

action

gore

sclfi

for_l(id*

cartoon

PG

PG

PG

PG

category

/?

;/'7'(.' *

271

- ^

c a t e g o r y ;
m o v ie t a b l e

t ill*

ratiag

drflMM

coMedy

Mction

Bor*

cifi

fe rv id

cartoen

* *

PG

PG

PG

PG

, - ^
U P P A T E .

UPDATE.
/?

6)
,
,

,
.
,
,
,
.

272

^ ,


.
UPDATE ^

.

: SELECT


,
? -
UPDATE
____ _
?

,
UPDATE, .
CASE
UPDATE,
. ,
.
,
, .

UPDATE m y _ t a b l e
^ -------- ^


CASE.
V

SET __ =

CASE

...

- > WHEN ! = !

. _
/

THEN __ !

WHEN 1 2 = 2

...

^
_

. ^

THEN _ 2




:


.

E LS E
EN D;

_
.


CASE
^-^PDATE (
; ).

273

UPDATE CASE

UPDATE e CASE
, CASE
m o v ie t a b le .
, U P P A T E
movie table S E T category =
---- '' W H E R E d ra m a iC
HO ^.

UPDATE m o v i e _ t a b l e
SET c a t e g o r y =
CASE
WHEN d ra m a = ' THEN ' *
WHEN c o m e d y = ' THEN ' '
WHEN a c t i o n = ' ' THEN ' '
WHEN g o r e = ' ' THEN ' '
WHEN s c i f i = ' ' THEN ''
WHEN f o r _ k i d s = ' ' THEN ''
WHEN c a r t o o n = ' ' THEN ''
ELSE ' '
, END;
^
1^

', .

us ,
-

m o v ie t a b l e
title

rating

drama

comedy

action

gore

scifi

for.kids

PG

PG

PG

PG

PG

274

category

SELECT

/ CASE
, .
,
:

UPDATE movie_table
:
S ET c a t e g o r y =
10 ^
CASE

W H E N d r a m a = '' T H E N '
:
W H E N c o m e d y = '' T H E N ''

:
W H E N a c t i o n = '' T H E N ''

W H E N go r e = '' T H E N ''
:
W H E N scifi = '' T H E N '

W H E N f o r _ k i d s = '' T H E N ' ',
~~ :
W H E N c a r t o o n = '' T H E N ' '

E L S E ' '
: ,
END;
c a te g o ry
.
,
, .

:

' ';

END,

.

UPDATE movie_table
SET c a t e g o r y =
;
CASE

-,
W H E N d r a m a = '' T H E N ''
END,
W H E N c o m e d y = '' T H E N ' '

W H E N a c t i o n = '' T H E N ' '
.

W H E N g o r e = '' T H E N ''
.
W H E N scifi = '' T H E N ''
W H E N for _ k i d s = '' T H E N ''
W H E N c a r t o o n = '' T H E N ''
E L S E ' '
END;
*

275

CASE

,
^ ' " > " - - .
.

Time

13.41

'"

}^> >^
. ^


% # / @
............. ^ ..............................

276

SELECT

- ^
CASE , (
cartoon) '', ''.
G,
.

,

?

>

277

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PoijliPUMp

CASE , (
c a r to o n ) '', ''.
G,
.

UPDATE movie_table
S E T category =
CASE
WHEN d ra m a - ' ' THEN ''
WHEN com edy = ' ' THEN "'
WHEN action = ' THEN ''
WHEN g o re = ' THEN ''
WHEN sclfi - ' THEN ' '
WHEN for_kids = ' THEN '
WHEN cartoon = ' AND rating = '<5' THEN '
ELSE 'mise'
END;


.I.,^ AND ^ ^ : " ~ 1 : : ; ~

,'
. '!

BoT lJoC bl
ELSE?

, . ,
,
, ,
-
, .

, WHEN
, ELSE ?

278

^ CASE
? ,
CASE
c a te g o ry = ' '. WHERE?

, END
WHERE.
WHERE.

CASE
, UPDATE?

.
. CASE
SELECT, INSERT, DELETE , , UPDATE.

pacunipeHi'e- SELECT

CASE

;
From;
Subject:


.
SQL, ,
.

!
,


,

6


^
.

5 .
-

-
-
-
-

.
,

,
. ,
.

, /, .

279

case

CASE

;
From;
Subject;


.
SQL, ,
.

UPDATE movietable
SET cate.gory =
5 .

CASE

-
-
-
-
-

WHEN dratma = ' AND rating = 'R' THEN '\-'


VJHEN comedy = ' AND rating - 'R THEN '-r'
WHEN action = '' AND rating = 'R' THEN -'
WHEN gore = '' AND rating - 'R' THEN '-'
WHEN scifi = AND ra tin g = 'R' THEN ' - r
WHEN category = '' AND rating = 'Q' THEN ''

END;

,
. ,
R.

UPDATE movietable
S E T category CASE
WHEN
WHEN
WHEN
WHEN
WHEN
END;

category
category
category
category
category

= ' -' THEN '


= ' - THEN '
= '-' THEN ''
- ' -' THEN ''
= ' -r' THEN ' '

, /, .
A L T E R TABLE movietable

DROP
DROP
DROP
DROP
DROP
DROP
DROP

280

COLUMN
COLUMN
COLUMN
COLUMN
COLUMN
COLUMN
COLUMN

d ra m a ,
co m edy ,
action,
g o re,
scifi.
for_kids,
cartoon;

SELECT


, ,
.
. ,
, . 20 ,
3000 .
, .
,
, -
.
m o v ie t a b l e
m o v ie id I

t it le

1^

83

6-3-2002

84

PG

5-2-2001

85

20-11-1999

86

19-4-2003

87

19-4-2003

88

5-2-2001

89

PG

6-3-2002

90

5-2-2001

91

20-11-1999

92

PG

19-4-2003

93

PG

5-2-2001

'


8 0 1 ?


5 0 0 0
, ) .

SELECT


3000
,
.
,
.

SELECT,
,
.

SELECT.
:

SELECT title, category FROM movie_table WHERE title LIKE 'A%' AND category =

'';

SELECT title, category FROM movie_table WHERE title LIKE '%' AND category =

'';

SELECT title, category FROM movie_table WHERE title LIKE 'B%' AND category =

'';

SELECT title, category FROM movie_table WHERE title LIKE '%' AND category =

'';

SELECT title, category FROM movie_table WHERE title LIKE '%' AND category =

'';

SELECT title, category FROM movie_table WHERE title LIKE 'E%' AND category =

'';

SELECT title, category FROM movie_table WHERE title LIKE '%' AND category =

'';

.

,

,
.

/ , .

3 0 0

).


,
,

(,
)?

SELECT

^
,
,
.
200 ( ) .
.

SELECT title, category FROM movie_table WHERE title LIKE 'A%' AND category = ''


title

category

! 2

283

- ^

,
,
.
200 ( ) .
.

SELECT title, category FROM movie_table WHERE title LIKE 'A%' AND category = '',

t it le

?
!
!2

284

ca te g o ry


,

20 ?
,
,

3000?

SELECT

ORDER BY
?
SELECT ORDER
BY .

'
-
>^, 6

^ SELECT.

...
,
- ^
6

title .

SELECT title, category


FROM movie_table
WHERE
title LIKE A%'
AND
category = ''
^ ORDER BY title;

,
?

.


.
,
?

' ^ ^

, ).

285

ORDER B Y

no
ORDER BY title,
,
,
title.

titleLIKE,a ORDER BY title .

ORDER BY

.



,
?

SELECT t i t l e , c a t e g o r y
FROM m o v i e _ t a b l e
WHERE
M m t-

c a te g o ry = ' '
ORDER BY t i t l e ;

SELECT title, category


FROM movie_table
WHERE
category = ''
ORDER BY title;
Ha



.

,
,
.

.

- ^

286

lit!*
1 ^
10 \
/
101
\
/ 13- \
/
2-2=5
\
001 ^
8 2
1
?
/
\
!
/
\
! 2
'
'>

^^1^^ ^
;

SELECT

, char (1)
test_chars.

, ( ) -
, (
). n u ll .
order b y .
.

0123ABCDabcd! #$%''&* () -_+=[]

SQL

SQL
o r d e r b y /;,^
,
,
-

ORDER BY
^ ^

+

.
NULL

>

287

,
, char (1)
test_chars.

, ( ) -
, (
). n u ll .
order
.

by .

_____ _ '

.

.

5 .
,


5 .

!"#$%&' ()*+,-./0123: ;<=>


?0ABCD[\]'- abcd{|}~

SQL

SQL
ORDER BY /,^^
, .
^^,

.^ ORDER BY
^ .


...

.
....

.
NULL

& ' (
.

NULL .. .
.

.
1

288

cj'iaea

1.

&

SELECT

ORDER
, :
.
,
-...

;
From:

Subject:
,


^^.
?
.

,

.

SELECT title, category, purchased


FROM movie__table
ORDER BY category, purchased;

.

,
ca teg o ry .

^0

? ;;

ca tego ry -



?
,
?
?

289

ORDER
.
,
.

1 ORDER BY .
, .

SELECT *

FROM m o v i e _ t a b l e

ORDER BY c a t e g o r y ,

p u rc h a s e d ,

3^e

"e Z Z T ,

title ;
(" ' ;



ORDER

SY. ^
.

,
.

,


,

.

20-11-1999 - -

I
---------- >

19-4-2003

--

---------- >

20-11-1999 - 290

>

T itle s
s ta rtin g w itli

SELECT


,
SELECT .

t it le

r a tl g

83

6-3-2002

84

PG

5-2-2001

m o v ic jd

moviejtable.
- ^

>

(!

>



6 , .

.U

^9

/ ] 1^

--

5,

/ ^

p rs h .d _
'

85

20-11-1999

86

19-4-2003

87

19-4-2003

88

5-2-2001

89

PG

6-3-2002

90

5-2-2001

91

20-11-1999

92

PG

19-4-2003

93

PG

5-2-2001

aepuAa>u^a

M o v ie jd

tille

110

c a te g o ry

84

PG

5-2-2001

86

19-4-2003

89

PG

6-3-2002

90

5-2-2001

91

20-11-1999

88

5-2-2001

purchased

92

PG

19-4-2003

83

6-3-2002

87

19-4-2003

20J1-199X

291

...
?
?

SQL
.
SQL ORDER
BY : , 1 99999 . .

,
DESC.

"^
1])1
DESC
. ,
?

. . DESC
, DESC m o v ie _ ta b le ;-
.
DESCRIBE.
ORDER
DESCENDING, .

292


)ESCRIBE DESCENDING, ?

DESCRIBE, DESCENDING

DESC

ORDER BY
.

S ELE C T

DESC u
,

,
,
. ,
, .

SELECT t i t l e , p u r c h a s e d
FROM m o v i e _ t a b l e
ORDER BY t i t l e A S C , p u r c h a s e d D E SC ;
7 '


ASC,
.
,

.

( ) ,

DBSC.

293

:

From:
Subject: !
!
!
,
ORDER BY
, .

,
. 18:00.
!

. S. ,
- ...

294

S ELE C T


,

.
.

J
)

- ^

,
^
^

cookie sales

ID

111_*

1
2


v f

>als

a l*_ d a t

32.02

6-3-2007

26.53

6-3-2007
6-3-2007

11.25

18.96

6-3-2007

9.16

7-3-2007

1.52

7-3-2007

43.21

7-3-2007

8.05

7-3-2007

17.62

8-3-2007

10

24.19

8-3-2007

11

3.40

8-3-2007

12

15.21

8-3-2007

13

9-3-2007

14

31.99

9-3-2007

15

2.58

9-3-2007

16

9-3-2007

17

2.34

10-3-2007

18

13.44

10-3-2007

19

8.78

10-3-2007

20

26.82

10-3-2007

21

3.71

11-3-2007

22

0.56

11-3-2007

23

34.19

11-3-2007

24

7.77

11-3-2007

25

16.23

12-3-2007

26

12-3-2007

27

4.50

12-3-2007

28

19.22

12-3-2007

, ,
. ,
,
.
ORDER BY ,
.

>

295

- ^
'

, ,
. ,
,
.
ORDER BY ,
.

S E L E C T F;Vst_nflme, sales

FROM cookie_sales
ORDER BY First_name;
...

296

111_1

19.22
0.00
8.05
26.82
7.77
15.21
18.96
3.40
2.58
4,50
11.25
8.78
43.21
34.19
17.62
9.16
0.00
32.02
2.34
3.71
16.23
26.53
0,00
0.56
1.52
13.44
24.19
31.99

^ .


,


.

8 1 .0 8

98.23

SELECT

SUM

C A o ik u m

. -'.
SQL.
SQL , .
.
, ,
. SUM , .
, .
SUM
sales.

S U M , mo ecmt?

one ,
.

SELECT SUM (sales)


FROM cookie sales
WHERE first name = '

, ,
,
sales>
5 .
I File

Edit Window Help TheWinnerlT

> SELECT S U M (s a le s )

FROM c o o k ie _ s a le s

- > WHERE f i r s t name =


S U M (s a le s )

96.03

1 r ow i n s e t

' ';

( 0 . 0 0 sec)

,
.
...
n o n p o 6 v u m e y c a M u

. , 1_1,
, ,
.

>

297

GROUP BY SUM AVG

GROUP BY

SUM
GROUP

BY.

SELECT

f ir s t _ n a m e ,

SUM ( s a l e s )

FROM c o o k i e _ s a l e s
GROUP BY f ir s t _ n a m e ^


first_ n am e .

ORDER BY S U M ( s a le s ) D E S C ;

SUM,

Ui/'

1^0 yOt^ieanuK),

..

u c n 0 A t? 3 0 6 a -

sales-

,,,

6 .

firs t

1*

19.22

fin i

0.00

alas

8.05
26.82

1.77
15.21
1 8 .9 6

26 .5 3

0.00
0.56
1.52
1 3 .4 4
24 .19

f ir s l nam e

31 .99

I Fils Edit Window Help TheWinnerReellyls

> SELECT

first_ n a m e ,

S U M (sa le s)

->

FROM c o o k i e _ s a l e s

GROUP B Y

->

ORDER B Y S U M ( s a l e s ) ;

+-------------------- +---------------------+
f ir s t

nam e

...
!

' > -|

107.91

98.23

96.03

81.08

298

1 su m (sa les)

-+-

row s

in

set

(0.00

sec)

first_ n a m e

sales
17.62
9.16

0.00
32 .0 2
2.34
3.71
16.23

fir s l name

sales

3.40
2.58
4.50
11.25
8 ,78
43.21
3 4.19

SELECT

AV6 6R0UP BY
,
.
AV G .
.
A V G , 7.

HO

, .

fiyst_nam .e

SELECT f i r s t , A V 6 ( s a l e s )
FROM c o o k i e s a l e s
A Va
GROUP BY f i r s t n a m e ;

,

. .


19.22
0.00
8.05
26.82

flra l.m in i*

*#_ *

15.21
18.96

vL
/

saUs
26.53
0.00
0.56
1.52
13.44
24.19
31.99

111_|*

sal*
17.62
9.16
0.00
32.02
2.34
3.71
16.23

flrsl_naine

sales
3.40
2.58
4.50
11.25
8.78
43.21
34.19

I EdK Window Help TheWmnerReallyls

...

> SELECT
->

first_ n a m e ,

FROM c o o k i e

sa le s

A V G (sa le s)
GROUP B Y f i r s t

nam e;

f ir s t

nam e

A V G (sa le s)

_____ _

13.718571

15.415714

11.582857

14.032857

row s

in

set

(0.00

sec)

299

MIN MAX e

MIN u MAX
He ,
MIN . ,
,
?

,
MIN.
M A X

S E L E C T r s t _ n a me^ (sales)
FROM cookie_sales
G R O U P B Y first name;
!



.

f i n i nam

saie*
26.82
43.21
32.02
31.99

S E L E C T first_name, M I N (sales)
FROM cookie_sales
G R O U P B Y first name;

,

,


.

f ir s l name

MIN ^

.

sales
0.00
2.58
0.00
0.00

. ,
,
, ?

300

S ELE C T

COUNT u
, ,
,
C O U N T. C O U N T .

---------_ COUNT
^ ------------
S E L E C T C O U N T (sale_date)
^-^sale_date. F R O M co o k i e sales;
n u l l ,
.

^
c o o k ie s a le s
ID

111_*

sales

sal*_dat*

32.02

6-3-2007

26.53

6-3-2007

11.25

6-3-2007

18.96

6-3-2007

9.16

7-3-2007
7-3-2007

1.52

43.21

7-3-2007

8,05

7-3-2007

17.62

8-3-2007

10

24.19

8-3-2007
8-3-2007

11

3,40

12

15.21

8-3-2007

13

9-3-2007

14

31.99

9-3-2007

15

2.58

9-3-2007

16

9-3-2007

17

2.34

10-3-2007

18

13.44

10-3-2007

19

8.78

10-3-2007

20

26.82

10-3-2007

21

3.71

11-3-2007

22

.56

11-3-2007

23

34,19

11-3-2007

24

7.77

11-3-2007

25

16.23

12-3-2007

26

12-3-2007

27

4.50

12-3-2007

28

19.22

12-3-2007

. ,
?

,
?

,
,
.

>

301

- ^

. ,
?
8

,
?

.
<<sale_date.

,
,
.

SELECT flrst_name, COUNT(sale^date)


FROM cookie^ales
ROUP BY first_name;

,
,
sale_date,
.
?

- .
,

.
,
.

D ISTIN CT.
COUNT, ,
.

302

SELEC T

SELECT DISTINCT

DISTINCT -
, , ^
saie^date ^
.

,
D IS T IN C T COUNT.

SELECT D IS T IN C T s a l e _ d a t e
FROM c o o k i e _ s a l e s
ORDER BY
.
ORDER BY s a l e d a t e ; < ~
I File Edit Window Help NoDupes

> SELECT D IST IN C T

sa le _ d a te

FROM c o o k i e _ s a l e s
->

ORDER B Y

I s a le

d ate

in

s a le

d a te ;

ro w s

s e t

(0 .0 0

sec)

COUNT:

: DISTINCT

s.ale_date).

SELECT C O U N T (D IS T IN C T s a l e _ d a t e )
FROM c o o k i e s a l e s ;

ORDER BY ,
COUNT
.
.

.

?

yiHwndg

>

303

SQL,
, ?
,
, . ,
.
.
, .

:
COUNT, DISTINCT, AVG, MIN, GROUP BY, SUM, MAX

11
.

? , .

304

SELECT
4 a cm

^
^!
ORDER BY

,
.

//
AVG, MIN?

M IN

,
. ORDER BY,
.
,
ORDER BY.
, ?

, ?

, ,
.
.

M IN ,
D IS T IN C T

NULL?

.
?

, . ,

. ,
NULL, NULL
, .

... AVG, COUNT



. SUM,
,
, .

,
, .

?

305

LIMIT u
, SUM .
, ,
.

SELECT i r s t _ n a m e , SUM ( s a l e s )
FROM c o o k i e _ s a l e s
GROUP BY f i r s t _ n a m e
ORDER BY S U M (s a le s )D E S C ;

1, -'

O R P E R 8Y,


.. ^
.

firstjp em *

107.91'

'v

96.03
81.08

, .

.
.''
. '
.

,
. L IM IT
, .

SELECT f ir s t _ n a m e , SUM ( s a l e s )
FROM c o o k i e _ s a l e s
GROUP BY f i r s t nam e
ORDER BY SUM ( s a le s ) D E S C ^
^
L IM IT 2 ;
.

,
^ ^ ^
.

sales

107.91

98.23

,
. , .
, 1000 ,
100 . L IM IT
, 9 0 0 .

306

? 6

SELEC T

LIMIT u
L I M I T ,

. L I M I T :


,
, ouAuSemecb.
LIMIT
, .

L IM IT

0 ,4


. 8 SQL
.

first.nam e

sales

107.91
98.23
96.03
81.08

.
1 ,
Z,
3

^
. .

100 ? ,
20 30.

L IM IT

L IM IT

19,

10. 19 ,

2 0 ( S Q L 0 ),
10 10 .

g J o 3bMM
,
.
L IM IT .

307

- ^

,
.
L IM IT .

SELECT first^name, SUM(sales)


FROM cookie_iales
GROUP BY first_name
ORDER BY SUM(5ales) DESC
LIMIT
He iaSydotne, SOL u ,,
.
/01 2..



... , ,
- ?

,
.

, .
7 ...

308

S ELE C T

SQL,
, ?
,
, ,
.
.
, .

:
COUNT, DISTINCT, AVG, MIN, GROUP BY, SUM, MAX

11
.

, .

? , .

SUM

DISTINCT

COUNT

GROUP BY

UAU

Ava

309

sql


6 .
,
SELECT.

t- O

III.

COUNT

10-

GR0T3P

C yvxO A dt^

DISTINCT

AVg


j
.
______ _

^'^(..

^^^'^

SUM


.
LIM IT


: ,
SELECT'

310

M IN

_________

>^>^ .


,
.

7 ^[ 51

.
,

.
,
. ,
, ,
.

) nogpyikky


.

.
:

contact_id: 341
last_name:
first_name:
phone: 5552311111
e mail: nigelmoore@ranchersrule.com
gender: M
birthday: 1975-28-08
profession:
city:
state: TX
status: He
interests: , ,
seeking:
in t e r e s t s ;

. :
, .

.

' )
:
mXertsXs. - ,
^, ...

312

- ?
in t e r e s t s .
,
, .

,
5 .

- ^
, ,
. ,
.

SELECT * FROM m y _ c o n t a c t s
WHERE g e n d e r = ' '
AND s t a t u s = 'H e '
AND s t a t e = ' T X '
AND s e e k i n g L IK E ' % % '
AND b i r t h d a y > ' 1 9 7 0 - 2 8 - 0 8 '
AND b i r t h d a y < ' 1 9 8 0 - 2 8 - 0 8 '
AND i n t e r e s t s L IK E .........................
A N D ..................................................................
A N D ..................................................................

313

*^

, ,
. ,
.

my^contacU
,
.

SELECT * FROM m y _ c o n t a c t s
_ ...
WHERE g e n d e r = ' '
'
...
AND s t a t u s = 'H e '
AND S t a t e = ' T X '
... ...
AND
AND
AND
AND

s e e k i n g L IK E ' %% ' <f



...
b ir th d a y > '1 9 7 0 - 2 8 - 0 8 ' ^
S
b ir th d a y < '1 9 8 0 - 2 8 - 0 8 '
...
i n t e r e s t s L I K E ..... 7 ?.><^.1^%'

and

. interests,LIKE '%%'

.................... x

AND "" interests'LI K E '% kuho%'].......................

.
OR,
H a i i m u

...
:
contact_id: 1854
last_name:
first_name:
phone: 5557894855
e mail: cfioregfioreanimalclinic.com
gender:

birthday: 1974-01-07-^-- >!.


profession; ^
,
city: -
status:

interests: ,


^
>, , ,

seeking: single

314

...) !
,
:

. ...

<<
.


.

.
.

' )

& ^, 1)

'

'<5) ^ cmo^S\xa
15{5.

>

315

in te res ts


, ,
,
5 . , ,
.

in t e r e s t s , .

, interests.

contact_id: 873
last_name:
first_name:
phone: 5552311122
email: me@kathieleeisaflake.com
gender:
birthday: 1955-20-03
profession:
city:
state: MA
status: He
interests: , ,
seeking:

SI 6

372

.
,
:


.
,
...

^ & & &,


.


, .
, ,
, . -
, , L IK E
in t e r e s t s .

SUBSTRING_INDEX
i n t e r e s t s .

317

- ^

SUBSTRING_INDEX
i n t e r e s t s .

SUBSTRING JN P E X (in terests,


. ---------------------------- ------"


,
__
lnterests
'

1 .

lna|yumcyv\fyu/vi
,
.

,
.

SUBSTRING INDEX,

' '.

SELECT * FROM m y _ c o n t a c t s
WHERE g e n d e r = ' '
3
AND s t a t u s = 'H e '

, AND s t a t e = ' M A '

AND s e e k i n g L IK E ' % % '
''.
AND b i r t h d a y > ' 1 9 5 0 - 2 8 - 0 8 '
AND b i r t h d a y < ' 1 9 6 0 - 2 8 - 0 8 '
AND S U BSTRING I N D E X ( i n t e r e s t s ^ 1 ) = ' ';

Peg)ku
- ! ;

contact_id: 459
last_name:
first_name:
phone; 5550983476
email: alexangel@yahoo.com

birthday: 19(,-\9-09<^^
profession:
ci ty;
state: MA

status: He

interests: <
seeking:

318

p.


,
.
my

c o n ta c ts , .

] ^ ^ | ^ |:>

^ : ^, ]=>: . ||

, ! ] ]=
!

' ^ )

ucno/<b3o6'3mb ^, ;.. '

) ^& ) &'
, / ) "
.
<v,cmoAoue



,

,

.



.

fe rW T V P M


?

319

in ie ra s t

interest
,
.

LIK E , .

ALTER

, ,

. ,
.

- |
ALTER SUBSTRING_INDEX,
,
. .

c o n ta c t_ id
la s t_ n a m e
fir s t_ n a m e
phone
e m a il
gender
b ir th d a y
p r o fe s s io n
c ity
s ta te
s ta tu s
in te r e s tl
in te r e s t2
in te r e s ts
in te r e s t4
s e e lc in g

. 371'

320



. :

contact_id: 872
last_name:
first_name:
phone: 5554531122
email : regis@thieleeisaflake.com
gender:
birthday: 1955-20-03
profession:
city:
state: MA
status: He
interestl:
^ 1~
interest2: L
...

interest3:
J
.
interest4: NULL
seeking:

, .
gender, status, state, seeking birthday
interest.
.

>

321

,
gender, status, state, seeking birthday
interest.
.

S ELEC T * FROM my_contacts


WHERE g e n d e r = ' '
AND status = 'H e '
AND
AND
ANP
AND
ANP

state='M A
seeking LIKE '% % '
birthday > ' 5 0 ~ 0 ~ 0 '
birthday < 'X 4 (2> 0-Z 0-03'

(
in t e r e s t ! = ''

>

,
^,

,


.

OR in teres ts - "'
OR in teres ts = ''
OR interestd - ''
)

AN P
(
in t e r e s t l = ' '
OR in teres ts = ' '
OR in teres ts - ' '
OR in teres ts = ' '


,


in t e r e s t ,


.

AN P
(
in t e r e s t l = ''
OR in teres ts - ''
OR in teres ts = ''
OR in t e r e s ts - ''

322

i n t e r e s t ^

NULL,


.

...


' )

M fi,

:


.

--

\ Styh

pe-LUeHWe.-

>^

...OguH !

0 0

,
q^op/a ?______


?

?

323


,
, .
,
. .
.

I File Edit Window Heip^ MessyTable

> DESCRIBE m y _ c o n t a c t s ;
1 F ie ld
i T yp e
I N u l l I K ey I D e f a u l t | E x t r a
|
+ -------------------------- + -----------------------------+ ------------ + ---------- + ------------------ + --------------------------------- +
1 c o n ta c t_ id

1 in t(ll)

1 NO

1 PRI

1 NULL

1 a u t o in c r e m e n t

I l a s t name

| v a r c h a r (3 0 )

1 YES

1 NULL

1 f i r s t name

| v a r c h a r (2 0 )

1 YES

1 NULL

1 phone

1 v a r c h a r (1 0 )

1 YES

1 NULL

1 e m a il

i v a r c h a r (5 0 )

1 YES

1 NULL

1 gender

1 c h a r (1 )

1 YES

1 NULL

1 b ir th d a y

1 d a te

1 YES

1 NULL

1 p r o f e s s io n

1 v a r c h a r (5 0 )

1 YES

1 NULL

1 c ity

1 v a r c h a r (5 0 )

1 YES

1 NULL

1 s ta te

1 v a r c h a r (2 )

1 YES

1 NULL

1 s ta tu s

1 v a r c h a r (2 0 )

1 YES

1 NULL

1 in t e r e s t s

1 v a r c h a r (1 0 0 )

1 YES

1 NULL

1
1
1 NULL
1 s e e k in g
1 v a r c h a r (1 0 0 ) 1 YES
1
I
_+ -------- _ + ----------+ ------------ + ---------------------------------+
+ -------------------------- +
13 row s i n

324

> 7

set

(0.01

sec)

>


3?
,

.


'^ ciownjtracking

clown_tracking
CtOMTN^iMf

BftsepHHKa

a c tiv H ie c
, , < .

^ ) ,
\

^ : ,
| 6.1,

,

.

.

iTVPM
,
? ?

325

clownJracking

clown_tac]cing

( , . .)

1 * |

#
,

, , ! ,
, ;

)4^ ^ ^ * " " * 5 ,

,

.

( )
,
, .
7

5 ,.

, , ,

326


, .
m y

c o n ta c ts .

DESCRIBE.

,
, - .
my

my_contacts

contact id

c o n ta c ts .

,

.

last name
first name
phone
email
gender

0
U . -

birthday

6 ,.

profession
city
state
status
interests
seeking

327

1_|#

i n t e r e s t s ,
.
,
.

contact id
last name

64,
c o n t a c t s ^

first name
phone

my

email

c o n t a c t s

. i n t e r e s t s ,

gender

birthday
profession

, .

city
, ,

state

status

interests

seeking

in te re s ts
.
in t e r e s t s .

id \ \ ,
.

interest

VARCHAR

.

'
'.

i n t e r e s t s
m y _ c o n ta c ts (
).

328

,
,
m y _ c o n ta c ts .
m y _ c o n ta c ts ,
, .
my

c o n t a c t s

i n t e r e s t s ,
.
, f i r s t

nam e

la s t_ n a m e i n t e r e s t s .

my_cwtwts
contact id
last name

Interests

first name
phone

int_id

email

interest

gender

first_name

birthday

last name


.

.

profession
city


,
.
interests

,

.

state
status
seeking

, f i r s t n a m e
l a s t _ n a m e
.
?

iHbUie *

329


my

c o n ta c ts

_11
irtUrests:

(ir5t_name
Last_name
irtkrest

rtw_corTtads
CSe^ irtUrests)

contact id
last name
first name

inter*!

phone

int id 0=~w

email

last name

gender

first name

birthday

interest

profession
city
state

9 - -

status
seeking




'^
,
01^.

:
.
, ,
S Q L - ,
.
SELEC T,
.

SELECT f i r s t name, l a s t name


FROM m y_contacts
WHERE {) ;

330

SELECT i n t e r e s t FROM i n t e r e s t s
WHERE fir s t_ n a m e = ''
AND l a s t name = ' ' ;

- ^
_1 1
?
;
. ,
.

5.

(>|9;
5_
5_

(5 50

.'

,-

331

- ^

g r e g s _ l i s t
?
;
. ,
.

^ irfterests;

;
|ir5t_name
Last_name

inferest

T a iA U C ,


~
m y_contacU
,
, .

1^ .

: ! " ; . . . MU .

, first^ n am e
<<lait_name,
,
c o n t a c t j d :
/^'
interests:

int id
in terest
c o n t a c t jd

n^a5uu,a
m ijjco ntacti
(5
in t e re s ts )

332

c o n t a c t j d

.
,

c o n t a c t j d

m y _co n tacts.



:
f ir s t _ n a m e la s t_ n a m e . m y _ c o n ta c ts
f ir s t_ n a m e
la s t

nam e?

irfkresty.

;

|?rst_name
La5t_name

rm_cxiritacts
((fe, (5 irrto-ests)

first_name

friterest

>^0 -
!

. , ,
m y _ c o n ta c ts

.

m y _ c o n ta c ts in t e r e s t s . ,
,
m y _ c o n ta c ts .

c o n ta c t

id O

la s t

nam e

f ir s t

nam e

phone
e m a il
gender
b irth d a y
p ro fe s s io n
c ity
s ta te
s ta tu s
s e e kin g

coom- ^^
,

inl*r*sls
in t

id

in te re s t
c o n ta c t

id

^
,


5 , my_contacts


,



.

333

)

,
.
, ,
. ,
,
.

.
NULL,
.

,
.

,
.
NULL ?
,
?

N U L L
,

.
,
,
.

334

,
,

, CREATE
ALTER. ,

.

,

. -


,
.
.

m y contacts ,
, ...
my_cowtat
c o n ta c t

id O

la st

nam e

f ir s t

nam e

...
^ \.

phone

ii

e m a il

in t

gender
b ir th d a y
p ro fe s s io n
c ity
s ta te
s ta tu s
se e kin g




;


.

id
in te re s t

c o n ta c t

id


,



.


.

,
.
*

335

?
- "
,
:
my_contacts.
... ,
.


.

ALTER

TABLE.

,
,
.
in t e r e s t s
c o n ta c t_ id

c o n ta c ts .

----------------------- < ----------------------------------1)1


,
m y _ c o n ta c ts ?

J . ,
.
contacts, .

336


, ,

. ,

?! P R IM A R Y
K E Y 6

( C O N S T R A IN T ):
, .

CREATE TABLE i n t e r e s t s

( )
.

I
in t

id

IN T NOT NU LL AUTO INCREM ENT PRIM ARY K E Y ,


,

i n t e r e s t VARCHAR( 5 0 )

NOT N U L L , ,


(my_contacts),
- ^ c o n t a c t i d IN T NOT N U L L ,
(c o n t a c t jd )

____
(fk.) - C O N STR AINT m y ~ c o i r t i c t s ^ c o n t a e t ^ i d ^ f i e


,
,
FO R E IG N KEY ( c o n t a c t ^ i d )
.

,
:

REFERENCES m y _ c o n t a c t s ( c o n t a c t _ _ id )

,
IN T
r

)
... .
,
NULL.


13
.
...
.
,
.

.
in te re s ts .
, .
?

337

.
in te re s ts .
, .
?

I File Edit Window Help

> DESC i n t e r e s t s ;
N u l l I Key 1 D e f a u l t I E x t r a
F ie ld
I Typ e
+ ------------------------ + ---------------------------+ ------------ + ---------- + ------------------ + --------------------------------- +
in t_ id

I i n t (1 1 )

I NO

I PRI

I NULL

in te r e s t

I v a r c h a r (5 0 )

| NO

c o n ta c t_ id

I i n t (1 1 )

I NO

| MUL |

I a u t o in c r e m e n t

+ -------------------- M U L ,
0 .
c o n t a c t j d m y _ c o n ta c ts .

'^
1

?


?

,

,
.
.


).


,
,
.


i n t e r e s t s ?

!
.
,
-
.

,
m y _ c o n t a c t s
,

, .
?

i n t e r e s t s

? ?


(
, ,

338

,
.
,
my_contacts,
.

'
. UNIQUE
( )
.
CHECK,
MySQL. ,

.
CHECK
.

)
, , , .
m y _ c o n ta c ts ,

,
:

--.

--, --

, (

: --
,

--,

, .

.

, ,

(
).

1_<1

U3

1 _ 1 1
, 1_11
.

.

employees
,
.
- -

enployees
ni|iloyee_id

0~*1

first_Bame

salary
salary_l*vl m p le y e e jd

iast_name

SSH ~

234567891
345678912

2
5

23456789

6
35
1

1 - ,

em ployee
, .alary.

339

--


--
,
--

?

- . - .

- - .

--
, )- - - ,
,
.
1. .
,

, .
2.
,

NULL .

3. .
,
,
.
4. ( ,

BLOB)

<<-->>:

.
340

: --
- -
,

.


-
>

-----

my





,



^

,

c o n ta c ts

<<-->>:



,


- .
,
my

c o n t a c t s .

p fto lo in
p ro f

p r o fe s s io n

id

p ro fe s s io n


p r o fe s s io n p r o f _ id .
p r o f _ id ,

c o n ta c t

id

la s t

nam e

fir s t

nanne

phone

ennail

gender

; ,

b ir th d a y

.
c ity

p r o f e s s io n s

s ta te

m y _ c o n ta c ts ,
my

s ta tu s

c o n t a c t s

se e kin g

p r o fe s s io n s .
, p r o f

i d

m y _ c o n ta c ts
,
my

c o n ta c ts

p r o f_ id .

341

<-:<-

02 0 02

: MH Ue-k -MH U>



.

,
- ,
.

MHOrUE

,
, ,
.
w om en s h o e s .

w o m a n _ id

w om an

shoe_id

------ - - - - - - -

shoe_nam e

1
2

3
4

f
4

4
4

%
>

,
, .
.

, ,
;
0
.

w om an

s h o e jd

shoe^nam e

0)
1
2

3
4

iTVPM

( , )?

342

-' /

- ^
.
, _11
.

w o m a n jd 0 ~ w
1

2
3
4
5

6
7
8
9
10

s h o e jfl
3

1
1
1
4

^
/

^
/
/ >

she_M

sho_iiame

1
2
3

/ /

3
4

3
4

//
/

____
, i h o e j d :

,
wom an_id shoes
.
,
.

343

w o m a n jc l 0 w
1
2
3
4
5

7
8
9
10

.
, _ 1 1
.

she

3
1
1
1
4

^
/

2
3
4
3
4

,^-

w om an

h e e jd

5(_^.

Z_____ 2______

/
/

/ ;
1

/ ///
/ /
/
/ '

3
4

sho*_nam*

__ /

sk o ejd .

,
w o m a n _ id s h o e s
.
,
.

shoe_id 0 W
1
2
3
4
5
6
7
8
9
10

344

$_
\
^

w jtm a n jd
3

//

'v

^1
1
3

/
/

3
3

/
/

4
4
4

/,
/

woman_id

wom an

1
2

)
,

. ,
.
.
,
- - - . w o m a n _ id
s h o e _ id .
.


, -
- -
.
w om anjd

woman

shoe_idl Csr

1
2
3
4

--

_____ ^

'
...

2
3
4

- /
...

_ .

--

woman_id

shoo_id

1
1

3
4

2
3
3
3
3

1
1




,

.

4
4

2
3
4
1
3
4

--

<<-->>:


.

345

--

: --

--:

- - , .
my

c o n t a c t s

in t e r e s t s .
,

--.

i n t e r e s t s
- - . ,
:

^
- - -

"

n te re rts ,

_011 tacts
c o n ta c t

id

interests

contact^
iiiteresl

la st

nanne

c o n ta c t

f ir s t

nanne

in te re s t

id
id

in te re s t

phone

erail
gender

id

in te re s t

/
- -

- -

b irth d a y
p ro fe s s io n

c ity
s ta te

-----------------1>:1

s ta tu s
s e e kin g

_1<1

--?

1 8 _ . ,
,

, . --

,

( ,
).

,
.

.

346


,

.
,

. ,

--,
.


. ,

my_contacts,
c o n ta c t_ in te re s t.

. ,
.

. ,
,
. ,

in te re s ts ,
c o n ta c t_ in te re s t _
contacts .

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

doughnHt_rating

]
rating

clown_tracking
1\/

11

activities
d ate

m y.conlacts
co n tact

id

s ta !r-f>

books

id

fish records
record

id

347

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

doghiiat_ratlng

, ^ -tf^ g h n u t_ ty p ?

-- >

rating

clown_tracking
clown id
activities

- -

date

my_contacts
contact id
C ^ ~ s ta T r~ D
< d int^e^5>^

books
book id
(^ ^ th o rs ^

- -
- -
:
'\. ^ ,
- - .
^----- ..1'!.- -
...... - -

fish ro co rd s
..... - -

- -

348

,
.
gegsJist my_contacts
, ?

. ,
,
g re g s _ lis t.
, in t e r e s t s
- . s e e k in g
.

*.


.
,
( .
).
g r e g s _ lis t ,
.

my_conlacts
co n tact

id '"

last

nam e

first

nam e

phone
em ail
g en der
birthday
profession
city
state

, ,
?
, .

status
interests
seeking

>

349

6
.
, ,

.
, ,
, .

, :
1. .
2. .

.
:
,
.

1
le y jd
5

le y

12

colors
,

fo y jd l
5

,
,,

6
9
12

toy

5 co lo rs
,

, z
3 .

350

1,


, VARCHAR
.

- 1...
, .

1
.

nep6wHHK>iC(
lo y jd

toy

12

U pt
<--;;tAAeAl3H0 0^1'

color
5
5
5

9
9
9
12
12


^
'" '7 ^
,
^^>^


t o y j d c o lo r

IZ7.

t o y _ id
,

.
c o lo r

t o y _ i d .


?

?

. ,
,
.

.

351



(--, -), ,
.
-

. ^
I

.

, ?


,
,
.

.
,
pow er.

, .

,
. ,

,
.
^
super_heroes
po w er
*
w o akn o M

-

NULL

-

-


-

,
NULL


NULL

NULL

352

)

!

) -




, ,

.

!
s u p e r_ h e ro e s .
, .
i n i t i a l s

nam e.
, ?
, i n i t i a l s

. , i n i t i a l s

nam e.

, ^
1 p o w e r
.

super_heroes

I
Item 0 + i r

p o w e r 0+ *

w oaknoss

c it y

n rc h ^ o n o m y

i n it ia l s

NULL

^ -

40

NULL

NULL

^ -

, i n i t i a l s
n a m e . - ?
.

353

, i n i t i a l s
. - ?
.

initials
weakness
_
city country

co^
;

.


mauJ .

UP

. > .
:
. .
:

s u p e r _ h e r o e s . nam e > s u p e r _ h e r o e s . i n i t i a l s

s u p e r_ h e ro e s i n i t i a l s

s u p e r _ h e r o e s . nam e > s u p e r _ h e r o e s . w e a k n e s s

super

h e ro e s w e a k n e s s

s u p e r _ h e r o e s . nam e > s u p e r _ h e r o e s . arch_^en<

super

h e ro e s a rc h

enem y

s u p e r _ h e r o e s . c o u n t r y > s u p e r _ h e r o e s . c i t y

super

h e ro e s c i t y

c o u n tr y .

354


, ,
in itia ls

; ,

nam e.


,
. ,
a rc h

enem y

c i t y

^^-

- ,

^ ,

.

.
R i n i t i a l s

nam e,
i n i t i a i l s

p o w e r ( n a m e !)
in itia ls

p o w e r

'
, ,

- uAU^ciVib.

weakness

ST

NULL

& < !

& *

initials arch_enemy_id 1|__11

SG

WW

SG

NULL

FW

10

16

NULL

GG

33

355

; / : ^ /



.
- ,
_ _ 1 1 .

^ _[ ,
- .
^ _ > 1 ^ r c h _ e n e m y j^ y
n a m e +
\^ -
- 4
4
^
^

-
5

-
1

,
. _ _ 1 1
,
a r c h _ e n e m y _ c itY .
-
, ,
.

a r c k ^ e n e m u j d :

a r c h .^ ^ .

^ _ ^ ^ ^ " a r c h _ e n e m y j^ y
n a m e '
-4/
-

-
5

-
1

-

, ,

.

- a r c k _ ,e n e m y J d .
-.


: -
- .
356

. _1(1
, pub_city , .

a u th e r 0 +JT

t i l l e 0+ W


!
,

c o p y r ig lit

p u b jd

pul>_city

1930

1968
1950
1951

5
3
1

-
-

, copyright, title
!.
c o p y r ig h t
title.>>
'co py righ t. ............................................................. '' .

copyright,
, ?

, _1(1
1?

_11 ,
?

_11 , _1(1
1?

357

. pub id
, pub city , .
, copyright, title
!. c o p y rig h t

tit le ,

....................................... .
copyright,
, ?
,

........................................................1

Copyright

.

author O'1'R

|1 0+!

copyright

^.

|-*



!
,

1930
1968
1950

2
5
3

1951

-
-

, pub

id

!?

^ ^ p u h _ c j t y p u b J d 1 p u h j d Z
p uh _city . - ,
p ub id - ................................................... ( pub_city p ub_id)

pub city
pub id , U
?
&.^_^^^'^'^^-'^^^ .
.

pub city , pub id


1?
^
^ p u b ^ c it y
jub_city - p ub_city - .
/ ^ p u b j d
\ .............................................................................. u b j d ,
/'^?<^ .
.
-

358

author +-

|1 **-

copyright

1930
1968
1950
1951

^ .

2
5
3
1

|_
-

-
-

-,
m y _ c o n ta c ts , .
,
,

-?

)?

, .


, .
, .

, ,
.

, , .

?



2.
,

,
.
2 ,

.

359


,
,


.

*_

toy

5
6
9
12

.
--------- -

toy.id
0+-

1_
id 0 +

inventory

store.oddress

5
5

1
3
1
2

34
12

1
2
2
4
4

24
50
2

23
100 -
23
1902
17

5
6
6
9
9
9
12
12

5
10

18
28
11

/

.

, .
toyjcL
, - .
s t o r e a d d r e s s
,
s t o r e id .
, ,
.
, ,
.
, s t o r e _
a d d r e s s ,
.

360

23
1902
1902
17
17


,




:
.



,
,

.

), ) 6 2 ...
1 2,
.

t o y _ i d s t o r e id .

, ,
.

1
2,

lo y_sto re

toy_id
store id

1 2,
.
AUTO_INCREMENT.

, 2:
1. .
2.
.
my_contacts

, ...

, ...

: ^

361

^
^

=*1
IJj eAcmaDbine cc^ff
U ucKJIioMume ^

'
. iij^eAcmaB m ajiuU Bbi4ej>KHume m e
, Komof*bie

nejeMecmumb

1 .

fo yjn ven lo r

(
^ "(

toy_id
store id

ceekie sales
am ount

singers

g ir li d

s in g e rid

date

last

girl_nam e

first name

troop_leader

agency

total sales

agency _state

mevies
movie id
title
genre

salary

r e n te d b y

ernployee_id

due date

last name

rating

first name
salary
manager

dog_breeds

e m p lo y e e e m a il

breed

hire date

description
avg_w eight
avg_height
club id
club state

362

^
, 2.
,
,
. .
p h o n e , m a n a g e r, c o s t
w e ig h t . , t o y i d .

5
6
9
12

l e y id
0+>r
5
5
5

6
9
9
9
12
12

Id 0 + i r
1
3
1
2
4
1
2
2
4
4

c o lo r

In v e n t o r y

s to re _ a d d re s s

34
12
5
10

23
100 -

24
50
2

23
1902

18
28

17
23
1902
1902
17

11

17

363

2.

^ ^

=^ . QmBem
| ] |


. ^ ^^^ '
, * ]=

singers
singer_id
last_nam e
first_nam e
agency
agency _state





agency
(

- ' ) ,

salary

^ em ployee_id
last_nam e

first name

ceeki*_sals
am ount

date

gtffrfwetf p _ loador

teterKsateS"

mevies

movie id
title

.'

genre
rented_by
due date
rating

salary
manager
em ployee_email
hire_date

deg_breeds

breed
description
avg_w eight

club_id


ocmauecJl
^
.

girl_id

avg_height

364

to y_id
store id

1 ).

lo yJavM flo ry
v

1_11
(
- - ),
c^ub_state
. ,

.

^1

^
"2 0 0 , 2.
,
,
. .
p h o n e , m a n a g e r, c o s t
w e ig h t . , t o y _ i d .

toy

toy id
0 +"

atore_
id 0+ir

color

t * y jd
5
6
9

5
5
5
6

1
3
1
2

34
12
5
10

23
100 -
23
1902

12

6
9
9
9
12
12

4
1

24
50
2

17
23
1902

18
28
11

1902
17
17

2
2
4
4

storo.addroas

S t o r e _ in v e n to r y


t o y j d
sto rejd .

toy id
0+V

store
id 0 + w

inventory

5
5
5
6
6

1
3
1
2
4
1
2
2
4
4

34
12
5
10

t o y _ in f o
to y jd

toy

cost weight

0 -^
1
2

3
4
5
6

-
-

8
9
10

1.95
2.20
1.95
3.50
1.50
5.75

0.3
0,5
0,2
1,2

5.75

1.2

3.15

0.8

4.25
1.50

0,4
0.2

9
9
9
12
12

0.3
0,4

24
50
2
18
28
11

s to r e in fo
store_
id Ow

address

phone

manager

1
2

23
1902
100 -

555-6712
555-3478
555-0987
555-6554

3
4

17

365

(-!)

,

.
,
, 2.
, ?

, :
1. 2.
2. - ^
.
; cou rse_nam e (
), i n s t r u c t o r ()
in s tr u c to r _ p h o n e ( ).

c o u r s e _ n a m e
i n s t r u c t o r , i n s t r u c t
p hone

=>

=>

i n s
i n s t r u c L o r ,

t r u c t o r _ p h o n e

?



.
-


,

.

courses
c o u rs e
c o u rs e

id
nam e

in s tru c to r
in s tr u c to r _ p h o n e

co u rse _ n a m e

.
. "
i n s t r u c t o r

in s t r u c t o r _ p h o n e

366

o r _




,
2.

: 7

' ,

in stru cto rjp h o n e .

joAsmb my.contaets?
.
my contacts gregs_list.
, -- .
.

contact id
last name
first name
phone
email
gender
birthday
profession
city
state
status
interests
seeking
.

:
7.)

367

m y^contacts?
^ /

'

.
my contacts gregs_list.
, -- .
.

--
- -
.

m y _ c e n ta c ts
contact id
last _ name
first_nam e
phone
email
gender
birthday
profession


/^ <^

< / -

city
state
status
interests
seeking

contart_iwt>r4t

interest_id O y
interest_id

0 + ir
iy_coBtacts


- - .
'

^--

contact_id
last_nam e

'Mh,

first_nam e
phone

prof4teii

email

p ro f_id

gender

profession

birthday

interest

8 co n ta cts
in terest n^opoe
in te re s tjd
J
in t e r e s t s
.
-s e e k in g jd

seeking_id (

zip.cod*

city
state

status
status

368

seeking

0+W

.^zip_code

- ^

.fstatus_id

^ ^
.

'^ . --
Z m o u m
f^ ^ ^ Z e d u - - U
-

... 9) ( ^^
; ...


, ,
. , .

-------, !

!

- ?

.
...

>

369

sqi


(1)

,
.
,
7.
III.

,

^ ^ ^ ^ ~,^_

-
-
(-).

(2)

--




^


.

-


.

()


I
<

.


. -

5 6,
, & " " "

370

A L T E R S U B S T R IN G

IN D E X ,


\ (5(7(;

contact_id
last_name
first_name
phone
e m a il
gdnder
birthday
profession
city
state
status
interestl
interest2
interests
interest4
seeking

. .

ALTER TABLE my_contacts


ADD COLUMN interestl V A R C H A R (50),
ADD COLUMN interest2 VARCHAR(50),
ADD COLUMN interests VARCHAR(50),
ADD COLUMN interests VARCHAR(50);

i n t e r e s t l . :
U P D A T E my_contacts
SET interestl = SU B ST R IN G IN D E X (interests,

1 );

, interest^-, --'
in terests .
:
TRIM
,
^

UPDATE my_contacts SET interests = TRIM(RIGHT(interests,


(LENGTH (interests)-LENGTH (interestl) - ].)));

A ^^

in terests . in t e r e s ts .,^. , in t e r e s t ^ . / /;
, ,: <aivM-wu.

:
UPDATE my_contacts SET interest2
UPDATE my_contacts SET interests
LENGTH(interest2) - 1)));
UPDATE my_contacts SET interest3
UPDATE my_contacts SET interests
LENGTH(interests) - 1)));

= SUBSTRING_INDEX(interests,
= TRIM(RIGHT(i n t e r e s t s , (LENGTH (

1);
in te r e s ts )

= SUBSTRING_INDEX(interests,
1);
= TRIM(RIGHT(interests, (LENGTH(interests)-

:
UPDATE my_contacts SET interest4 = interests;

in t e r e s t s .
in t e r e s t ^
ADD COLUMN
( J ).

>

371

, in te r e s ts .

'

SELEC T

. 316.

WHERE g e n d e r = ''

FROM my_contacts

AN D s t a t u s = 'He '

AND s t a t e -


^ ___ ^ ,
-

AND seeklna LIKE %


%
AN D b i r t h d a y > '1-5 0 - Z 0 ~ 0 3 '
AN D b i r t h d a y < ' 1 0 - 2 0 ~ 0 3 ,

372


in terests.

^ 0


?^
^

! ,
, , ,
.
,
. ,
, .
, !

: ^ vr

U , ...
, p r o f e s s i o n , i n t e r e s t s
II s e e k in g .

.- .4

~[~^

lolus

''
~

|^|^^^

I ----

professien


'

in te r e s ts

<?

374

NULL



p r o f e s s i o n ,
i n t e r e s t s s e e k in g .
,
my c o n t a c t s .

,
-
.

,
profession, i n t e r e s t s s e e k in g v a lu e s
my c o n t a c t s . .
6.

>

375

^
,
p r o f e s s i o n , i n t e r e s t s s e e k i n g v a l u e s
m y _ c o n t a c t s . .
6.

SELECT profession FROM imy_contacts


^
f

GROUP BY profession
ORDER B Y profession;

GROUP B Y
~
.

ORDER
BY
.

,
. ORDER BY

.

SELEC T seeking FROM my_contacts

^ GROUP BY seeking
ORDER BY seeking;

GRQJ^P B'YUnterests

Ho
interests.

, ?

1RDER BY inte^bit;


SELECT
.

S E L E C T .
in te r e s ts
,
, ,

,
,

376



.
i n t e r e s t s .

, :
interest

, , ,

^ y ^ c o n t a c t s

, ) :
interests

^'' in t e r e s ts .

(
-
i n t e r e s t s ?

, ?

rny_contacts,
.

, .
,
.
-,
.
,
.
,
? 8 .

377

()
m y c o n t a c t s

. .

- ^
A L T E R ;

c o n t a c t s .
in t e r e s tl, in te r e s t2 , in te r e s ts in te r e s t4 .
my

QiTiBfinbi ,

408

i n t e r e s t s
m y _ c o n ta c ts A L T E R .

in te re s t

interests
, , ,

interestl

hitertS

interest4

i n t e r e s t l
S U B S T R IN G _ IN D E X (. 5):

UPDATE
SET

m y _ c o r^ ta c ts

in te r e s tl

S U B S T R I N G _ IN D E X ( in t e r e e t s ,


.
interests
, , ,

378

-= 8

Interestl

interests

McKoMWw

( )
lalMWSI9

1 );
...

interest4


:
i n t e r e s t s ,
interestl.
.

interestl

___ _
interests
( ^, , ,

interesta

interest#

> ,
interests S U B S T R i n t e r e s t s
. , interestl, ( ).

,
interests ,
, , '
;
in t e r e s t ^
-

UPDATE
SET


-.

6 i n t e r e s t l . ^

m y_conta c ts

in te r e s ts

S U B S T R ( in t e r e s t s ,

L E N G T H ( in t e r e s t l) + 2

LENGTH

SUSSTR

^ ^ ^ ^ ^ ^ ^ " ^ ,

, -
.
^


,
.


5 0 1 .
,
. \
5 0 1
11'\!

) ;

f
^

^^^^
^^

^
4

Si

,
4 rZ , 6 ^
6ydevn


interests.

O/ihiiie

379

( 2)


UPDATE
, .
.
i n t e r e s t 2 , i n t e r e s t s i n t e r e s t 4 .
interests
, ,

interestl

interests

interest#

^
u p d ate .
, .

. -

001 SU 3STR
interests
.

UPDATE my_contacts SET


^ i n t e r e s t l = SUBSTRING_INDEX ( in t e r e s t s .

1)

in t e r e s t s = SUBSTR ( i n t e r e s t s , LENGTH ( i n t e r e s t l ) -1-2) ,


\

in t e r e s t2 = SUBSTRI NG_I NDEX(

^ i n t e r e s t s = SUBSTR ( ..................................................................... ) ,
in t e r e s t s = SUBSTRING_INDEX ( .................................................) ,
in t e r e s t s = SUBSTR (..................................................................... ) ,
in te r e s t4 = ......................................................................................
-T
^ in teres ts
, .
?

^
interests
, ,

380

interestl


.
interests

interests

interest#


- .
S E L E C T .
,
. .

File Edil Window Help TooM anyColumns

> SELECT i n t e r e s t l ,

in te re s t2 ,

I in te re s tl

I in te re s t2

{
{

\
{
\
\
1
1
1
1
1
!

1
{
!
1
1
1
1
1
1
1

I in te re s ts

1
1
1

in te re s ts ,

\
1
!
1
1
{
1
!

I in te re s t4

i
1
1
1
i
1

i
i
1
1
1
1

i n t e r e s t 4 FROM m y _ c o n ta c ts ,

, S E L E C T
:
SELECT interestl

FROM m y _ c ontacts;

SELECT

interests

FROM my_contacts;

SELECT interest2

FROM my_contacts;

SELECT

interest4

FROM my_contacts;

,
. , , !
VU

select profession, . 375:


SELECT profession

FROM my_contacts

GROUP BY profession

O R D E R BY p r o f e s s i o n ;

Ha select
interests.
select,
.

insert create.

, .

381

,
,

6 8 <.,?

( )
- ,
.

. ,
,
.
,
.
,
.

prof_id
profession

() CREATE SELECT u INSERT


I.

C REA TE TA B LE , IN S E R T SELECT
! t a b l e
.1 CRFATE, .
: ; 1, . SELECT . 375.

profession ::\
CREATE p r o f e s s i o n

i d IN T (1 1 )
p r o fe s s io n

VARCHAR

N O T N U L L A U T O _ IN C R E M B N T P R IM A R Y K Q Y ,
v a r c h a r (2 0 )

);

INSERT INTO profession (profession)


SELEC ^ p r o fe s s io n

FR C ^ m y _ c o n ta c t^

GROUP BY profession
OBBER BV p r o f e s s io n ;

3 ..

on

5| profession .,
SELECT.

382

2.

CREATE TABLE SELEC T, A LTER


: p r o f e s s i o n C R E A T E
SELECT,
profession m y contacts.
A L T E R ' 1 0 0 .

s
^

profession . :

CREATE TABLE p r o f e s s i o n AS ^
SELECT p r o f e s s i o n FROM my c o n t a c t s
GROUP BY p r o f e s s i o n
ORDER BY p r o f e s s i o n ;

- .

SELEC T

.
A L T b R

ALTER TABLE p r o f e s s i o n
.
ADD COLUMN i d IN T NOT NULL AUTO_INCREMENT F IR S T ,
ADD PRIMARY KEY ( i d ) ;

CREATE, SELECT u INSERT


3.

C REA TE TABLE u SELECT 6


A ;iTOT h:i oahoi'o : C R E A T E ;) p r o
'
V A R C H A R (|) ( iiii, |)' :1<
1 (> ! :;1':,'
,. A U T O _ I N C R E M E N T
1:1>/(, '1'o ( id
( , ( .., ( 1.1 .

CREATE TABLE p r o f e s s i o n
(

I t-


! p r o fe s s io n
.
^

p r o f e s s i o n '>, '
Jf-'
m oi -

i d I N T (1 1 ) NOT NULL AUTO_INCREMENT PRIMARY KEY S E l B C T


p r o f e s s i o n v a r c h a r (2 0 )
AS
SELECT p r o f e s s i o n FROM m y _ c o n ta c ts
GROUP BY p r o f e s s i o n
ORDER BY p r o f e s s i o n ;
AS.
,
,
.
, 8 .
,
:)!

AS

AS?
S E L E C T . ,
AS
, , my c o n t a c t s
S E L E C T ,
p r o f e s s i o n .
AS

,

, AS
,
, S E L E C T .



'^,
SELECT.


CREATE TABLE p r o f e s s i o n
VARCHAR
(
^ __i d I N T (1 1 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,

^ p r o f e s s i o n v a r c h a r (2 0 )
profession.
K o poiM K o e

^ 7 1 SELECT p r o f e s s i o n E^OM in y _ c o n ta c ts

GROUP BY p r o f e s s i^ T ^ ;^ - .^

ORDER BY p r o f e s s i o n
o m .:


p rofession
w\y_contacts.


s e l e c t
.6-

p r o f e s s i o n
,
,
p r o f e s s i o n .

profession
!
,
?


.
, SQ L
,
.

384


.
AS.
, p r o f e s s i o n m y _ c o n ta c ts
,
.
, my c o n t a c t s , mc_prof
( m y _ c o n ta c ts ).

CREATE TABLE p r o f e s s i o n

(
id

I N T (1 1 )

p r o f e s s io n

NOT NULL AUTO_INCREMENT PRIMARY KEY,

) AS

SELECT p ro fe ssio n AS mc_pro FRCM my_contacts


GROUP BY mc_pro
OM.EK BY = _ p r o I ;^

v a r c h a r (2 0 )

^^,


.




-
5 .


.

.
.
,
. , .
,
( p r o f e s s i o n ) ,
p r o f e s s i o n , m c_ p ro f.

m cprof

.
programmer
teacher
lawyer

programmer

.
-

teacher
lawyer

385

) ?
!
.
.
,
.
AS.
, my c o n t a c t s
.

SELECT p r o f e s s i o n AS m c p ro f
FROM m y _ c o n ta c ts AS me
GROUP BY m c _ p ro f
fr
ORDER BY m c p r o f ;
^

^v^a
^ ,
.
W

5
,
?

,
.

.
,
.

1. 0 -

SELECT p r o f e s s io n m c _ p ro f
FROM m y _ c o n ta c ts me
GROUP BY m c _ p ro f^
ORDER BY m c _ p ro f;

386

; 8


.

.

,
,
.
, .
, , ,



.

...



(
- !).

.
,


.

, :
, . ,
.

toys

boys

to yjd

b o y jd

1
2
3
4

1
2
3
4

'f

387



. :
t o y t o y s boy b o y s.

VT'

SELEC T
FROM

t .to y ,

to y s

CROSS
b o ys

AS

b .b o y
t

J O IN
AS

b ;

}
?
6,, 6,
.
.

\)
)


boys t o y
to y s .

to y s . toy

boys-boy

to y

-
^
^

'
^^^

.
^
.
20
(5 * 4 ),
.
.,

^ (
^ 0
hoys^

:; .

'

388


(CROSS
JOIN)



.

to y

^^ ^ L

<

BoIlJoCbl

,


. ,
. ,

.
, .

.


!

, CROSS JOIN
:

SELECT * F R O l t o y s CROSS J O IN b o y s ;
SELECT *7

SELECT toys.toy, boys.boy


FROM toys, boys;

. 20 ,
4 .


(INNER JOIN)
,


.

. ,
?

0:


, ,
- ,

.
- !

,
:
SELECT . ,
FROM b o y s

AS

2 .
CROSS J O IN b o y s

AS b 2 ;

389

^
iny_conlacls

co n tact_ id 0 ir
last_nam e
first_n am e
phone

prof*ssien

email

p ro f_ id

gender

profession

birthday
^ prof

id

zip _ cod e
statu5_id

SELECT . la s t _ n a m e ,
. fir s t_ n a m e ,
p .p r o fe s s io n
FROM m y _ c o n ta c ts AS me
INNER J O IN
p r o f e s s i o n AS p
ON m e. c o n t a c t _ i d = p . p r o f _ i d ;

390


g r e g s _ l is t : p r o f e s s io n m y _ c o n ta c ts .
, ,
, .

, , , .
.


4 -3 -1 4 7 8

--,

jeverettSm igM yum bal et

, ,

-% ~ 7

555 555- ^

tara@breakneckpizxa.com
, ,

5 5 5 5 5 5 -3 4 3 2

-,

ps@tikiheanlounge.com
,
5 5 5 5 5 5 -8 2 .

. ^

391

-^

m y_ c H ta cls
contact_id
last_nam e
first_nam e

g r e g s _ l i s t ; p r o f e s s i o n m y _ c o n ta c ts .
, ,
, .

phone

p ro fe s s io n

email
gender

profession

birthday
- p ro f_id
z ip _ c o d e ^ -^ status_id

SELECT . la s t _ n a m e ,

last^nam e
<<my^c6'niacis>>'(nce^

. fir s t_ n a m e ,

m e ) ........................................

u First_nam e mt^_contacts

p .p r o fe s s io n

p rofession
profession ( p)

FROM itY _ c o n t a c t s AS me

my_contacts ( )

INNER J O IN

p r o f e s s i o n AS p

profession ( )

0N . c o n t a c t _ i d

= p . p r o f_ id ;

,
1: _ ^ny_coniacts
11
profession

, , , .
.

la s l_ n a m e

392

firs f_ n a m e

p ra fo s s ie n


!
my_contacts.
SELECT,

!


, ?
.

,
.

.

,
.
.

,
.

SE1C T
FRO M

s o m e c o lijm n s

t a b le l

IN N E R

J O IN

t a b le 2

ucnoAt^^oeami?
^ ) 6

W H ERE.

ON

Mb/
,
.

s o m e c o n d x tio n ;
.

.

393

6 :
.
.
--, t o y _ i d .

boys

toys

b o yJd 0 -n r

boy

1
2
3
4

5
2
1

t o y j d
1
2
3
4
5

to y jd

, ,
.
=
b o y s t o y s .

SELEC T
FROM

b o y s .b o y ,

to y s . to y

J O IN

to y s
ON b o y s .to ^ _ id

t o y s . to y _ id ;

1 boys
b o y j d 0
1
2
3
4

[
. ,
/.

1<

394

Y h o y s.b o u .

boy

boys

IN N E R

to y

toys
lo y jd

lo y J d

1
2
3
4
5

3
5
2
1

boy

to y

to y



g r e g s l i s t .

, (e m a il) ( p r o f e s s i o n )
c o n t a c t s .

, (first_name), (la s t_ n a m e ) ( s t a t u s )
m y _ c o n ta c ts .

, (f i r s t
ra y _ c o n ta c ts .

name), (la s t_ n a m e ) ( s t a t e )

contact intorost

professiow

,contact_id

pro f_id (> rprofession

zip_ode

phone

z ip _ c o d e ( H -^

email

city

gender

state

birthda
pro f_id

sla iv s
status id
status

O+w

last name
first name

>zip _cod e
>status

id I

interest_id ^

0 + ir

interests
interest id
interest

contnct_oeicin9
contact id

+.

seeking_id
0

+w

seelting
seeking id

O w

seeking

395


g r e g s _ l i s t .

, (e m a il) ( p r o f e s s i o n )
m y _ c o n ta c ts .

SELECT mc.email, p.profession FROM my_contacts m e


INNER JOIN profession p ON m c .p r o f j d - p.profjd-,
p r o f j d
p r o f id
>^ profession.
, (f i r s t name), ( l a s t
( s t a t u s ) m Y _ c o n ta c ts .

name)

SELECT mc.first_namej mc.last_name, s.status FROM my_contacts m e


INNER JOIN status s ON m c .sta tu sjd - s.statusjd;
s t a t u s jd

s t a t u s j d sta tu s.
, ( f i r s t
m y _ c o n ta c ts .

name), ( l a s t name) ( s t a t e )

S ELECT mc.first_name, mc.last_name, z-state FROM my_contacts m e


INNER JOIN zipjcode z ON mc.zip_code = z.zip_code;
,
,
zip_code>
MY_cowt<ts
p ro f_id

O jr-

profession

contact id
last name
first name

xlp_odl*
zip_code

OJT

gender

state

birthda

status id

status

j:o n ta c t_ id

O+w
interest_id
0

+w

email

city

-interest idO jr
interest

cowtact_a00iclng
contact id

0 + ir

slalus

396

phone

c o n la clln te re sf

>zip _cod e

If

>status id

seeking_id
0

+ jr

6eeking_id
seeking

6 qeiiemBuu;
,
.
, b o y s t o y s . ,
, (
).
SELEC T

b o y s .b o y ,

to y s . to y

E T ^O M b o y s
IN N E R J O IN

to y s
b o y s . to y

qn

0W 5ER

BY

id

<>

__
M coedu.

to y s . to y

b o y s .b o jr ^

id

boys
b e y j d 0W

1
2
3
4

toys
to y id

to y jd

3
5
2
1

1
2
3
4
5

toy

boy

toy

K om ovbiy

397

>,

:
!.
.
, , ,
. .

boys
b o y j d -

boy

2
3
4

toys

'
lo y jd
3
5
2
1

to y jd 0 - ^
1
2
3
4
5

, ,
.

.

SELEC T

b o y s .b o y ,

to y

to y s . to y

FROM b o y s
NATURAL

J O IN

to y s ;

b o y j d 0 W
1
2
3
4

boy

to y jd
3
5
2
1

lo y jd 0 ^
1
2
3
4
5

M w


. 5 ,
W

,

398

. 8

boy

to y

to y


g r e g s l i s t
.

, (e m a il) ( p r o f e s s i o n )
m y _ c o n ta c ts .

, (f ir s t_ n a m e ), (la s t_ n a m e )
( s t a t u s ) , m y _ c o n ta c ts .

, (f ir s t_ n a m e ), ( l a s t
c o n t a c t s .

profeiew
p ro f_id
profession

last name
first name
phone

zip_code

0~^

city
state

status
status id
status

co n tactin terest

my_ceHtacts
contact id

name) (state)

,contact_id

1 -V

0 + ir

interest_id

0 + ir

email
gender
birthda

status id

interest

coBtqt_seeltiwg
contact id

0 + ir
> zip _cod e

interests
-interest id

seel<ing_id

0 + ir

seeitlwfl
5eel<ing_id
seel<ing

399

- ^

_ 1 1 1
.

, (e m a il) ( p r o f e s s i o n )
my_contacts.

SELECT mc.emailj p.profession FROM my_contacts me


INNER JOIN profession p;,

, ( f i r s t name), (la s t_ n a m e )
( s t a t u s ) , m y _ c o n ta c ts .

S ELECT mc.First_name, mc.last^name, s.status FROM my_contacts m e


INNER JOIN status s ON m c .sta tu sjd <> s.statusjd^

,
sta tu sjd .
, ( f ir s t_ n a m e ), (la s t_ n a m e ) ( s t a t e )
m y _ c o n ta c ts .

S ELECT mc.First_name, mc.last_name, z.state FROM my_contacts m e


INNER JOIN zipjcode z;

J-

..
^
^
^
^
^
ON
.
mv ontacis

p ro f_id

r-

contact id
last name

profession

first name
phone
zip_code

'

conlncl in leresi
,contact_id

0+ r
interest_id
0

email

city

gender

state

birthda

status idO I f
status

400

zipcode
fstatu sjd

interest

contacl_e*M ag
contact id
0

stains

in t*r sls
-interest id

+ ir

seeking_id

0+ ir

M h iag
6eeking_id
seeking

jr

.
.

,


.

.

,


,
.
,
.

>

401

? )

.
.

^
0 5

,


,
.
,
.

11

402

,


.

_11 1
501, .


contacts contact interest.

contact_seeking
seeking.

my_contacts, .

protosloii
p ro f_id profession

conlacl interest
contact id

lp_cde

phone

zip c o d e O ~ T r

email

state

slatu*
status idO
status

0+>r

last name
first name

city

.contact_id

gender
birthda

interest_id ^

0 + ir

>status_id

interest

contact_seeiting
contact id

zip_code

interests
interest id

+ ,

seeking_id

0 + ir

seeiting
seeking_id
seeking

403

gregs_list
801, .


_
contacts contact_interest.

S ELEC T mc.first_nam.ej m c.last_nam e, ci.in terestjd FROM my^contacts m e


INNER JOIN c o n t a c t jn t e r e s t ci ON m e .c o n t a c t jd = ci.co n tactjd ;
SELECT mc.first_name, m c.iast_nam e, ci.in terestjd FROM my_contacts m e
NATURAL JOIN c o n t a c t jn t e r e s t ci;

contact
seeking.

seeking

S ELECT * FROM contact_seeking CROSS JOIN seeking;

SELECT * FROM contact_seeking, seeking;

------- .
my

contacts,

S ELECT .profession FROM my_contacts


INNER JOIN profession p ON m c .p r o f j d = p .p ro f _ id GROUP BY profession
ORDER BY profession;

|1 1 1
p r o fjd
profession

IWy_0Wta*8
contact id 0 - - ^
last name
first name

ip_code
0 ~-ir

zip_code

city
state

phone

status idO sf
status

404

contact_id

0+w

interest

interest_id

0 + fr

-interest id

<

email
gender
birthda
p ro f_id

talH*

centacljnleresl

zip_code
status id

interest

contwct_seelting
contact_id

0+w

seeidna

seeking_id
0

+>r

seeking_id

seeking

^ !
,

, . yj , .
,
.
. ,
WHERE ON.
?

SQL
.
(,
INNER JOIN )
.
, .


ORDER BY. ,
?

(^ ,
GROUP BY, WHERE, SUM, AVG .

?
.
, ,

. g r e g s l i s t .

-
,
,

. ...

?
?

405

0 |<![013: 0'

'
;

?
Head First: ,
. ,
. ,
.
: ,
.
().

Head First: -! , .
, , .
? - ?

: ,
.

Head First: . ,
?
: . ,
, :
. last_nam e,

SELECT

: !

.p ro fe s s io n

, .
, ?

FROM

: . ,
:

. .
,
.
.

Head First: ,
, . ,
,
, .
,
.
: , . -,
.
Head First: ?
, .

406

: ,

m y_contacts

INNER

e ,

me

JOIN

p ro fe s s io n
WHERE

AS

.firs t_ n a m

AS

me.c o n ta c t_ id

p .id ;

Head First: ! ,
m y _ c o n ta c ts ,
. p r o f e s s i o n .
,

:ianpoc.
:
.
, ,
- .

Head First: ;> , .


.... .... ?


8 ,
SQL-.
.

III.

od
5

'

\ '^'^-


.

,

.


.

^
,


-




. >
,

.


^^K>eu^>

<^> 6 ^ ^ '

^.

sa^AenZ

407

. 378.

ALTER;
my_contacts .
interestl, interest2, interests interest4.

ALTER TABLE my_contact5


A P P (i n t e r e s t l VARCHAR(ZO), in teres ts VARCHAR(2-0),
interest3 VARCHAR(ZO),, in teres ts VARCHAR(20));


666

380

update. , .

SUBSTRIN G JNPEX SUBSTR:


SUBSTRIN G JNPEX
( ) * *
in te r e s t s , , SU/3STR
in t e r e s t s , UPDATE iny_contacts SET ^ , (->-2-) .

i n t e r e s t l = SOBSTRING_INDEX(interests,

1 ),

in t e r e s t s = SUBSTR ( i n t e r e s t s , LENGTH ( i n t e r e s t l ) -1-2) , ^


in t e r e s t2 = SUBSTRING_INDEX(

),

in t e r e s t s = SUBSTR(

),

interests, LENGTH(interestZ)+Z

in t e r e s t s = SUBSTRING_INDEX (

)'

in t e r e s t s = SUBSTR(,../interests, L E ^
in te r e s t4 =
.

.......................................
.



in t e r e s t s
.
^yintereats

sec-e^?.tbttd?iorth

408


in t e r e s t s
. ^
. in t e re s t s in t e r e s t ^
interestl

in terests

in terests

interest4

first

second

third

fourth

1|=1

, , .
,
.

. ,

. ( , !)


g r e g s _ l i s t
.
, .
,
,
.


,
!

, ,
,
.
my_con t a c t s ,
- .
-, ^_ta c ts
.
N U L L _
contacts.

-, - ,
) ,

.
,
.

410




, .

.

1^*^(
.

m y _ c o n ta c ts --,

.

411

, . W

"

'

7 ;

^. 0 -.

" - ''

: -
-
HTML & CSS

. ,
-,

,
,
.

: $95000-$105000

: 5+

(, ,


- 0 1 ^< 0 1 0

412

- J o 3bMM
,
.

|_1
contact id

iob_desired
contact id 0 " ^

iob_llsting
job

idO >r

title
salary

title

title

start date

salary_low

salary


>
.

salary_high

zip

available

description

years_exp

,

>
.

413


, .
p r o f e s s io n s ,
.
m y _ c o n ta c ts ,
, .

job_current.
SELECT t i t l e FROM jo b _ lis t in g s

till*
-
-

GROUP BY t i t l e ORDER BY t i t l e ;
^
BY, ^ ^ ^ /
.
!^, ^




joh_current.

^.
,
.

"it.

SELEC T m c.last^nam e, m c.first^nam e, .phone


FROM m y_contacts A S m e
NATURAL JOIN

joh_Aesired A S jd

m y_contacts job__desiVed
^ ^^

c o n t a c t e d ,
.

WHERE Jd.title = '- '


AND jd .sa ta ry jo w < 1 0 5 0 0 0 :
>

414

,
. sa la ry jo w
,
.

IN, ,
.
SELECT . first_ n a re e , me. last_nam e, me.phone, j c . t i t l e
FROM jo b _ cu rren t AS j c NATURAL JOIN m y_contacts AS me
WHERE
j . t i t l e IN ( ' - ^^^^-' ,
IN^
,
jc.title
.

' ' ,

' '

' ')


.
'

mc.ffirsl.iiame

mc.lasl name

.phone

|c.tille

(555) 555-3214
(555)555-8976
(555)555-4443
(555)555-5674
(555)555-0098

-
-
-

...


. .

>

415

nodjan/jocaMU

, , ,
.

,
p r o f e s s i o n s , ,
, . , .

^SELECT me. firs t_ n a ra e , m e.last_nam e, me.phone, j c . t i t l e

FROM jo b _ c u rre n t AS jc NATURAL JOIN m y_contacts AS me


WHERE
jc .title

IN

',

X.


,
.


,
j o b _ c u r r e n t . (
, !),

. , ,
;

B H V T P E H H U U
SELECT t i t l e FROM j o b _ l i s t i n g s

' '^


, <<
.
<< .



( ).

416

6
.
, .

B H V T P E H H U U

^
.

SELEC T
FROM
W HERE

m e . f ir s t_ n a m e ,

jo b _ c u r r e n t
je . t it le

AS

IN

jc

m e . la s t_ n a m e ,
NATURAL

(S E L E C T

J O IN

t it le

m e .p h o n e ,

j c .t it le

m y _ c o n ta c ts

FROM

jo b

AS

me

lis tin g s )

,
,

W H E R E , .

mc.first_name

m c.iast name

.
(555) 555-3214
(555)555-8976
(555)555-4443
(555)555-5674
(555)555-0098

'

,
. !
|.1

-
-
-

417

|^

:
, .
,
, .

).

SELEC T
FROM

C T O J i6 e L i; l ,

a r ^ th e r _ c o liim n

ta b le

W HERE

c o lu m n

(S E L E C T

c o lu m n

FROM

t a b le )

(^ .).
.

SELEC T
FROM

s o m e _ c o lu m n ,

a n o th e r

c o lu m n

t a b le

W HERE

c o l\a m n

(S E L E C T

c o lu m n

FROM



=,
,
( , S Q L
).

WHERE.

418

t a b le )

i'


.
'\ '..,:: -,,
. iaiMiC:.] /'ynv,,'
/,
. -

6
,
my c o n t a c t s .
z i p code WHERE.

(S E L E C T

z ip _ c o d e

z ip _ c o d e
' '

W HERE
AND

FROM

c ity

s ta te

=
T N ')

SELEC T

la s t_ n a m e ,

fir s t_ n a m e

FRO M m y _ c o n ta c ts
W HERE

z ip _ c o d e

(S E L E C T

z ip _ _ c o d e

z ip _ c o d e
' '


^y^contacts ~
, ^
( ).

W HERE
AND

FROM

c ity

s ta te

=
'T N ')

^
B o rijb C b i

, ,
,
. .

SELECT last_name, first_name


FROM my_contacts me
NATURAL JOIN zip_code zc
WHERE zc.city = ''
AND zc.state = 'TN'

>

419


, ,
- .
.

, .
,
, .
. ,
, .

. ,
,
,

?
, .

,
.

.

WHERE.

, .
?
.

WHERE,
. ,
.

. ,
.
.

, .
.

420


'21

,
. (
).


1>1

8 0 1

$ 0 1

421


, .

S Q L

SQ L

SELECT.

FROM

WHERE,

. ,

SELECT, SELECT

DELETE, UPDATE
SELECT.

INSERT,

3s

,,

- '

<
BoTljoCbl
?
?

,
.
(^ ?

!
,
.
.

. IN .
.

,
. 418 ?

, WHERE

J^^ae?
1 .

( =
) ,
.

422

!..
.

J
I

, , , ,

, mc.last_name.
- ?


.

SELECT.
.

.

First^name |^ my_contact5

fi\rstnam&i^^^

last_name>;
(5/ my_contacts

SELECT me. f i r s t _ n a m e AS f i r s t n a m e ,
m e.ph on e AS p h o n e,

jc .title

m c . l a s t _ n a m e AS l a s t n a m e ,

AS j o b t i t l e

p h o n e
^
my^contacts. fro m j o b _ c u r r e n t AS j c NATURAL JOIN m y _ c o n t a c t s ( ^ m c
---- ^ w here j o b t i t l e i n ( s e l e c t t i t l e from j o b _ l i s t i n g s ) ;
>
p h o n e .
'
^:

, !
AS
.
> !

- -


!6
,
lan^ocoM-.



.
.
^

firs ln a m *

iastn am *

phene
(555) 555-3214
(555)555-8976
(555)555-4443
(555)555-5674
(555)555-0098

ie b lille

-
-
-

423


, ,
(
).

. ,
( ),
.
,
, .



.
,
m y _ c o n t a c t s .
,
s a l a r y j o b _ c u r r e n t .

f i r s t _ ^ a ^ e
la st_n a m e
'^-Contacts.

MAX(salary)
^
Joh_current.

,
,
.
,
( s a l a r y ) :

SELECT M A X (s a la r y )

FROM j o b _ c u r r e n t ;

MAX?
,
, .

424

.
;
:

SELEC T

. fir s t_ n a m e ,

FROM m y _ c o n ta c ts

AS

m e . la s t_ n a m e

m e;
SwfopKa a .

, .
m y _ c o n t a c t s ,
( s a l a r y ) .

:

S E LE C T . f ir s t_ n a m e ,
nam e, je .s a la r y
FROM m y _ e o n ta e ts
N A T tJ R A L

J O IN

AS

m e. la s t

me

jo b _ e u r r e n t

AS

je ;




).
.

WHERE
.

,
,
: ?
q
/ .

SELEC T

m e . f ir s t_ n a m e ,

FROM m y _ c o n ta c ts
W HERE

jc .s a la r y

(S E L E C T

AS

me

m e . la s t_ n a m e , " ^ jc . s a l a r y
NATURAL

jo b _ e u r r e n t

AS

jc

M A X (jc .s a la ry )

FROM

jo b

,

salary.

.
Mc.first_naM*

J O IN

mc.lasl_iiaiii*

c u rre n t

j c ) ;

?
.

|.>1
187000

425

,
.

,
.


L I M I T .
SQ L ,
.

, ,
.

,
.
.
,

.

.

. 430?

426

SELECT

SELECT. .

SELEC T
(S E L E C T
FROM

m e.f

1r

St_ n a m e ,

m e . 1 a s t_ n a m e

s ta te

z ip _ _ c o d e

W HERE m c .z ip _ c o d e
FROM m y

c o n ta c ts

^
=

z ip _ c o d e )

AS

s ta te

-

sta te .

m e;

zipjcode.
:

my_contacts.
, 1 (

zip_code).
,
,
. .

mc.f irst_nam *

nc.lasl_name

11*

NY
NJ

,


SELECT,


.

>

427

:
.
, ,
. ,
.
SELECT

jc .s a la r y

FROM m y _ c o n t a c t s
WHERE e m a i l

me NATURAL J O I N

jo b _ c u r r e n t

jc

'a n d y 0 w e a th e r o r a m a .c o m ';

, .

, .
, :

one
>.

^ - ;
;


,
,
,

.

,
\
. ^ ___

sa la ry
.

:. f ir s t _ n a m e ,

m c .ia s t

nam e,

jc .s a la ry * ^

my contacts AS me NATURAL JOIN job current AS jc

>

428

( )

,
; .

,


.
?
,
.
5
.
.
ORDER BY, .
M c .f lr s t_ n a M *

M c .ia c t n a n *


- ,

46500

78000

48000

49000

120000

,
, .
,
WHERE .

,


,


; ,
.

.

, ^

\.

i .s a la r y

,
^.

).


.
>

429

- '

191-



Head First SQL: , SQ L .
, . ,
.
SQL: ?

?
, ,

.

Head First SQL: ... ,


.
.
,
.

!
.

Head First SQL: ,


?
?
SQL: . , .
,
.
Head First SQL: ?

SQL: ,

SQL: ,

.

.

:
.
,

. ,
.

Head First SQL: - ,


.

Head First SQL: . ,


, ?

SQL: .
- .

SQL: ,

Head First SQL: ,

,
... .

SQL: !

! , {)

Head First SQL: ,

.
.
.

SQL:

Head First SQL: ,


, .
, ?
SQL: , .
, .
430


.
...

Head First SQL:

-?

SQL: ..
Head First SQL: ,

SQL: .


,
. ,

.

Head First SQL: , SQ L . ,


...
SQL: .
.

.
, .
^

- j ob_current.
,
. , ,
.

-
job_current.

, -
job_current.

, -
job_current.

( ) ,
- , (
)

. select.

>

431

.
, .
^

- j ob c u r r e n t .
,
. , ,
.

-
job_current.
S ELECT AVG(saiary) FROM jo h _ cu rren t WHERE title = ' Be.5-';

__
AV6J.

, -
jo b _ c u rr e n t.

, -
job_current.
S ELECT mc.first_name, .last_name, Jc.salary
FROM my_contacts me NATURAL JOIN jo b_cu rren t jc
WHERE jc.title = '=';

a , ( ) ,
- , (
) .

. select.
.
S ELECT mc.rirst_name, .Iast_name, jc.salary,
,0^

'

^
***

'

jc.salary (SELEC T AVCi(satary) FROM jo b _ cu rren t WHERE title = '-')


FROM my_contacts m e NATURAL JOIN jo b_cu rren t jc
WHERE jc.title = '-';

432


: IN, NOT IN
, . 17.
,
. t i t l e ,
SELECT ,
j ob c u r r e n t .

SELECT . f i r s t _ n a m e ,

me. l a s t _ n a m e ,

m e .p h o n e ,

jc .title

FROM j o b _ c u r r e n t AS j c NATURAL JOIN m y _ c o n t a c t s AS me


WHERE j c . t i t l e

(SELECT t i t l e

FROM j o b _ l i s t i n g s ) ;

jc.title
no , .

NOT I N ,
. t i t l e ,
SELECT ,
j o b _ c u r r e n t . ,
. .

SELECT . f i r s t _ n a m e ,
FROM j o b c u r r e n t j c
WHERE j c . t i t l e C ^ T

me. l a s t _ n a m e ,

m e .p h o n e ,

jc .title

NATURAL JOIN my c o n t a c t s me
I ^ (SELECT t i t l e

FROM j o b _ l i s t i n g s ) ;

NOT IN . .


; IN NOT IN



\0
( )
,
, .

433

(
, ).
.

8 ^\
^\ , ^
.

, jo b_listings.

436

4 3 6 .

~1

-, (21_1)
I - - jo b_listings.

. 4 3 7 -

, (zip code)
, .

434

-jjiaea 9

iob_curreiit

iob.desired

contact id
title
salary_low
salary_high
available
years_exp

title
salary
start date

iob_listings

job_id
title
salary
zip
description

contact Jn te r e s I

contact_id ^
my_conlacts

contact id
last name
first name
phone
email
gender
birthday

profeasion

prof_id 0~ne
profession
sip_code

zip_code
city
state

>

prof _ id '
zip_code I

states

status_id 0 'wstatus

0+?r
interest_id

0+r

interests

interest id
interest

contact_seeking

contact_id ^
0 + jT
seeking_id
0+5

seeking

seeking_id
seeking

status id'
1

>

435

(
, ).
gregs_list.

, j ob_listings.

MAX(salary).

SELECT title FROM jobjistings

WHERE salary = (SELEC T MAX(salary)


FROM Jobjistinas);

MAX .

.

, sa la ry
.

SELECT mc.first_name, m c.lastjnam e


FROM my_contacts m e
NATURAL JOIN Jo b_cu rren t jc
WHERE jc.salary > (SELEC T AVG(salary) FROM job_curirent);

I
I



( ,
'
^
,
^^ .

__

436

__

__

__

__

__

__

__

__

__

__

__

__

__

-, (zip code)
- - job_listings.
HWX ( , , )
.
S ELECT mc.first_nam e, m c.ia stjn a m e, mc.pWone FROM my_contacts m e
NATURAL JOIN jo b _cu rren t jc WHERE jc.title = 'web designer' A N P mc.zip_code
IN (S E L E C T zip FROM jobjistings WHERE title = 'web d esigner);

, (zip code)
, .


. ,
IN .

, my_contacts.

, IN.



^,-

^ .

SELECT last_name, first_^name FROM my_contacts

WHERE zip_code IN (S E L E C T mc.zip_code FROM my_contacts me

NATURAL JOIN jo b_cu rren t jc


WHERE jc.salary = (S E L E C T MAX(salary) FROM job_current));


job_current.
, =.

>

437


^

, ,
-
.

.
(
)
.
,

.

i n t e r e s t m y _ c o n t a c t s ,

.

SELEC T

m e . fir s t_ n a m e ,

FROM m y _ c o n ta c ts

AS

m e . la s t_ n a m e

me
my_contacts
.

W HERE
3

SELEC T
W HERE
) ;

COUNT(*)
c o n ta c t

id

FROM
=

c o n ta c t

m e .c o n ta c t


i^ceudoHuM me.

in te r e s t
id

mc.contact_
((
,

.

.
,
c o n t a c t _ i d .
my c o n t a c t s ,
.

438

: 9

NOT EXISTS

,
.
,
.
my c o n t a c t s ,
jo b_cu rren t. NOT EXISTS.

SELECT me. first_n am e firstn a m e , m c.last_name lastnam e, me.email email


FROM nqr_contacts me

EXISTS
,

WHERE NOT EXISTS
6 ^
(SEI.ECT .
jo b _ c u rre t J c
^

'

WHERE me. eo n ta e t_ id = j e . co n ta e t_ id ) ;

^ ^

1 ?

, .

m e. f i r s t _ n a m e f i r s t n a m e
WHERE NOT EXISTS
WHERE me. c o n t a c t _ i d =
j e . co n ta e t_ id

me. l a s t _ n a m e

c o n t a c t

i d ,

f i r s t n a m e

FROM m y _ e o n t a e t s me
j

m c .la st_ n a m e la stn a m e


e m a i l

SELECT * FROM
jo b _ c u r r e n t j c

m e .e m a il e m a il

my e o n t a e t s

439

EXiSTS/NO T EXISTS

EXISTS u NOT EXISTS


IN NOT IN,
E X IS T S NOT EXISTS.
my c o n t a c t s ,
c o n t a c t i d
c o n t a c t _ i n t e r e s t .

SELECT me. first_n am e firstn a m e, me.last_name lastnam e, me.email em ail


EXISTS , , my_contacts,
4 ^ ^ c o n t a c t jd
co n ta ctjn terest-

FROM my_eontacts me
WHERE EXISTS

(SELECT * FRCM e o n ta ct i n t e r e s t c i WHERE m e.con taet id = e i.e o n t a c t id ) ;

, .
me. f i r s t _ n a m e f i r s t n a m '
WHERE NOT EXISTS
WHERE me. c o n t a c t _ i d =
j c . c o n ta ct_ id

m e. l a s t _ n a m e

c o n t a c t _ i d ,

f i r s t n a m e

FROM m y _ e o n t a e t s me
j

m c.la st_ n a m e lastn am e


e m a i l

440

SELECT * FROM
jo b _ e u rre n t j e

m e .e m a i l e m a i l

m y _ e o n t a e t s

^ ------------------------------------------------------------------------------
, ,
j o b _ c u r r e n t .

444.

441

)

.
INSERT, UPDATE DELETE.


, .

,


job_desied...

'^
B o n jb C b i

, ?

.
,
.

?

.
. ,
-,
:
-
,
.

442

,
?

, ,
- ...


. 6... . . ...... ...

[ ( !^ [ ^ < ) !? ^ ^

, ,
, ... .



In q u eIy er ,
.

.
, , ,
.
, ,
,
,
? !
,
11
.

?
.
443

sql

9
.
, .
III.

,
(
).

>

!^

,
cede

.

*,
,

. 441.


, ,
j o b _ c u r r e n t .

S E LE C T me.email FROM my_^contacts m e W HER E


EXISTS
(S E LE C T * FROM c o n t a c t jn t e r e s t ci W H E R E m c .c o n ta c t J D = ci.contactJP )
AND

----------

N O T EXISTS

W HER E AND.
(S E LE C T * FROM jo h _cu rren t Jc
W H ER E m e .c o n t a c t jd = J c .c o n t a c t j d ):

444

10

^ , 1 8 1

,
. ,
, ,
.
, ,

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


professions.
,
. ,
my_contacts?
.


.
, ,
, .

.
,
.
,
. ,
t o y i d :

SELEC T
FROM
IN N E R
ON

g .g i r l ,

g ir ls
J O IN

g . t o y _ id

g ir ls

gIrMd

girl

1_

1
2
3

3
4
1

t .to y

g
to y s
=

t . to y _ id ;




toy^id.

, 01.

446

"10

girl

to y s

lo y jd

1
2
3
4
5

6
7
8

; ...
,


,
.

(LEFT OUTER JOIN)


.
,
--.
,
, ,
.
,
FROM, JOIN, ,
, JOIN,
.





.
,

.

1,

. ^

447


,
.

. g i r l s
FROM, ;
LEFT OUTER JOIN; ,
to y s .

,
(girls)
(toys).

SELEC T g . g i r l ,
r r i i - l
g x r iS g < r
LEFT
ON

OUTER

t .to y
girls LEFT OUTER
j o i n , .,.

J O IN

g . to y _ id

to y s

t .to y _ id ;

girls
l e f t o u t e r j o i n ,
...

1^, toys,
LEFT
o u t e r JOIN, .

V
toys

g irls
g irijd

to y jd

1
2
3

........ V

le y j d
/

----------3
4
5

< ;

6
7

,
.

448

10

"^

^
!
/

/
/

fe y

? ,
? ,

.

:
,
.
NULL.
NULL ,
.
!

NULL
,
,
.
^

, , ,
.

SELECT g . g i r l , t . toy
FROM toys t
LEFT OUTER JOIN g i r l s g
ON g . to y _id = t . to y _ id ;

(.
8 .)

449

^Jo3bMM
^

. , ,
, .

SELECT . g i r l , t . toy
FROM toys t ^
LEET: OUTER JOIN g i r l s g
ON g .to y _ id = t .t o y _ id ;

toys
( ) girls
( ).

toys
lo y jfl
1
2
3
4
5
6
7
8

toy


,
.

,
6
, ,
NULL.

450

10

g ir ls
gM Jd
1
2
3

g irl

l o y jd
3
4
1

I
g iri

NULL

NULL
NULL
NULL
NULL

le y


50 .
~


<^ .

.
, , g irls toys
, .

Mbi .

giri

1*

NULL

girls
q irU d

Z
3

girl

to iJd
1
Z
3


giri

toy

Jen
Cleo
NULL
Sally
Martha

451

.
, , g irls toys
, .

/
'^

S ELEC T g .g ir i t.toy
FROM girls g
LEFT OUTER JOIN toys t

fy

NULL

ON g .t o y jd - t.to y jd ;


toys
girls

q ir ljd

to Jd

t o y jd
1
2.

7.

toy

77 3


t o y j d ,
toys, toy
NULL.


,
.

SELEC T g.girl, t.toy


FROM toys t
LEFT OUTER JOIN girls g
ON g .t o y jd - t.to y jd ;

NULL ,


.

t o y jd
%

10

Jen
Cleo
NULL
Sally
Martha

fo y

toys

452

,
,.
.

toy

girls
cjirljd

3
4

'

t o y jd

1
3
3

)
SELECT g . g i r l , t . t o y
FROM t o y s t
LEFT OUTER JOIN g i r l s g
ON g . t o y _ i d = t . t o y _ i d ;

,

,
.
:

toys
lo y jd
1
2
3

g irls
lo y

flM Jd

f e y jd

------------ ^---------- =>'


----- ----- 2----------

1
1
3
3

---------- 3------------------ -------- 4_______ -=->

( t o y s ) ( g i r l s ) : t o y s . t o y i d
g i r l s . to y _ id = 1

= 1,

.
( t o y s ) ( g i r l s ) : t o y s . t o y _ i d
g irls .to y _ id = 1

= 1,

.
( t o y s ) ( g i r l s ) : t o y s . t o y
g irls .to y _ id = 3

id

= 1,

.
( t o y s ) ( g i r l s ) : t o y s . t o y
g irls .to y _ id = 3

id

= 1,

.
( t o y s ) ( g i r l s ) : t o y s . t o y _ i d
g irls .to y _ id = 1

= 2,

.
( t o y s ) ( g i r l s ) : t o y s . t o y _ i d
g irls .to y _ id = 1

= 2,

.
( t o y s ) ( g i r l s ) : t o y s . t o y
g irls .to y _ id = 3

id

= 2,

.
( t o y s ) ( g i r l s ) : t o y s . t o y
g irls .to y _ id = 3

.
, NULL.

id

= 2,

>

"

( t o y s ) ( g i r l s ) : t o y s . t o y
g irls .to y _ id = 1

NULL

i d = 3,

.
( t o y s ) ( g i r l s ) : t o y s . t o y _ i d
g irls .to y _ id

= 3,

= 1

.
( t o y s ) ( g i r l s ) : t o y s . t o y _ i d
g irls .to y _ id

= 3,

= 3

.
( t o y s ) ( g i r l s ) : t o y s . t o y

i d = 3, g i r l s . t o y _ i d

= 3

453




, ,
.

.

SELEC T

select

FROM

to y s

R IG H T
ON

g . g ir l,
t ^

OUTER

g . to y _ id

t . t o y

g.giri,

. .
^
.

J O IN
=

g ir ls

t.toy

^ .
LEFT OUTER JOIN to y s t

t.to y _ id ;

ON g .t o y _ i d = t . t o y _ i d ;


. 448.


( ).

g ir ljd
1
2
3


girls
.

X ^
toys

g irls
g irl

lo y jd
3
4
1

lo y jd
1
2
3
4
5
6
7
8

454

10

giri

).

le y

<
1>1

?
LEFT
RIGHT ,
.

.
,

(, )
.
.


,
,
?
! ( )
,
.
MySQL, SQL Server Access.

>

455


,
?
.



.

,
.
,
.

, ...

456

10

...

,
.
,
,

.


.
(
, ).

.
,
.

deccripfieii

id

info_aclivifie

4-

gender
description
when

activity_id

> id
clown info

activities

activity_id

activity

id

name

infojocalion

location

location id
location id

location

when

UTVPM
,


?

,
? ...
, ?

.
\6 u ^

457

clown_boss



.
.

10
5

^
8

2
9

'


^
4


1 _ 1 .

c lo w n b o ss
id
1
2
3
4
5

7
8
9
10

458

1C

b o s a jd
3
5
10
3
10
3
3
5
5
10

1 _
1 ;^ _ 1
-- .


, .
b o s s j d
,
NULL
.


.
?

descri ption

id

info_activllles

4-

gender
when

activity_id

> id
clewn info

activities

activity_id

activity

id
name

clewn boss
id

infe location

> i d ^ - T r
location id

055 id

iocatien

location_id

location

when
.
-- 11 ( )
-- _ 1 1 . ,
1_.

,
--.
,
?

459


c l o w n i n f
,
.
. b o s s id ,
c lo w n _ b o s s .
c lo w n _ b o s s b o s s i d
. c l o w n _ i n f
,
. ,
, .
,
, b o s s i d
c i d .


, .

, 59_!(>:


clow nJnfo.

.


,
.

clown in fo
id
1
2
3
4
5
6
7
8
9
10

460

10

nan*

* < | < 3
5
10
3
10
3
3
5
5
-----------

i d

,


.

b 0S S Jd
^
.


,
.
SELECT:
SELECT nam e,

b o ss _ id

nan*

FROM c l o w n _ i n f o ;

H o .

, c l o w n _ i n f o l c l o w n _ i n f o 2 .

.

clown ino2

clown in f o l

1
2
3
4
5
6
7
8
9
10

b>a_id
3
5
10
3
10
3
3
5
5
10

id
1
2
3
4
5
6
7
8
9
10

n am *

bss_i<>
3
5
10
3
10
3
3
5
5
10

>

461

'

, 1 _ 1 1 1 _ 1 2 .

.

clown in f o l

1
2
3
4
5

7
8
9
10

name

clown in fo2
b e s s jd
3
5
10
3
10
3
3
5
5
10

id
1
2
3
4
5
6
7
8
9
10

name


SELEC T c l . n a m e , cZ .n a m e AS boss
FROM c l o w n j n f o l c l
INNER JOIN ciow nJnfoZ cZ
ON c l . bossJ d - cZ.id;


b o s s j d
clo w n Jn F o l i d
clow nJnfoZ.

462

10

HUM boss.

bes*_id
3
5
10
3
10
3
3
5
5
10



.
.

.
,
.

SELEC T
FROM
IN N E R
ON

c l.n a m e ,

c lo w n _ in fo
J O IN

c l.b o s s

c 2 .n a m e

b oss

c l

c lo w n _ in f o
id

AS

c 2 .id ;

clown In fo
id
1
2
3
4
5
6
7
8
9
10

n am *

besJ<i
3
5
10
3
10
3
3
5
5
10

c2
(5 clo w n jn fo
0, c l ( bossjd) cZ (
).


clown_inf ; 1 ,
2. _ 1 1 ( 1 )
( 2 )
' .

name

boas

^ bossJd
clownjnfo ( c l )
,
clownjnfo (cZ).


,

,
.
>

463



, gegs_list.
,
?

, .

-
-

^ocmynHbic,
.

ieb_dsird
contact id 0^

|*b_CH rriit
contact idO

ieb jislin g*
job idO >r

^ S - ir
title
salary
start date

title
salary low
salary high
available
years exp

title
salary
zip
description

SELECT:

SELEC T

t it le

FRO M

jo b _ c u r r e n t;

SELEC T

t it le

FROM

jo b _ d e s ir e d ;

SELEC T

t it le

FROM

jo b _ lis t in g s ;

,
,
.

464

10



( UNION) .

job_desired.

job_curtrev^



, SELECT.

.

SELECT t i t l e FRC4 jo b _ cu rre n t


UNION
SELECT t i t l e FROM jo b _d esired
DNKMI
SELECT t i t l e FRCM j o b _ l i s t i n g s ;

U N IO N

1
S E L E ^

/-

UN IO N

^


'
,

,
,
,
ORDER
BY SELECT.

jobjistings-

litle


,

- V

.

SELECT t i t l e FROM jo b _ cu rre n t ORDER BY t i t l e


UNION
SELECT t i t l e FROM jo b _d esired ORDER BY t i t l e
UNION
SELECT t i t l e FRCi jo b _ lis tin g a ORDER BY t i t l e ;

ORPER BY
6 ,

.

,
?

>

465


!
, ,
ORDER BY.

UNION
ORDER BY . ,


SELECT.
, .

6 SQL

s e l e c t

.


.

SELECT

.

SELECT
;
.

466

10

\(, 5 8 SQL
SQL


,
.


,
UNION ALL.
,
.


SELECT
.
.

, SELECT

aoaohoO.
.

SELEC T ( titl^ F R O M

jo b _ c u r r e n t

U N IO N
SELEC T

FROM

jo b _ d e s ir e d

U N IO N
SE LEC T ( ^ it ^ F R O M
ORDER

BY

jo b _ lis t in g s

t i t l e ;
,
ORDER BY
SELECT.
HUho .

titi*

^^, KomoptPie
^
.


VARCHAR. ,
, VARCHAR.

UiTVPM
, ,

?

467

U N IO N ALL

UNION ALL
UNION ALL , UNION,
,
.

SELEC T
U N IO N

t it le

FROM

jo b _ c u r r e n t

FROM

jo b _ d e s ir e d

FROM

jo b _ lis tin g s

A LL

31^01^ Mt>i

SELEC T

, , tit le
-

U N IO N

t it le
ALL

SELEC T
ORDER

t it le
BY

t i t l e ;

title

468

10



.

.
,
, ,

; ,
.
, INTEGER
VARCHAR. VARCHAR
,
INTEGER
VARCHAR.


, ,
- . CREATE TABLE AS
.
CREATE TABLE AS S E L E C T
. t i t l e
m y _ u n io n .

CREATE

TABLE

m y _ _ u n io n

SELEC T

t it le

FRO M

jo b _ c u r r e n t

SELEC T

t it le

FRO M

jo b _ d e s ir e d

SELEC T

t it le

U N IO N

AS

FROM

U N IO N


.



SELECT.

jo b _ lis t in g s

^
c o n t a c t _ i d ( j o b _ c u r r e n t )
s a l a r y ( j _ 1 i s t i n g s ) .

, ?
CREATE TA B LE AS .

DESC
.

QjnBero .

479.

>

469

INTERSECT EXCEPT

INTERSECT u EXCEPT

INTERSECT EXCEPT,
UNION,
.

.....................................................

^
)11^
I
!


MySQL.

INTERSECT
,
.

j o k c u r r e n t

job_desired.

SELECT t i t l e FROM jo b _ cu rren t


INTERSECT
SELECT t i t l e FROM jo b _ d e sired ;



,

.

EXCEPT ,
,
.

/\ job.xuirrent.

SELECT title FROM job_Current

job_desired.

e'

EXCEPT
SELECT t i t l e FRCai jo b _ d e sired ;

,
',
EXCEPi

470

. 10

, .^' .

, ...
, .
,
. .

( .... ...)


, ,
.
9.

1>. , ,
.

1> . - .

,
p r o f e s s io n s , ,
- ), . , .

+ < ia a ip

^ ^^
-

$,^^,.^

no, .isc.la*t_natBe, .phone, J c . e it l*


job _current

/ J c . t i t l e IN (

QV1

tf 3^ ^o:hanpoc.OA

S j c HhTOBAb JDIH By^oontacta AS me

SELECT me.first_name, me.l a


FROM job_current AS jc NATURAL JOIN my_contacts AS
WHERE jc.title IN (SELECT title FRCW job_liatings)

ianvoc.

^.

OVJlMetV' '.'-
)
- ,
jo b _ c u r r n t. (
. [).
. , .

SEL8CT t i t l e FROM jo b _ ll t n g a


, <<>>
.
' << .

*.>& ia-r^cc^

},

,
, .^

WHERE, .

u .ttM t

XvdH

J m Aj m h m

KOftVX*

.*1
555) 555-3214
555)555-8976
555)555-4443
555)555-5674
555)555-0098


hv
^anaorcubf

-
-
-

471

6
, 9, .

SE L E C T m e .f i r s t _ n a m e , m e .l a s t _ n a m e , m e .p h o n e , j e .title
F R O M j o b _ e u r r e n t AS je N A T U R A L J O I N m y _ e o n t a e t s AS m e
W H E R E je . t i t l e IN

(SELECT title F R O M job listings)


/

HC.firsl_nain*

inc.lal_naiN *

m c.p h e n *

i c .l i l l *

(555) 555-3214
(555)555-8976
(555)555-4443
(555)555-5674
(555)555-0098

-
-
-

- ^
WHERE,
.

SELECT .first_name, me.last_name, me.phone, jc.title


FROM job_current AS jc NATURAL JOIN my_contacts AS me
INNER JOIN job_listings jl
ON jc.title = jl.title;

WHERE

.

, IN N E R J O I N , .

472

10

.

?


, ,
.

.. .

> ?

,
.
, -
.

, ?
.
,
.

.
, .

?

. ...

, ;
.
,
.
|J>ooeue 1 ] .

473

:
U . ?

,
. .
,
.
,
.

,

WHERE . ,

.
.

, , ,
, .
,
.
, ,
.
:
.
,
.
, - ?
,
?
, .

... . ,
.
UPDATE, I N S E R T D E L E T E .
.

474

10

9 ,
.

, job lis tin g s .


SELECT

title

M A X (sa la ry )

FROM j o b _ l i s t i n g s
FROM j o b

WHERE s a l a r y

(SELEC T

lis tin g s );

.
SELECT

. first_ n a m e ,

NATURAL J O I N
A V G (sa la ry )

m c .la s t_ n a m e

jo b _ c u r r e n t

jc

FROM m y _ c o n t a c t s

WHERE j c . s a l a r y

>

me

(SELEC T

FROM j o b _ c u r r e n t ) ;

475

9 ,

, job lis tin g s .


SELECT

tit le

M A X (sa la ry )

FROM j o b _ l i s t i n g s

WHERE s a l a r y

(SELEC T

FROM j o b _ l i s t i n g s ) ;

S ELECT title FROM jobjistings


ORDER BY salary DESC LIMIT X:


.
? ....... ...........................................

.
SELECT . f i r s t _ n a m e ,
NATURAL J O I N
A V G (sa la ry )

m c .la s t_ n a m e

jo b _ c u r r e n t
FROM j o b

jc

FROM m y _ c o n t a c t s

WHERE j c . s a l a r y

>

me

(SELEC T

cu rren t);

,
ucnooamt? LIMIT ORDER BY.

476

10


LIMIT
....: .................... ^!^1_
.


LIMIT .

,

.


, .

clown info

nam*

boss

b o s s

1
2

3
4

3
5
10
3
10
3
3
5
5
10

id ,

c l o w n _ i n f ? ,
c l o w n _ i n f o c l 2.

5
6
7

SELECT c l . n a m e ,

c 2 . nam e AS b o s s

8
9
10

FROM c lo w n i n f o

c l

------------ -

IN N E R J O IN c l o w n _ i n f o
ON c l . b o s s _ i d

c2

clow njnfo.

= c 2 .id ;


clow njnfo.


,
, ,

b o ss

i d SELECT.


SELECT.

SELECT c l . n a m e ,

/1

(S E LE C T nam e FROM c l o w n _ i n f o
WHERE c l . b o s s ^ ^ id ^
ROM c lo w n i n f o

AS b o s s

c lT \


bo ssjd,
.

>

477

11?


.
,
.

, ,
. ,

, SQ L.

478

10

. 469.

c o n t a c t _ i d ( j o b _ c u r r e n t ) s a l a r y
( j o b _ l i s t i n g s ) .

S ELECT c o n t a c t jd FROM job^curirent UNION


S ELECT salary FROM Jobjistings;
, ?
C R EA TE T A B L E AS .

CREATE TABLE myjtable SELECT c o n t a c t j d


F^OM jo b_ cu rren t UNION S E L E ^ sala^^^^
Job J istings;
D ESC
.

D EC(1Z,Z)

WHERE,
:

SELECT m e .first_name, m e .last_naine, me.phone, jc.title


FROM job_current AS jc NATURAL JOIN my_contacts AS me
INNER JOIN job_listings jl
ON jc.title = j1.title;

WHERE

.

, IN N E R J O I N , .

Jc.title = Jl.title , WHERE :


WHERE jc.title IN (S E L E C T title FROM Jobjistings);
?


! , ,,
^ .

479

s q l


SQL .
,
, , .

::?

III.


lo T T f

,
.

6
'

Sftirvucu
U
'

^ ' ^

3ai^wceu
^


UHION

5-

^^'

CAU
6

'?'^^^ ^

CKV0C05 JZ c a <


.

,.

in t e r s e c t

K O K C l^p y*^'

create

table

as

,

SELECT.

480

10



,


.


.
.

.
except


, .
.

11

0^!,

,
, ,
SQL, . ,

, ,

. .
, 1.

^
,

)
SQL... ^
, per . J

,

.

,

.

jo b _ c iirr4 it

jo b _ d e s lr e J

contact id

|*b_ntiiia

contact id

title

title

salary

salary J e w

job_id

title
salary

salary_high

start date

zip

available

description

years_exp

co n la cl in lo ro st

in le r e s is

contact_id

Hiy_cHtats

0 + ir

1
^

interest_id 0 jr
interest

interest_id

p ro fessio n

first name

profession

phone
email

zip^codo
zip_code 0 -

gender
birthday

city

p ro f_id

state

-zip_code

s la lu s
status id 0Tfstatus

482

11

0+

last name

p ro f_id 0 ~ ) r

>status_id

se e k in g

11_1
contact_id

0 + ir

seeking_id

0+r

seeking_id
seeking

:
.

:
?

^, .

, .

' , 555-1239, patmurphy@someemail.com,


10087

^^ 15/4/1978/^

, .
, SELECT
.

( :)
!

X*

OiTVPM

483

] NULL
,

,
NULL
, ,

.


? ,
.
g e n d e r X.

, :

prof_id profession.
SE L E C T p r o f _ i d

FROM p r o f e s s i o n

WHERE p r o f e s s i o n

' ';

,

,


_$.

prof_M
19

status_id status.
SELECT

sta tu s_ id

FROM p r o f e s s i o n

WHERE s t a t u s

s t a le s id

M y_ciitats

contact id
last name
first name
phone
email
gender
birthday
prof_id
zip_code
status id

X gender.

AU TO JN C R EM EN T
.
,
.
IN SERT

IN TO m y _ c o n t a c t s

'5 5 5 1 2 3 9 ',
19,

VALUES('

'1 0 0 8 7 ',

11

'X ',

' '
1 9 7 8 -1 5 -0 4 ,

3);

,
.

.

484

' ' ,

'p a tm u r p h y @ s o m e e m a il.c o m ',

,

g e n d e r
NULL.


.
, my

c o n ta c ts ,

.
.

SELECT

COUNT(* )

AS

F e m a le s

COUNT(* )

AS

M a le s

M ales
6982

SELECT

COUNT(* )

FRO M

AS

m y _ c o n ta c ts

WHERE

gender

' ';

__6, my^contacts 5 9 7 5
g e n d e r .

Females
5975

SELECT

FRO M

T o ta l

Total
12970

FR O M

m y _ c o n ta c ts

WHERE

gender

'M';

6 9 82. .

m y _ c o n ta c ts ;

, .
13 , ,
. :
SELECT
WHERE

gender
gender

FR O M
<>

'M '

m y _ c o n ta c ts
AND

g der
^

gender

<>

'';

S
3-3 ,
g e n d e r X .



X?
X
X

485

check

CHECK

.

,
.
NOT NULL, PRIM A RY KEY, F O R E IG N KEY UNIQUE.

(CHECK). ,

,
.
1, 5 , 1 0 2 5 ,
, N , D Q .
CHECK ,
c o in .

CREATE TABLE p ig g y _ b a n k

CHECK
,
M oiyr

.


,
WHERE.

id

IN T AUTO_INCREMENT NOT NULL PRIMARY KEY,

c o in C H A R (l)

CHECK ( c o in IN

( ' P ' , ' N ' , ' D' , ' Q' ))


-------------- ----------------------

_
.

,
, CHECK,
.

I
>1:>1!

CHECK
MySQL.

MySQL
CHECK,
. MySQL .

486

11

CHECK gender
,

m y _ c o n t a c t s CHECK g e n d e r .

, A L T E R TA B L E .

A LTER TABLE m y _ c o n t a c t s
ADD C O N STR A IN T CHECK g e n d e r I N

('','');

H a ,
, g e n d e r X.
.
,
X , .


, .

C R EA T E

TABLE m y s t e r y _ t a b l e

(
co lu m n l

I N T (4)

co lu m n 2

CHAR( l )

co lu m n s

VARCHARO)

CHECK

('A'

SU B ST R IN G ( c o l u m n _ 3 ,

1,

1)),

co lu m n 4

VARCHARO)

CHECK

('A'

SU B STR IN G ( c o l u m n _ 4 ,

1,

1)

AND

= S U B S T R IN G (co lu m n _ 4,

'9 '

CHECK
CHECK

(co lu m n l

> 200),

(colu m n 2

NOT

2,

IN

('x',

'y',

'z ')),

1))

c o l u m n l : .............................................................................................................................................................................

c o l u m n 2 : .............................................................................................................................................................................

c o l u m n 3 : .............................................................................................................................................................................

c o l u m n 4 : .............................................................................................................................................................................

>

487

- ^

C R EA T E

, .

TABLE m y s t e r y _ t a b l e

(
co lu m n l

IN T (4 )

colu m n 2

C H A R (l)

co lu m n s

VARCHARO)

CHECK

('A'

= SU B ST R IN G ( c o l u m n _ 3 ,

1,

1)),

co lu m n 4

VARCHARO)

CHECK

('A'

= SU B ST R IN G ( c o l u m n _ 4 ,

1,

1)

AND

= S U B S T R IN G (co lu m n _4 ,

'9 '

..^

l u m n 1:

c o l u

(co lu m n l

CHECK

> 200),

(colu m n 2

NOT

2,

IN

('x',

'y',

'z ')),

1))


A N P OR-

c o l u m n 2 :

CHECK

. 9

. .

.............................................................................................................................

.\9.!,_^^^
m

s -

c o l u m n 4 - ^ ^ / ? ^ * ^ '^

.............................................................................................................

6mof?biM i^ucjojpa 9

^
11>1
, CHECK , NHERE7

, CHECK, .

.
: AND, OR, IN, NOT, BETWEEN .,
, . , -

\)'

, -

CHECK?

,
.
CHECK MySQL,
?
?

,
.

488

11

,
.


.
:
- ,
.
, .

,

-------



, .
.


anJ^c, ]=*

|= ^ naulJL
1 1.
><>
*

489

> <|>]=*
, ]=> >
.

S ELEC T Mc.fiVst_name, mc.iast_


, .p h o n e, .email
FROM my_contacts
NATURAL JOIN joh_desired j d
WHERE jd.title = 'B ed -':

]=*
JoL_Jeie<l
1 . | | *1^
*
.

S E L E C T title, salary, description,


zip
FROM Jobjistings
WHERE title - '
';

,
, -
. ,
,
.

> I
,

, .


.
,

.
.

490

11


]
CR EA TE V IEW .
.

CREATE V IE W w e b _ d e s ig n e r s AS
SELECT m e . f i r s t _ n a m e , m e . l a s t _ n a m e , m e . p h o n e , m e . e m a i l
FROM m y _ e o n t a e t s me
NATURAL J O IN j o b _ d e s i r e d
H ER E j d . t i t l e

jd

. - ';

CREATE V IE W t e c h _ w r i t e r _ j o b s
SELECT t i t l e

s a la r y ,

AS

d e s c r ip tio n ,

z ip

FROM j o b _ l i s t i n g s
WHERE t i t l e

' ';


!
,
? ^__



SQL,
?

491

SELECT


w eb

d e s ig n e r s .

CRE1ATE V IE W w e b _ d e s ig n e r s AS
SELECT m e . f i r s t _ n a m e , m e . l a s t _ n a m e , m e .p h o n e ^
FROM m y _ e o n t a e t s
NATURAL J O IN

jjo
o bb __ddee! s i r e d

WHERE j d . t i t l e

jd

He :
AS

' - ';

,
,
. , SELECT:

SELECT *

FROM w e b _ d e s i g n e r s ;
' .

fir s t nam e

la s t nam e

phone

em ail

5559872
5556948
5557888
5557744

jm@someemail.com

sammy@someemail.com

toci@someemail.com
fm@sotTieemail.com

- & ,
1

492

11

m e .e m a il

-.


, , ,
.
SELECT :

SELECT *

FROM w e b _ d e s i g n e r s ;

: ,
, ,
my

c o n t a c t s ,

SELECT *

FROM

(S E LE C T m e . f i r s t _ n a m e ,

m e .la s t_ n a m e ,

m e .p h o n e ,

m e .e m a il

FROM m y _ e o n t a e t s me
^ /N A T U R A L J O IN

jo b _ d e s ir e d

WHERE j d . t i t l e

jd

' - ')

AS w e b _ d e s i g n e r s ;

,
.


,

.

5 \_131?
?

FROM
.
SELECT
, S Q L
.

493


, ,

.

,
.
.
, ,
. V IE W .
,
1
.


, .

, -

m0.At>K0

UC-

. ,

1((

, , .

.

,
. S Q L

, .
,
.
, .

,
.
, g r e g s

l i s t

. , ,
, .
, ,
.

494

11

.
,
job_current, job_
desired, ,
salary_low ?
,
? ,
,
.

, , s e l e c t ,
. ,
j o b r a i s e s .

SQL

r a is e ?

i'nyivgvwi x?d\M isv )\/191


V>1V>iOQOjJ

029

495

, , s e l e c t ,
. ,
j o b r a i s e s .

joh_currentj job_desired my_cov\tacts


?
sa la ry Jo b_cu rren t s a la r y jo w

joh_desired
SQL r a i s e ?

sa la ry s a la r y jo w , .

job^raises.

CREATE VIEW Job_raises AS


SELECT mc.first_name, mc.lastjname,, mc.email, m e.p ho n e,

, , ,

. , V,

j c .c o n t a c t jd j jc.salary, jd .sa la ry jo w ,
jd .sa la ry jo w - jc.salary AS raise
FROM jo b _cu rren t jc
:
\
INNER JOIN job_desired j d

INNER JOIN my_contacts m e


W HERE


,
^
.

raise.
^

,

AND j c .c o n t a c t j d - m c .c o n t a c t jd ;

SELECT *

496

11

FROM j o b _ r a i s e s ;

^
S E L E C T . 4 9 6
j o b _ r a i s e s .
?

517.

,

. ,
.

^
(

,
,
?

)
^

, .

( , SUM, COUNT
AVG) ,
. ,

GROUP BY,
DISTINCT HAVING,
.

, I N S E R T , UPDATE

DELETE

,
.

>

497


p ig g y

bank.

, .
, (
, N , D Q ) .

CREATE TABLE piggy_bank


(

id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,


coin CHAR(l) NOT NULL,
coin_year C H A R (4)
)
p ig g y

id
1
2
3
4
5
6
7
8

coin

Q
P
N

co in .y ear
1950
1972
2005

Q
Q

1999
1981
1940
1980
2001
1926
1999

Q
P
D
P

9
10

b a n k :

, 2 5 -
(Q ):

CREATE V IE W AS p b _ q u a r t e r s
SELECT *

FROM p ig g y _ b a n k

WHERE c o i n

'Q';

SELECT *

498

11

FROM p b _ q u a r t e r s ;

1 _ , p b _ q u a r t e r s _ (1 1

IN S E R T

INTO p i g g y _ b a n k VALUES
1999) ,
' Q' , 1981) , ( " , ' D' ,

1926), ( ', ' P',

1950),
C ' , ' P ' ,
1
9
7
1 9 4 0 ) , ( " , ' Q' , 1980) , ( "

2
N' , 2 0 0 5 ) ,
, ' P ', 2 0 0 1 ) , ( " , ' D',

1999);

CREATE VIEW p b _ q u a r t e r s
CREATE VIEW p b _ d i m e s

AS S E L E C T

AS S E L E C T

FROM p i g g y _ b a n k

FROM p i g g y _ b a n k

WHERE c o i n

WHERE c o i n

,
IN SE RT, DELETE UPDATE.
p i g g y b a n k .
^
IN SE R T

INTO p b _ q u a r t e r s

VALUES

C ','Q ',

1993);

IN S E R T

INTO p b _ q u a r t e r s

VALUES

C ' , D' ,

1942);

IN S E R T

INTO p b _ d i m e s

VALUES

C ','Q ',

WHERE c o i n

UPDATE p b _ q u a r t e r s

c o in

WHERE c o i n

'Q '

'D '

' Q' ;
WITH CHECK O P T I O N ;

^


'
^
.

2005);

DELE T E FROM p b _ q u a r t e r s

SET

'N '

OR c o i n

'P '

OR c o i n

'D V

'P';

499

piggy bank, pb quarters pb_dimes

/
IN S E R T

INTO p i g g y _ b a n k

( " , ' Q ' ,

1999) , ( " , ' Q' ,

1926), ( " ,

'P',

VALUES

1950),

1981) , ( " , ' D' ,

C ' , ' P ' ,

1 9 4 0 ) , ( " , ' Q' ,

1 9 7 2 ) , ('', 'N',
1980) , ( "

, 'P' ,

2005),
2 0 0 1 ) , ( " , ' D' ,

1999);

CREATE VIEW p b _ q u a r t e r s
CREATE VIEW p b _ d i m e s

AS S E L E C T

AS S E L E C T

FROM p i g g y _ b a n k

FROM p i g g y _ b a n k

WHERE c o i n

WHERE c o i n

=
'D '

' Q' ;
WITH CHECK O P T I O N ;


,
,

.

,
INSERT, DELETE UPDATE. piggy_bank.
IN S E R T

INTO p b _ q u a r t e r s

VALUES

C ','Q ',

1993);

. .
IN S E R T

INTO p b _ q u a r t e r s

VALUES

C ','D ',

1942);

8 , -
WHERE .
IN S E R T

INTO p b _ d i m e s

VALUES

C ','Q ',

2005);

- CHECK OPTION. ,
,
WHERE .
DELETE FROM p b _ q u a r t e r s

WHERE c o i n

'N '

OR c o i n

'P '


,

coin - 'Q'
UPDATE p b _ q u a r t e r s

SET c o i n

'Q '

WHERE c o i n

'P';

,

p bj]u a v te rs ,
coin - '!

:

500

11

OR c o i n

' D' ;

cein

1
2

3
4
5
6
7
8
9
10
11
12

toin^year
1950
1972

2005
1999
1981
1940
1980
2001
1926
1999

Q
D

1993
1942

Q
Q
D

CHECK OPTION
CHECK O P T IO N , ,
, IN SE R T DELETE
WHERE . , CHECK O P TIO N
I N S E R T UPDATE?
CHECK O P T IO N
IN SE R T ,
WHERE p b _ d i m e s .
UPDATE :

UPDATE p b _ d im e s

SET c o i n

'x ';

' x ' WHERE p b _ d i m e s ,


.


CHECK OPTION
- CHECK CONSTRAINT,
MySQL?

CHECK OPTION





WHERE
.

, ,
INSERT
WHERE.
,
m y _ c o n t a c t s
, _

c o n t a c t s . ,
' ' g e n d e r .

MySQJ,
CHECK
CONSTRAINT
CHECK OPTION.


my c o n t a c t s
,
g e n d e r '', ''?

501

) , ...
p ig g y
.

b a n k

, . ,
NOT NULL
.
, ,
, .
,
: I N S E R T , UPDATE D E L E T E .
NOT NULL,
.

NOT NULL. ,

.

CHECK OPTION,
INSERT
.

,
INSERT,
UPDATE DELETE.
( ,
M y S Q L ),
I N S E R T , UPDATE D E L E T E .
,
,
NULL .
IN SER T .
WHERE,
, CHECK M y S Q L .
, ,
,
(SUM, COUNT, AVG . . ) ,
, BETWEEN, HAVING, I N NOT IN .

502

11




NOT NULL
.


1000
.
...

,
.

1000 5HnOLEr^5
1

30 5 0 1 5
1 5^^155
/

TRRn5FER
FROn

1000

5flnOLEO5
51^155

03

30

1 ^

, .
.
?

504

11

, ':'1


- ,
DROP V I E W . :

DROP V IE W p b _ d im e s ;

"^ a A a B a e M b ;.10
)]1
?

.
SHOW TABLES
. ,
,
DESC.

,
?

.
, . MySQL
,
, , ,
, .
.
, .
,
.

5:

CHECK
i ,
. ,
?

,
.
, .

CHECK




.

>

503

;
: nUCCUC <1 ! . HUC-

D a t a v il l e
Sa v i n g s & l o

LUC [ R c o o u r i T j D =
a n

: , .
:
S E L E C T B f l L f l n C E FROf l UHE R E
nccouDT_;o

S E L E C T B f l L R D C E FROIl S f l t ' i r i G S U H E R E R C C O U r i T . f D = 3 8 P P I : )

1000 HR , 30 110
: 1000
.
:

. n UCCUC .

,1...
[CHECHinS.BHL > 1000. ]
[ 1000 ]
[11. Buuuun...]

.

:
:
:
: nUCCUC ( 1 ! . CWC [ R c c o u r i T j o

--

: , .
:

S E L E C T F ROH C H E C K I D G UHE RE

_/D =
S E L E C T B f l L f l M C E F ROH S f l t ' i n G S U H E R E f l C C O U M T _ / D = ! : )

0 1^ . 30 C B E P E T R T E i l b H O n
:
RUi Ki J d RKOn 3 K P R H 4 P .
(1 .

,
i n s e r t ,
?
...

505


.
300 .

5

6,

350

; nPWSf , .
. AUUHUEP

: nPWflf .

CHECKirtG.BflL FROn fl CCOUDTSJ

: (SELECT

: SELECT
CHECKmG. Sfl L FROn RCC0UrtTS:>

350 aO^ilRPOB

350 aoii^BPOB

300 .

: S RLL 1
GOOD FOR. GIt'E 01.

JUST USE lOnORE .


^/^0 . U3
. nPUUEd. /1 - 0,1.

300 .

: .
[1^_> 300. ]
[ 300 ]

350 !
3 5 0

(CHECKiriG.BflL > 300. SHE HRS


01 [/5 BRL >

300. ]
fSUSTRflCT 300 FROnCHECmnG_BRLJ

[ . 300]
.
: . . 3B0HU.

506

11

50

__

__ [__30 __]

2 5 0

[ CHECKinO.BRL 300]
:
.

>

507

>= 1000
1000



^ .

1000

3 0 0 .

>= 300

>= 300

300

300

300

300

~^~
.

3 5 0

(
),
.

1
_ ^^

.
508

11


S Q L ,
; , ,
.
( A t o m ic i t y , C o n s is te n c y , I s o la t io n , D u r a b i l i t y ) .

, , -

' >

. .
,
.


.
.
, , .


, .
:
, .
,
- .

II

, .
.
,
1000 .

509

s q l

$01
c h e c k ie g

e s e r*

^ c c o u n t _ id
b a la n ce

a c c o u n tjd 0 " -

la s t_ n a m e
f ir s t_ n a m e

s a v in g s

phone

e m a il

a c c o u n t_ id

a d d re ss

b a la n ce

S Q L
.

START TR A N S A C TIO N ;

/
)
SQL
^.

5

.

START TRANSACTION
SQL
COMMIT ROLLBACK.

C O M M IT;


,


COMMIT...

COMMIT.

' -

.. -^
ROLLBACK,


.

' ^ ^

ROLLBACK;

^0
^^
- ,

ROLLBACK ,

S T A R T

.
/

TRANSACTION.

COMMIT
510

11

/
: - - ...
D a t a v il l e
Sa v i n g s & l o

: PILICCUC 1
[RCCOUHTJO =

! . -

a n

, .

: )) SELECT BflLflnCE FROH CHECKIflG UHERE

_10 = !:

SELECT BflLflMCE FROn Sflt'IDGS UHERE flCCOUT_ID =

1:1

1000 HR >^ . 30 HR CBEPETRTEilbHOn

1000

: 3RdR4R . HUCCUC XRn$PUC. CflPRB/1...


[5 TRRT TRRnSRCTIOri:
[SELECT BRLRHCE FROH UHERE RCCOUHT_ - 1}

1000 HR . /.

[U PORTE SET BRLRHCE = BRLRHCE - 1000


UHERE RCCOUHT.ID = 1 ]

[0(1. BCTRBbTE BUUHUO...]


5 \-

1^,1 RUTRHUE-. OTREHR TPRH3RI^ULIU

:
:
:
COMMI
,

.

: RUCCUC (1
[ r c c o u h t j o = 1]
:

! . -

, .

A T M : SELECT

RccouriT_m = i.

BflLflDCE FROO CHECKIMG UHERE

SELECT BflLflMCE FROn Sfll^lMGS UHERE flCCOUnT_/D

-)

HR . 30 HR

511

mysql


6 MySQL

M yS Q L,
.
,


. . 217,
SHOW CRATE
TABLE m y _c on r.ac t s. 1 ,
CREATE TABLE, .
, : .
1>' .

Jmu '.-.
<Rt-'AVt :,[

..

-4. I

SOLC4i(v\rtf>v>,


.
,
.
, 4

SHOW CR EA TE

TABLE m y _ c o n t a c t s ;

^
.

C R EA TE T A B L E

'm y

contacts'

'last_name' varchar(30) default NULL,


'first_Naine' varchar(20) default NULL,
'email' varchar(50) default NULL,
'gender' char(l) default NULL,
'birthday' date default NULL,
'profession' varchar(50) default NULL,
'location' varchar(50) default NULL,
'status' varchar(20) default NULL,
'interests' varchar(lOO) default NULL,
'seeking' varchar(100) default NULL,
E N G m B -N rlSM f

VBSKJLT

^^ no 1(/0 -

^" ^

^ULL(
,\1 ?
}.

^.4 ! r.cAamt/\tHo
/,. -

Ai.1 5.

. N U LL.

1251

He


. ,
u c n 0 A t '3 y e M y h 0
.
.
).
'

,

1

,
.
,
.

M yS Q L .

, .
:

A LTER TABLE TYPE ~


512

11

In n o D B ;


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

p ig g y

b a n k , .

ROLLBACK,
.

S T A R T T R A N S A C T IO N ;
SELECT

FROM p i g g y _ b a n k ;

UPDATE p i g g y _ b a n k
SELECT

c o in

FROM p i g g y _ b a n k ;

'Q '

w here

< -------

c o in =

' P ';

------ .

ROLLBACK;
SELECT

set

FROM p i g g y _ b a n k ;

,,..

COMMIT,
.

S T A R T T R A N S A C T IO N ;
SELECT

FROM p i g g y _ b a n k ;

UPDATE p i g g y _ b a n k
SELECT

CO M M IT;
SELECT

co in

FROM p i g g y _ b a n k ;
-

set

'Q '

w here

< --------

c o in =

'P';

euie ...

,.

FROM p i g g y _ b a n k ;

,u

>

513

- ^

p i g g y b a n k
.
.

START

T R A N S A C T IO N ;

UPDATE p i g g y _ b a n k

set

c o in

'Q '

w here

c o in

'P '

piggy_bank
M

coin

cin_year

1
2

Q
P

1950
1972

3
4

N
Q

2005
1999

id

coin

coin_year

coin

coin_yeor

coin

coin y o '

coin

coin_yor

coin

coin_yoar

1
2

AND c o i n _ y e a r

<

1970;

3
4

COMMIT;

START

id

T R A N S A C T IO N ;

UPDATE p i g g y _ b a n k

set

co in

'N '

w here

c o in

'Q';

set

co in

' Q'

w here

c o in

'N '

c o in

'D '

w here

co in

'Q '

ROLLBACK;

1
2
3
4

S T A R T T R A N S A C T IO N ;
UPDATE p i g g y _ b a n k
AND c o i n _ y e a r

>

1950;

ROLLBACK;

S T A R T T R A N S A C T IO N ;
UPDATE p i g g y _ b a n k

id
1
2
3
4

id
set

COMMIT;

2
3
4

S T A R T T R A N S A C T IO N ;

id

AND c o i n _ y e a r

> 1980;

UPDATE p i g g y _ b a n k
AND c o i n _ y e a r
COMMIT;

set

> 1970;

co in

'P '

w here

c o in

'N '

1
2
3
4
OipBem Ha c. 518-

514

11

'^
^
.
START TRANSACTION,
COMMIT ROLLBACK ?


START TRANSACTION.
, ,
.

START TRANSACTION
,
?

.
, ,

COMMIT ROLLBACK
.

COMMIT ROLLBACK?

,
, :
, .
,

,
,

.

,

. ,
,
. ,
SELECT,
INSERT, UPDATE DELETE
.


?
.

515

sql


11 ,
. ,

.
III.

J

.
(\
,
>
.

^^^.

^''^OCtnot

,
)
.


NOT n u l l
.

START TRANSACTION

-, ^


.

,
,



.
.

,

| OPTION
,
,


ROLLBACK,


;


,



START TRANSACTION.
WHERE |^|.
516

11

. 497.

S E L E C T . 4 9 6
j o b _ r a i s e s .
?

ORPER BY last_name

, S ELEC T
.

517

- ^ \

piggy_bank


1 _
.

.

. 514.

S T A R T T R A N S A C T IO N ;
UPDATE p i g g y _ b a n k
AND c o i n _ y e a r

<

set

co in

'Q '

w here

c o in

'P '

1970;

- a
, .
START

T R A N S A C T IO N ;

id

coin

cin_year

1
2
3
4

1950
1972
2005
1999

id

coin

<5

P
N
Q

17.

2 .0 0 5

Id

cein

1
UPDATE p i g g y _ b a n k
ROLLBACK;

START

----------------- ^

c o in

AND c o i n _ y e a r
ROLLBACK;

>

c o in

= 'Q'

, .

set

c o in

'Q '

w here

co in

'N '

- Qm MCHa, u 3 MeHeHuu Hem.

T R A N S A C T IO N ;

AND c o i n _ y e a r

set

c o in

'D '

w here

co in

= '-QQ'

> 1980;

COMMIT;

T R A N S A C T IO N ;

UPDATE p i g g y _ b a n k
AND c o i n _ y e a r
COMMIT;

518

w here

1950;

UPDATE p i g g y _ b a n k

START

= ' N'

coin_year
50

17-

2005

id

cein

1
2

Q
P

cin_yar
5 0

2005

1-

id
1

coin

coin_yoar
5 0

T R A N S A C T IO N ;

UPDATE p i g g y _ b a n k

START

set

coin_year
50

11

set

> 1970;

c o in

'P '

w here

c o in

'N '

1 .9 7 2

19 72
2005

1999

Id

coin

coin_year
1950

1972
2005

1999

12

) 5 :

- ,

. ,

,
, .
,
,
.

'

c lo w n _

tra c k in g .
, ,

I nvest

.
,

........ Security deveiope

,
, -
.
:

c lo w n jn fo ,
. , ,
gender description ( ).
c lo w n jn fo
. , in fo jo c a tio n
, c lo w n jn fo .

Info Mtlvilio

activltlos
.a c tiv ity

id
a c tiv ity _ id

1
1

id O " T r

a c tiv ity

clewn inf*
id
nam e
gender

Info location

d e s c rip tio n
boss

id

lo c a tio n _ id
w hen

520

12

location
lo c a tio n

id

lo c a tio n


, ,
. ,
, ,
.
,
.

,
.
,
.

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

-. S ELECT fro m activities

,
.

: DROP TABLE on clow njn fo

521

- ^
\


. ,
( ) .
, , .

,
.

,
.

: S ELEC T From activities


S ELECT From clo w n jn fo ,
info_activities, activities,
infojocation, location

: PROP TABLE on clow njn fo


PROP TABLE on clo w n jn fo , info_
activities, activities, infojocation, location
INSERT on clo w n jn fo , info_activities,
activities, infojocation, location
UPPATE on clo w n jn fo , info_activities,
activities, infojocation, location
ALTER on clo w n jn fo , info_activities,
activities, infojocation, location
PELETE on clo w n jn fo , info_activities,
activities, infojocation, location


!
,

.

,

522

12

roof

, . ,
,
, .
ro o t
. , ro o t
.
ro o t , ro o t
. M y S Q L ;

SET PASSWORD FOR

' r o o t ' @' l o c a l h o s t ' = PASSWORD( ' b 4 d c l w n Z ' )



'root'.

localhost

Hue SQL.

,

root.

. , O r a c le
:
a lte r

user

root

id e n tifie d

by

- ;

,
,
. , , ,
.
ro o t
.

^
B o ljo d b l
<1187
?

111 ,
, ,
lo c a lh o s t ,
.

SQL- ?

.
;
localhost IP- .
,
kumquats O'Reilly,
root@kumquats.oreilly.com.

>

523


, , , :

SQL ?
, !
.
, , ,

.

. S Q L
,
:

CREATE USER e l s i e
ID E N T IF IE D BY

' c l3 v 3 r p 4 s 5 w 0 r d '
^

--------


?

8 0



.



.
,
,
.

, ,

.


. :
,

,
.
,

.

524

12

, )
.
- . c lo w n _
i n f o ( ) , GRANT.
ro o t,
S Q L ,
. -
,

GRANT.


'.

w o o d la n d _ c o tta g e ^

tallcing_aniaals
animaLM

badger

deer

blue bird

2
3
4

II

bashful

doc

dopey

chores
chore M

chore name

time

washing up

9:30 pm

i\

sewinq

10.00 am

cooking

5;00 pm

kitchen

making beds

7:35 am

bedroom

grumpy

i\

h appy

sleepy

sneezy

c h o re s

. ro o t

INSERT, UPDATE DELETE . h a p py


t a l k i n g a n im a ls
ALTER, .

t a lk in g _ a n im a ls

gru m p y .

:
.
, dopey,

in s tr u c tio n s

GRANT

,

lyr
.

c h o re s .
>

525

GRANT

GRANT
, -
.
, .
SELECT c lo w n

i n f o ,


SELECT...

GRANT SELECT ON

_____ ^ .

C lO W n _ _ in fO

TO e X s i e /

, 3^,,^

'



elsie.

SELECT
,
SELECT.
GRANT:

GRANT SELECT ON a c t i v i t i e s
GRANT SELECT ON l o c a t i o n

TO e l s i e ;

TO e l s i e ;

GRANT SELECT ON i n f o _ a c t i v i t i e s
GRANT SELECT ON i n f o

526

12

lo c a tio n

TO e l s i e ;

TO e l s i e ;

4^

, g r a n t
woodland_cottage (. 525).

1.

GRANT

IN SERT

ON m a g i c _ a n i m a l s

TO d o c ;

2.

GRANT D E L E T E ON c h o r e s
TO h a p p y ,

3.

s le e p y ;

GRANT D E L E T E ON c h o r e s
TO h a p p y ,

sle e p y

WITH GRANT O P T I O N ;

........................

^ ----------^ :
4.

GRANT S E L E C T ( c h o r e _ n a m e )
chores

5.

ON

TO d o p e y ;

GRANT S E L E C T ,

I N S E R T ON

ta lk in g _ a n im a ls
TO s n e e z y ;

6.

GRANT A L L ON t a l k i n g _ a n i m a l s
TO b a s h f u l ;

g r a n t .
7.

doc
chores.

8.

9.

10.

sleepy
talking_animals,
sleepy
talking_animals .
( a l l )
chores.

doc
woodland cottage.

>

527

, g r a n t
woodland_cottage (. 525).

1.

GRANT

I N S E R T ON m a g i c _ a n i m a l s

TO d o c ;

2.

3.

happy sleepy
chores.

GRANT D E L E T E ON c h o r e s
TO h a p p y ,

s le e p y ;

GRANT D E L E T E ON c h o r e s
TO h a p p y ,

GRANT S E L E C T ( c h o r e _ n a m e )
chores

5.

ON

TO d o p e y ;

GRANT S E L E C T ,

IN SERT

-----

happy sleepy
chores,
.

s le e p y

WITH GRANT O P T I O N ;

4.

doc
magic_animals.

ON

ta lk in g _ a n im a ls

dopey
ch o rejn a m e chores.

sneezy
talking_animals.

TO s n e e z y ;

6.

GRANT A L L ON t a l k i n g _ a n i m a l s
TO b a s h f u l ;

bashful ,
,
talking_animals.

g r a n t .
7.

528

d R A N T S ELECT ON chores
TO doc;

doc
chores.

8.

d R A N T PELETE ON talking_
animals TO sleepy WITH d R A N T
OPTION;

sleepy
talking_animals,
sleepy
talking animals .

9.

d R A N T ALL ON chores TO bashful,


doc, dopey, g r u m p y , happy, sleepy,
sneezy;

( a l l )
chores.

10.

d R A N T SELEC T ON woodland_
c o t t a g e * TO doc

doc ^ woodland_cottage.

12

GRANT

GRANT. :

GRANT
.

.

WITH GRANT OPTION


, .
, ,
c h o r e s ,
WITH GRANT O P T IO N c h o r e s
.


.

.
.

.
, .

GRANT ALL SELECT,


UPDATE, INSERT DELETE .

.

database_name.*
.
, * SELEC T,
.

>

529

REVOKE

REVOKE

SELECT? REVOKE.
GRANT?
REVOKE , GRANT
REVOKE, - FROM.

,
(SELECT).

REVOKE SELECT ON
clown^info
FROM elsie;
,
.

W IT H GRANT O P T IO N ,
. happy sleepy
D E L E T E c h o r e s ,
.


^
flRAN T OPTION.

REVOKE GRANT OPTION ON


DELETE ON chores
FROM happy, sleepy;

d e le t e

530

12


, ,


.

GRANT OPTION
, root sleepy DELETE
GRANT OPTION c h o re s. sleepy
sneezy DELETE c h o re s.


PELETE
chores
GRANT
OPTION

sleepy


DELETE
chores

sneezy

, root
sleepy. sneezy ,
sleepy.

"

root

sleepy

d e l e t e
chores

sleepy

sleepy

,
sneezy

.

1
sneezy

REVOKE : sneezy
. ,
, REVOKE
.

RESTRICT CASCADE. ,
?

531

revoke

CASCADE u RESTRICT

,
.
CASCADE RESTRICT
,

.

I

PELETE sleepy
chores GRANT
OPTION


PELETE
chores

JL

sneezy

CASCADE (
sleepy), , .

REVOKE DELETE ON chores FROM sleepy CASCADE;

sleepy

PELETE
chores

sleepy

,
sneezy

.

I
sneezy

CASCAPE

,


,

.

RESTRICT ,
- .

REVOKE DELETE ON chores FROM sleepy RESTRICT;

sleepy

sleepy
PELETE
chores

, root
. ,
sneezy, .

532

12

,

sneezy

sneezy.

...HO




,
REVOKE
RESTRICT
.

^
- .
REVOKE
, SELECT.

GRANT SELECT,

INSERT, DELETE ON l o c a t i o n s TO e l s i e ;

GRANT ALL ON clown in f o TO e l s i e ;

GRANT SELECT, INSERT ON a c t i v i t i e s TO e l s i e ;

GRANT DELETE, SELECT on i n f o _ l o c a t i o n TO e l s i e


WITH GRANT OPTION;

GRANT IN S E R T (lo c a tio n ), DELETE ON lo c a t i o n s TO e l s i e ;

>

533

- ,}

GRANT SELECT,

- .
REVOKE
, SELECT.

INSERT, DELETE ON l o c a t i o n s TO e l s i e ;

REVOKE INSERT. UPDATE. DELETE ON locations FROM elsie.

GRANT ALL ON clo w n _ in fo TO e l s i e ;

REVOKE INSERT, UPDATE, DELETE ON c l o w n j n f o FROM elsie;


)
/

HpuBuAezua
SELECT doAPKHa ocM.am.bc$i,
noaimoMy o m -

GRANT SELECT, INSERT ON a c t i v i t i e s TO e l s i e ;

3bi6aeM He 6ce.

REVOKE INSERT ON activities FROM elsie;


/



,

.

GRANT DELETE, SELECT on i n f 0_ l o c a t i o n TO e l s i e


WITH GRANT OPTION;

REVOKE DELETE on i n fo j o c a t i o n FROM elsie CASCADE;

GRANT IN S E R T (lo c a tio n ), DELETE ON l o c a t i o n s TO e l s i e ;

REVOKE GRANT INSERT(location), DELETE ON locations FROM elsie;


,
^ .
GRANT,
loca .

^


,
.

534

12

] 1


GRANT .
,
?
! . -

;
,


,
,
GRANT.

,
.
MySQL
:
GRANT SELECT ON *.*
elsie;


, .

, CASCADE

REVOKE?
{ I ! CASCADE
,

.

,
GRANT?


,
SELECT GRANT.

,
,

.
?


,
?
! ,
GRANT.

,
sneezy
,
root ?
.

, GRANT
CASCADE,
>1,
. ,

.


, ,
GRANT
REVOKE?
!
,

.
INSERT
. ,

.

,
,
?

.
.

. , 10

. ,
,
S E L E C T .
-,
.

535

1;

^
\
!
I


,

?



,
, .
,
:



.

,
.



. -

,

.

V
main database

536

12

,
,
.
,

,
.



,

... ?

-
,

.
.

.
,


.
:

MySQL

CREATE ROLE data__entry ;

,

MySQL,


.

,
.

GRANT SELECT, INSERT ON some_table TO data_entry;

.
...

>

537



GRANT.

GRANT SELECT, INSERT


ON t a lk in g _ a n im a ls
TO d oc;



SELECT
INSERT
talking,,
animals.

n
doc

/7

tal)cing_anlinals
anlmal_ld

anlmal.type

sings

dances

blue bird

badger

deer

squirrel

GRANT,
doc.
,
d a ta _ e n try :.

GRANT data__entry doc;

doc

GRANTS

- data_entry

talk ln g _ a n lm a ls


,
. DROP.

DROP ROLE data_entry;

538

12

dances

animal M

animai.type

sings

blue bird

badger

deer

squirrel

^
1)1

? ?

! ,
, .

, .

, :

GRANT SELECT,

,
, ?

INSERT, DELETE

ON gregs_list.*
TO jim;

, *
.

,
?


5:.
?
POJ

0 , ,
,
.

,
. ,
.



, .
d a t a _ e n t r y
doc, ?

539

WITH ADMIN OPTION

p- ^

, .
d a t a _ e n t r y
doc, ?

REVOKE data_entry FROM doc;

IVITH ADMIN OPTION


, GRANT W IT H GRANT
O P T IO N . W IT H A D M IN
O P T IO N .
. , :

GRANT data_entry doc WITH ADMIN OPTION;


^1 ADMIN OPTION
< doc

doc
happy d a t a e n t r y ,
;
GRANT d a t a _ e n t r y

h a p p y ;

REVOKE
CASCADE R E S T R IC T . ,
.

CASCADE
CASCADE REVOKE
, .

REVOKE data_entry FROM doc CASCADE;

doc
data_
entry.
540

12

doc

happy em
,

doc.


CASCADE
REVOKE
,
U
.

il
happy

RESTRICT
- ,
REVOKE
RESTRICT .

REVOKE data__entry FROM doc RESTRICT ;


,
REVOKE
RESTRICT
.

doc
data_
entry...

...
,



.

happy

, <
. ,
happy.

,
? ,
. ,
,
root.

?


8_81.
,
, 1, ,
,
.
: ...

>

541

^
^ Ja9 njeAanaBbine ^ ^ HacmJ^ou j a a j e iB e H u H , | ^

ucnopreiujiu.

|Jj>o4uinauTne >, .

.

>
u .

:
.
,
.

m y _ co n ta cts.
:
. ,
X g ender,
.
, .
, ...
:
. ,
. -, S Q L ,
SELECT.
- .

grege_lifit U

]^, .

542

12

lJaJ=to 11 Toot.

Janumume m j^ , Koinop>ie !!!! mj>u

* p>aSoinHuKoB.

Janumume Q

| %^1 ^^ |>^>

]=^ j=>aSomnuKoB.

|_1

contact id
title
salary
start date

|b_deslred

|ob_listiiigs

contact id
title
salary_low
salary_high
available
years_exp

job_id OTr^^-jT
title
salary
zip
description
contact interest

contact_id ^

profassign

prof_id 0 profession
xi |i_cede

city
state
status

status id 0 wstatus

0+ -

interests

-interest id
interest

interest_id
last name
first name
phone
email
gender
birthday
prof_id
>zip_code

0+

centact_seeiting

contact_id
^

O +w

seelcing

seeking_id
seeking

seeking_id
0+ r

>status_id

543

(\ . Q m B em
^ J>a3 ^ ^ | *
j>a3jeineHuH , *
]^.
* * ,
\

Koinoj>i,,e

' '>.
,

*
U .

J |* Toot.

SET PASSWORD FOR r o o W lo c a lk o s t = PA SSW O R D C grSG R ulz);

m j^ , Kom oj^ie m f^ no
m je*^ J^aSoinHuKoB.

CREATE USER f m n k IDENTIFIED BY 'jO bM 4tcH :

CREATE USER j i m IDENTIFIED BY 'NOmOr3Xs';

IT '" ''
'


!

CREATE USER j o e IDENTIFIED BY 's3 LeCTdOOd';


Komf*bie ^

m f e * .

GRANT DELETE ON j o b ji s t i n g s fran k; ^ -----


^
<^
m y_contacts.
GRANT SELECT ON m y_con tacts * TO frank;

GRANT SELECT, INSERT ON g r e g s j i s t

TO jim ;

SELECT
INSERT a reas

~
.

GRANT SELECT ON m y_contacts, profession , zip_code, status,


c o n t a c t j n t e r e s t , interests, co n ta ct_ seek in g , seeking TO jo e ;
\

544

12

,
- ,
.

CREATE USER GRANT



CREATE USER 6RANT


?

, .
, .
CREATE
:

USER

GRANT,

CREATE USER e l s i e
ID E N T IF IE D

BY

' cl3v 3rp 4sS w O rd ' ;

GRANT SELECT ON
clo w n _ in fo
TO e l s i e ;

, CREATE USER.
elsie
,
,
, -
.

GRANT SELECT ON
clown_info
TO elsie
IDENTIFIED BY 'cl3v3rp4s5w0rd';

545

. ,. ,) ..

!
? " 6 ^ . *

,
! ,
...
, ?

.
?
^ - - , 500
"
'^;,

11 !41 [


,
.

INQUERYER

.
,
,
.


?
,
.

546

12


, 12!

SQL,
.
III.
1XD

grant


I

-

' * '

\ ?

WITH GRANT OPTION



.
^

WITH ADMIN OPTION


-

\ ^
<^ H i c i T '

547

, !

$ 0 1 6 ...
6), ) !
.
, , ,

- ,
, , , [
], .
-
301 !

+
( )


! -, . ,

. ,
, ,
. ,

... , ...
. !

1.
, SQL ,
, .
,
.
.
MySQL.

MySQL
MySQL MySQL,
MySQL Administrator. :
http://dev.mysql.com/downloads/gui-tools/5. .html
Windows, Mac Linux. MySQL Administrator
,
.
MySQL Query Browser.
( ).

Untitled @ locafhost via socket

(
j

Back

SELECT name, boss.id FRflMclawui

text *

Slop

OQuary
:id

[F
12

name
Bsie'
Pickles

ibossjd
3
5

13

Snuggles

10

l4

Mr. Hobo

Is

Clarabelle

10

|6

Scooter

|7

Zippo

is

Babe

l9

Bonzo

110

Mister Sniffles 10

_______ ______

10 1 felched.___________ j </' Edit

Selected schema 'gregsLlst'.

550

M C anl

'Savt i R rst

M Last

j^

Sarch


MySQL.
, .
, .
CocoaMySQL:
h t t p : / / cocoain y sq l. s o u r c e f o r g e . n et/

(M ^QL 5.0.37) ro^tocalhost/chS/boys

ShowConso) OearConsott

Table C^rMions Create Table Syntax

Structure i Content

f d .

Show Variables Bush Priviteses

Databases

f boy.id

bOY-W
i ......

b&fs

jy

^4

toJd

Davey
Bobbv
Beaver

giris
moretoys
tov^t

Status

IDG l.

Custom Query

chie
Johnny

,
>1

encoding

\ ISO latin

lO atin

'

r o w s in ta b le

, phpMyAdmin.
MySQL
. MySQL
. ;
http://www.phpmyadmin.net/
.
PC; ,
,
.
Navicat 30- ;
http://www.navicat./
SQLyog Community Edition;
http://www.webyog.com//
>

551

2.
SQL .
, .
select, , select
. ,
, .
, .
, SQL ,
SQL. ;
, .


SQL .
,
(_). ,
. ,
.
SELECT.
,
, .
SQL.

h------------------------------------- ;----------------------------- -------------------------------- (, INSERT IN). ^


.____________.
LIKE.

LIKE

-------------

LIKE.
(NOT); WHERE.
SQL .
, .
.
, () .

.
>

!>

>=

<

!>

>=
1=

552

.

.

'^

. - 5 - , .

ABSOLUTE ACTION ADD ADMIN AFTER AGGREGATE ALIAS ALL ALLOCATE ALTER AMD ANY ARE ARRAY AS
ASC ASSERTION AT AUTHORIZATION
BEFORE BEGIN BINARY BIT BLOB BOOLEAN BOTH BREADTH BY
CALL CASCADE CASCADED CASE CAST CATALOG CHAR CHARACTER CHECK CLASS CLOB CLOSE COLLATE
COLLATION COLUMN COMMIT COMPLETION CONNECT CONNECTION CONSTRAINT CONSTRAINTS
CONSTRUCTOR CONTINUE CORRESPONDING CREATE CROSS CUBE CURRENT CURRENT_DATE
CURRENT PATH CURRENT ROLE CURRENT TIME CURRENT TIMESTAMP CURRENT USER CURSOR CYCLE
DATA DATE DAY DEALLOCATE DEC DECIMAL DECLARE DEFAULT DEFERRABLE DEFERRED DELETE DEPTH
DEREF DESC DESCRIBE DESCRIPTOR DESTROY DESTRUCTOR DETERMINISTIC DICTIONARY DIAGNOSTICS
DISCONNECT DISTINCT DOMAIN DOUBLE DROP DYNAMIC
EACH ELSE END END EXEC EQUALS ESCAPE EVERY EXCEPT EXCEPTION EXEC EXECUTE EXTERNAL
FALSE FETCH FIRST FLOAT FOR FOREIGN FOUND FROM FREE FULL FUNCTION
GENERAL GET GLOBAL GO GOTO GRANT GROUP GROUPING
HAVING HOST HOUR
IDENTITY IGNORE IMMEDIATE IN INDICATOR INITIALIZE INITIALLY INNER INOUT INPUT INSERT
INT INTEGER INTERSECT INTERVAL INTO IS ISOLATION ITERATE
JOIN
KEY
LANGUAGE LARGE LAST LATERAL LEADING LEFT LESS LEVEL LIKE LIMIT LOCAL LOCALTIME
LOCALTIMESTAMP LOCATOR
MAP MATCH MINUTE MODIFIES MODIFY MODULE MONTH
NAMES NATIONAL NATURAL NCHAR NCLOB NEW NEXT NO NONE NOT NULL NUMERIC
OBJECT OF OFF OLD ON ONLY OPEN OPERATION OPTION OR ORDER ORDINALITY OUT OUTER OUTPUT
PAD PARAMETER PARAMETERS PARTIAL PATH POSTFIX PRECISION PREFIX PREORDER PREPARE
PRESERVE PRIMARY PRIOR PRIVILEGES PROCEDURE PUBLIC
READ READS REAL RECURSIVE REF REFERENCES REFERENCING RELATIVE RESTRICT RESULT RETURN
RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP ROUTINE ROW ROWS
SAVEPOINT SCHEMA SCROLL SCOPE SEARCH SECOND SECTION SELECT SEQUENCE SESSION
SESSION_USER SET SETS SIZE SMALLINT SOME SPACE SPECIFIC SPECIFICTYPE SQL SQLEXCEPTION
SQLSTATE SQLWARNING START STATE STATEMENT STATIC STRUCTURE SYSTEM USER
TABLE TEMPORARY TERMINATE THAN THEN TIME TIMESTAMP TIMEZONE_HOUR TIMEZONE_MINUTE TO
TRAILING TRANSACTION TRANSLATION TREAT TRIGGER TRUE
UNDER UNION UNIQUE UNKNOWN UNNEST UPDATE USAGE USER USING
VALUE VALUES VARCHAR VARIABLE VARYING VIEW
WHEN WHENEVER WHERE WITH WITHOUT WORK WRITE
YEAR
ZONE

553

ANY, ALL SOME

3. ALL, ANY u SOME


ALL, ANY SOME
.
.
, IN 9.
SELECT name, r a t in g FROM re s ta u ra n t_ ra tin g s
WHERE r a t in g IN
(SELECT r a t in g FROM re s ta u ra n t_ ra tin g s
WHERE r a t in g > 3 AND r a t in g < 9);

re s ta u ra n t_ ra tin g s
name

rafiiig

Pizza House

The Shack

Arthur's

Ribs 'n' More

.
& ^

7 S'.

, . .
, The Shack Ribs WMore.

ALL
:
SELECT name, r a t in g FROM re s ta u ra n t_ ra tin g s
WHERE r a t in g > ALL
(SELECT r a t in g FROM re s ta u ra n t_ ra tin g s
WHERE r a t in g > 3 AND r a t in g < 9);

Ha ,
( >5).

> ALL
,

.

<;
SELECT name, r a t in g FROM re s ta u ra n t_ ra tin g s
WHERE r a t in g < ALL
(SELECT r a t in g FROM re s ta u ra n t_ ra tin g s WHERE
r a t in g > 3 AND r a t in g < 9);

ALL >= <=.


Shack Arthurs.
,
, 7:
SELECT name, r a t in g FROM re s ta u ra n t_ ra tin g s
--------------------WHERE r a t in g >= ALL
(SELECT r a t in g FRC^ r e s ta u ra n t_ ra tin g s
WHERE r a t in g > 3 AND r a t in g < 9);

554

> f

< ALL
,

.

,
.

ANY
ANY ,
. .
SELECT name, r a t in g FROM re s ta u ra n t_ ra tin g s
WHERE r a t in g > ANY
(SELECT r a t in g FROM re s ta u ra n t_ ra tin g s WHERE
r a t in g > 3 AND r a t in g < 9);
O h ; ,

, (5, 7).
The Shack
7, 5,
. i4rt/iurs 9.

> ANY
,

.
< ANY
,

.

SOME
SOME , ANY SQL.
, ,
.

>

555

4 .
,
. ,
, .

BOOLEAN
true, false,
NULL. /.
1 .
1 true false.

INT
INT .
4 294 967 295 ,
.
, ,
INT .
-2 147 483 648 2 147 483 647. ,
INT , :
INT(SIGNED)

INT
INT , SMALLINT BIGINT
. ,
.
. MySQL :
1

6ei 1

SMALLINT

- 3 2 7 6 8 32767

0 6 5 5 3 5

B IG IN T

-9 2 2 3 3 7 2 0 3 6 8 5 4 7 7 5 8 0 8
9 2 2 3 3 7 2 0 3 6 8 5 4 7 7 5 8 0 7

0
18446744073709551615

, MySQL :

TIN YIN T

-1 2 8 127

0 255

MEDIUMINT

- 8 3 8 8 6 0 8 8 3 8 8 6 0 7

0 16777215

556

DATE u TIME
MySQL.
DATE

YYYY-MM-DD

DATETIME
TIMESTAMP

YYYYMMDDHHMMSS

TIME

some d a te s
a date
2007-08-25 22:10:00
1925-01-01 02:05:00

, / ,
. /
. MySQL
DATE_FORMAT () .
, a _ d a te :

SELECT DATE_FORMAT(a_date, ' % %Y') FROM som e_dates;

% %Y .
:
dale
August 2007
January 1925

;
. ,
/ ,
.

557

5 .

.
.
. SQL ,
. ,
, .
SQL
.
.

. DROP.

} :
,
,
.
.
,
? ,
, .
SQL , ,
,
.


MySQL
TEMPORARY:
CREATE TEMPORARY TABLE my_tei4}_table

(
som e_ld INT,
some d a ta VARCHAR(50)

TEMPORARY

.


:
CREATE TEMPORARY TABLE m y_ten?)_table AS
SELECT * FRCM m y_perm anent_table ;

AS
.
558

. 1

6.
,
. SQL
CAST ( ) .
:
CAST ( , )
:
CHARO
DATE
DATETIME
DECIMAL
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]

) CAST()?
'Z 0 0 S - 0 1

DATE:
SELECT CAST('2 0 0 5 -0 1 -0 1 ' AS DATE);

:
SELECT CAST (2 AS DECIMAL) ;

npeodj
<^^

PATE.
^

------" 5 Z.OO.

CAST { ) :
INSERT, SELECT . .

CAST )
:
;
TIME,DATE,DATETIME,CHAR DECIMAL INTEGER.

>

559

7.

. ,
, :
SELECT CURRENTJJSER;

.
,
mot, :
t @ lo c a lh o s t

IFile

560

Edit Window Help

8.

. .

ABS(x)

( )
sanpoc
SELECT A B S (-2 3 );

ACOS()


SELECT ACOS(O);

ASINO

3,45 2,10 0.5 0


SELECT LN (2);

LOG(x) and
LOG(x,y)

0.13533528323661

X

SELECT FORMAT(34 521 00 .5 0,2);

LN(x)

-1.5726734063977

,
1SELECT FLOOR(1 .3 2 );

FORMAT (,)

0.54030230586814


SELECT E X P( - 2 ) ;

FLOOR()


SELECT (12);

()


SELECT C O S (l);

()

-0.78539816339745

, .
1 6 1
SELECT C E IL (1.32 );

COS ()

0.10016742116156


SELECT A T A N (-2 ,2 );

C EIL(x)

1.5707963267949


SELECT A S IN ( O .l) ;

ATAN(x,y)

23

|
0.69314718055995

, ,
,
SELECT LOG(2);

0.69314718055995

SELECT LO G (2,65536);

16
||| 1 .

561

8. ())

MOD(x,y)


|1>

SELECT MOD( 2 4 9 , 1 0 ) ;

""

1()

SELECT ( ) ;
POWER ( X , )
RADIANS()

ROUND( X , )

S I6 N (x )

SELECT ROUND( 1 . 3 4 ) ;

SELECT ROUND( - 1 . 3 4 ) ;

-1

,
SELECT ROUND( 1 . 4 6 5 , 1 ) ;

1 .5

SELECT ROUND( 1 . 4 6 5 , 0 ) ;

SELECT ROUND( 2 8 .3 6 7 , - 1 ) ;

30

1, , 0 - 0, -1

10


SELECT T A N (P IO );

TRUNCATE( , )

1 .2 2 4 6 0 6 3 5 3 8 2 2 4 -1 6


SELECT SQRT(IOO);

TAN(x)

-1


SELECT SIN (P I 0 ) ;

SQRT()

0 .8 4 6 5 5 9 2 0 6 8 1 2 2 3

SELECT S I ( a i ( - 2 3 ) ;
SIN (x)

0 .7 8 5 3 9 8 1 6 3 3 9 7 4 5


SELECT RANDO ;

ROUND ()


SELECT RADIANS( 4 5 ) ;

RANDO

3 .1 4 1 5 9 3


SELECT P O W (3,2);

- 1 . 2 2 4 0 6 3 5 3 8 2 2 4 -1 6

,
SELECT TRUNCATE( 8 . 9 2 3 , 1 ) ;

562

8 .9

9 .
,
.
.
,
.
WHERE ,

, . (,
4 )
.

, .
, ,
.
.
, ,
.
.
,
. , ,
a l l _ c o n t a c t s l a s t _
name f irs t_ n a m e .
, , .
MySQL a l l c o n t a c t s names
:
ALTER TABLE m y_contacts
ADD INDEX a ll_ co n ta cts_ n a m e s(la st_ n a m e , firs t_ n a m e ) ;

:
CREATE INDEX a ll_ co n ta cts_ n a m e s
ON a ll_ c o n t a c t s (last_nam e, firs t_ n a m e ) ;

a ll_ co n ta cts_ n a m e s
: (
, SELECT * FR(1 a ll_ c o n ta c ts )
last_nam e first_ n a m e
.

563

MySQL hi 10,000

10. PHP/MySQL 2

MySQL .
,
.
, ,
SQL.
g r e g s _ l i s t
my c o n t a c t s . ,
, .
-.
<?php
$conn = m y s q l_ c o n n e c t( "lo c a lh o s t" , " g re g " , "g rS g zp A s");
if

( ! $conn)

{
d ie ( 'D id n o t c o n n e c t: '

. m y s q l_ e rro r());

m y sq l_ s e le c t_ d b ("my_db", $ con n );

$ r e s u lt = m ysq l_ q uery("SELECT firs t_ n a m e , last_nam e FROM m y_ con tacts");

w h ile ($ ro w = m y s q l_ fe tc h _ a rra y ( $ re s u lt) )

{
echo $ ro w [' firs t_ n a m e ']

. " " . $ ro w ['la s t_ n a m e '];

echo "<br />";

m y sq l_ clo se ($ co n n );

?>
gregsnam es .php -.

564

)
<?php
- , .
$ = m y s q l_ c o n n e c t( " l o c a l h o s t " , " g r e g " , "g rS g z p A s") ;
g re g s l i s t , -
, . ,
$. mysql co n n e c t {)
.
if

( ! $corai)
{
d i e ( ' D id n o t c o n n e c t ;

'

. m y s q l_ e r r o r ( ) ) ;

}
, ,
.
n ^ s q l_ s e le c t_ d b (" m y _ d b " , $conn) ;
. ,
. g re g s l i s t USE:
$ r e s u l t = n ^ sq l_q u ery ("S E L E C T f ir s t _ n a m e , la st_ n a m e n iy _ c o n ta c ts ") ;
, , .
m ysql_qu ery {).
$ r e s u l t .
w h ile ($ ro w = m y s q l _ f e t c h _ a r r a y ( $ r e s u l t ) )
{
$ r e s u l t -. $w h ile
, .
ech o $ r o w [' f i r s t _ n a m e ' ]
ech o "< b r / > ";

. " " . $ ro w [' la s t_ n a in e ' ] ;

}
ech o - f i r s t name l a s t name .
HTML <br>.
lo s e ($ c o n n );
, (
).
?>
.

>

565

| 1


, .
MySQL.

MySQL

!
SQL,
.
MySQL Windows OS X.

. Windows 2000,
Windows Server 2003, 32-
Windows.
OS X 10.3.x .

,
MySQL. MySQL
MySQL Community Server.

u
MySQL
Windows OS X.
MySQL,
! ,

:
^

h t t p : / / d ev .m y sq l. com /doc/refm an/5. 0 / e n / w in d o w s -in s ta lla tio n .h tm l

MySQL Query Browser,


. 550-551.
( ).

568

MySQL

MySQL 6 Windows
:
h ttp :/ / d e v .m y s q l. com /dow nloads/n^sql/5. .h tm l
Download MySQL Community Server.
;

.

8/
S.O
.

Windows.

ct^poKal

Mmfsdownhxth

* * I ,^[1*
tKtmtcai t d u . vtnts aM more.
S u ta c rtb * MOW .

MySQL 6.0 CoRvmmtt/ 8rvr - GefwraRy Avaieble (<


In conlnsi to le U^SQL Enttfpn Stvw. nicn rectM S D0monM>^
sp*alc scAediMforwnftn a ntwvweion oflhe ii^SQLCommun^^
3rvr wM afso M avMaU In e si
M l (source and Olnarr') CommunKy M)U4e. So whUe th t $1^
' Downloaaa StcBoo. the 8lnafl>s bstrt on Ws mav
operMng syslvffls and wM rtmaw comefttenHy
> ThtStMeaniWnarie&ar^rBcomnwneeaior^

<Th*M
uv*rM
nlndudM
aM
Ioculfei
M* Matures have matured and
IX vefsKjn also, for most pli

Windows
Windows x64
Linux (non RPM. Intel C/C+-b comt
Red Hat Enterprise Linux 3 RPM f

569

MySQL Windows

Windows downloads
Windows Z IP/Setup . EXE, ,
. Pick M irror.

WtnOows SPfSeUsp EXE (x86).

Downioad I Pick a m m x
5- lSff9022cdB49Q3e03d46cf*20S 1Siyialuf
5.0 .4 5
5O0M
Download I Pick affijffOf
M:.-'' c40bS7fe5gefa9iSfcaam7ba-><gb! S y a l i y

W tftoot iR^aHer ( s i \)

Window x64 download* (piattoftn notes)


Windows Essenttats <^woe4 / mtef

Eh4T}

5045

28QM

Dgswilcadt WcKjiiiwrof

r * . e60bMe2tefS749a>?t540b
vwodows ap /s e tu p EXE (AMD64 / Intel
EM64T)

5 0 45

51 7M

Download 1 PteK a mirror

,
meMj

.EXE.

f-,fO 6f JS4S4Se4CieWS39ac<lS$ee7 ! .!
without BWJaner (AM064 / Intel EM64T>

5045

61

0 ! 1 !

: eeUa:6s3U021bltSt?etefef<!So^ufg

Unux (non RPM package) download* {platform rwtes)


Lima

gN>c-2 2, stioxianT is state)

5045

iim :

75

Dowaoaa |PIcit a mifrof

.1: 3ct21H15cllic-c3blf 1* *1 1!
5045
604M
Qownioadl PtcKamuTor

Llou*(x86)

eO5QM65deZbUet6*{}7C-sabtlSc4 !1
5 0 45
632M

/ mtef EM647}

f.Ob;

Linux (IA64. Red Hat AS 2.1. state)

)9%1

5045
1 2
Ptwn>paai P jck3_gaB
MC? ?4S491422fSleJ7liil0647SS2K7f4 Si9fiatUfft
Q Irrtem! I Protected Mcde On

,
; , .
,
. (Setup Wizard),
. Next.
MySQL Srrm 5.0 - Setup Vteaid
W e l c o n i e t o t h e S e t u p w b a r d f o r M y S Q I.
S e r v e r 5 .0

The Setu p \zard w l alow you bo modify, repair, or remove


MySQL Server 5 .0 . To continue, d d cN ext,

"

i-

t \
M y S Q L

............................. ^
i

570

Next>

^ 1

Caned . .{

,


.
Next.

MySQL

:
(Typical), (Complete) (Custom).
Typical.
, MySQL
,
:
C :\Program Files\M ySQ L\M ySQ L S e rv e r 5.0

Next.

Ready to InstaM the f^ogram


The vMzardis reedy to begin in

I f you a n t to review or ctiarige an y o f )R]ur iista ts tio n setting s, cid ( Bade. C kk


e x rttfie w te rd .
Current S e ta ig s :

1 iS e tL p T i^ e :
Typical

Destination Rdder:

:>1=51|5{.1|5013-5.0\ 1
^

Desenatjon Fokter:

Install u !
Ready to Install, 1 .
, Install.
, .
Install.

>

571

MySQL Mac OS X

MySQL OS X
OS X
Server, MySQL .
, ,
MySQL ( A p p lic a tio n s /
Sexver/MySQL Manager.

:
h t t p : //dev. n ^ s q l . com /downloads/m ysql/5. 0 . h tm l
Download MySQL Community
Server.
,

572

//

MySQL

OS X (package format).

MySQL S.OC<
SubacUfa Now r

Server - Generally Available (GA) Release

Inconirait to Vk MvSQ- Enicmn^ server wtvc^ rchs &omonthly rapid updiMsarvd quarterty Mtvica pack rataases, (hare I ru)
spetiflc Kheduie for when a r>ewverson ot (he MySOC Communi Server Is released. WMI every bug ftx ihathas Mf) applied to the
EntewM Server wHi also be avtilttle m ia subsequent Community Server reteate, ere vUI be Mirce<only rtiMsea in bet*een Kill
(wree ar\d binary) CommwWv boiW*. So hue ihe laie puohfted commuoiiy sour* wiHalways be avaflawe fromtw SiiyiS
Downioads Section, the nariet Usted on ihlspaga maybe from a prevlouamleese. ki any case, full binaries lor an our supported
operawg systemt are and wWremain conveniently avaiiable fromihis page.
. TbeSUr
rd br trst U!
The Uax version mdudes addtdonal toatuies ai haM not been exhausSvely
M ae teaMet have mabted and proven B be able, they *tMbe incorpora)
Haz version also, tor mo piaflorms, contam* u
programs
The Debwg binaries have been compiled with exirs debt
irKhided debugging code m

J

!

Mac OS X fpackage formal!

w ------------------------

, Mac OS X.
Pick Mirror.
,
; , .
, .
MySQL ,
Query Browser, . 5 5 0-55L
,
.
^ :
s h e l l > cd / u sr/ lo c a l/ m y sq l
s h e l l > sudo . / b in / in y sq ld _safe
( , .)
( Control-Z.)
s h e l l > bg
( Control-D e x i t .)
>

573

: ^ ^

SQL


, . ,
!

= <><><=>=

13 .

AND OR
ANP OR
WHERE
.
2

ALTER CHANGE
,^ .
5

ALTER MODIFY
,/ .
5

ALTER ADD

.
5

AUTOJNCREMENT

,
INSERT

.
4

AVG
^
.
6

BETWEEN
.
2

ALTER DROP
.
5

ALTER TABLE

.
5

576

Ifl

CHECK CONSTRAINTS

,

.
11

CHECK OPTION

;

WHERE .
11

CROSS JOIN

.

J
.
8

COUNT

SELECT
. COUNT ^
.
6

DELETE
.
WHERE
.
3

CREATE TABLE
.

.

,
.

DISTINCT
,
.
6

CREATE TABLE AS

SELECT.

DROP TABLE
,
{

INSERT, .

10

CREATE USER
5

.
12

EXCEPT
3 , , ,

.
10

>

577

G -S

GRANT
,

,
.
12

MIN
^
, MIN .
6

GROUP BY

.

NOT
.
2

INTERSECT
, ,
.

NULL NOT NULL


,

NULL
. NOT NULL
.
1' 1

IS NULL

NULL.
2

ORDER BY

.
6

L
LIMIT
,
.
6

578

1 (! II!

SELECT *
.
2

, .
().
9

(LEFT OUTER
JOIN)



.
10

,
.

7
--
(INNER JOIN)

,
.
8


,


.
7

,
. .

,

.

(2)

1
.
7

,

.

.
,
.
8
580

III

11

,
.

NOT NULL .
11

--



.
7

--


,

.

, .

.
9




.
10

,
.
.
11

(1)


,
.

,
,
.
10

(PRIMARY KEY)

,

.
4


,
,
.
10

>

581

()

, ,
,
.

2
.
7

,
,
.
.


.
,

.

, ,

.

-
- (-).
7

582

III

80
.

.
.
.
.
.
.

, 198206, -, , 73, . 29.


005-93,
2; 95 3005 .
26.08.11. 841(/16. . . . 62,160. 2000. 26231.
1 ,
.
197110, -, ., 15.

Оценить