Язык SQL и его реализация в СУБД FoxPro: Методические указания по курсу ''Теория информационных систем''

Материал предназначен для студентов специальности ''Информационные системы'' факультета ВМК, а также

201 111 265KB

Russian Pages 16 Year 2000

Report DMCA / Copyright

DOWNLOAD PDF FILE

Recommend Papers

Язык SQL и его реализация в СУБД FoxPro: Методические указания по курсу ''Теория информационных систем''

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

.

.

Ч « «

»

SQL

FoxPro»

2000

519.6 «

».

FoxPro» ( ) /

.

«

SQL

, . .,

. . -

:

, 2000.

« ,

»

,

, SQL.

-

. -

.

.

,

.

. . . .

-

.

.

. .

. .

2000 .

. «

» SQL,

. FoxPro

.

SQL SQL (Structured Query Language) -

. .

SQL National Standards Institute - ANSI) Standards Organization)

(American ISO (International . (

SQL

,

FoxPro)

ANSI. .

1. 2. 3.

. . SQL. / . . - .: Gruber. Understanding SQL. SYBEX, 1990.] . , . . SQL: «BHV», 1999 . ., . ., . . , 1995.

. «

», 1996. [ /

: Martin

.

.-

.:

Visual FoxPro

.

. .:

. SQL SQL

, .Э SQL FoxPro)

(

. SQL FoxPro. Rushmore),

, SQL

( . CREATE CURSOR.

CREATE CURSOR

. ,

,

. ,

. CREATE TABLE. CREATE TABLE CREATE CURSOR,

. . INSERT.

INSERT

. .

SELECT. SELECT .

FoxPro :

;

FoxPro;

(RQBE).

и и SELECT [ ]{*| .* | [ [AS _2] [, [ .] _2 [AS FROM [, ...] [IN [WHERE... ] [GROUP BY... ] [HAVING... ] [ORDER BY... ] [WITH OWNER ACCESS OPTION]

.]

_1 _2] [, ...]]} ]

SELECT:

Э

: ALL, DISTINCT, DISTINCTROW

TOP. .

, *

ALL.

, . _1,

, ,

_2

. . ,

. _2,

,

_2

. , .

яя

,

, , .

Д

и

ия. , ,

,

, .

SELECT

.

SELECT

SQL.

SQL

SELECT

SELECT...INTO. ,

1. SNUM 001 002 003

Salespeople ( SNAME

CITY . .

) COMM 0.12 0.9 0.14

3

.

004

0.7

2. CNUM 001 002 003

Customers ( CNAME

3. ONUM 001 002 003

)

CITY .

Orders (

RATING 3 2 4

SNUM 003 001 002

CNUM 001 002 003

SNUM 003 001 002

)

AMT 145 325 221

ODATE 10.10.2000 10.10.2000 10.10.2000

1. Snum Sname City Comm

(

)

(

)

2. Cnum Cname City rating

,

.

(

,

)

snum

(

1)

3. onum amt odate cnum snum

(

2)

,

(

1)

. SELECT .

FROM , SELECT. и и SELECT FROM

,

[IN

] SELECT,

Э

FROM: ,

, SQL,

, (ALL, DISTINCT, DISTINCTROW

TOP)

SELECT. ,

,

.Э , INNER JOIN, LEFT JOIN,

JOIN.

яя Д

RIGHT

, .

и

,

ия FROM "

SELECT. .

"

IN

. (*). "

":

SELECT * ; FROM salespeople : SNUM 001 002 003 004

SNAME

CITY .

COMM 0.12 0.9 0.14 0.7

.

.

,

SELECT snum, sname, city ; FROM salespeople : SNUM SNAME CITY 001 . 002 003 . 004 SELECT , ,

DISTINCT.

Salespeople ) SELECT

. SELECT city ; FROM salespeople

SELECT DISTINCT city ; FROM salespeople City . .

city .

).

,

,

,

. (

(

.

,

,

,

AS.

, "

"

sname: ;

SELECT snum AS FROM salespeople

, ,

AS

.

"

"

: SELECT COUNT (DISTINCT cnum) ; AS " " FROM orders

WHERE ,

,

и и SELECT FROM WHERE SELECT,

Э С

FROM, DELETE.

SELECT, UPDATE

WHERE,

: ,

, DISTINCT, DISTINCTROW SELECT.

,

(ALL, TOP) ,

.

У Д

, и

, .

ия ,

,

WHERE.

WHERE,

. JOIN,

WHERE . WHERE

• • • •

,

,

,

FROM. WHERE 5 : =, ,, =;

AND, OR, NOT ( , , SELECT * ; FROM customers ; where city = ' . CNUM CNAME 001

: (

( NULL (

BETWEEN); IN); IS NULL, IS NOT NULL).

).

WHERE

40

. .

' AND rating > 2 CITY .

,

RATING 3

2:

SNUM 003

,

2

SELECT * ; FROM customers ; where rating BETWEEN 2 AND 4 CNUM CNAME CITY 001 . 002 003

RATING 3 2 4

4:

SNUM 003 001 002

,

, . .

SELECT * ; FROM customers ; where city IN (' . CNUM CNAME 001 003

:

', ' CITY .

, SELECT * ; FROM customers ; where cname LIKE ' %' CNUM CNAME 003

') RATING 3 4

SNUM 003 002 :

CITY

,

RATING 4 2000

SNUM 002

.

SELECT * ; FROM orders ; where odate BETWEEN > '01/10/00 AND 30/10/00'

GROUP BY . SELECT

SQL, .

Count, SELECT FROM WHERE [GROUP BY

, Sum

] SELECT,

Э

GROUP BY: ,

, SQL, TOP)

, (ALL, DISTINCT, DISTINCTROW SELECT. .

, FROM. .

WHERE,

Microsoft Jet

WHERE. ( 10),

я . Д

и

.

ия GROUP BY SELECT Null,

.

, SQL.

,

GROUP BY,

.

SQL

Null. ,

GROUP BY, , SELECT,

Memo, FROM, SELECT

, SQL.

. GROUP BY

SELECT GROUP BY,

SQL. : SELECT cnum, MAX(amt) ; FROM orders ; GROUP BY cnum , SELECT snum, odate, MAX(amt) ; FROM orders ; GROUP BY snum, odate

,

:

HAVING , SELECT

GROUP BY. GROUP BY,

,

и и SELECT FROM WHERE GROUP BY [HAVING

HAVING ,

HAVING.

] SELECT,

Э , SQL, TOP) ,

HAVING: , , (ALL, DISTINCT, DISTINCTROW SELECT. .

FROM. . WHERE,

Microsoft Jet

WHERE. ( 10),

я .

. , Д

и

, .

ия HAVING WHERE,

HAVING

.

HAVING

,

. GROUP BY, . ,

, WHERE

HAVING

. HAVING ,

40 And

,

Or.

, 200: SELECT snum, odate, MAX(amt) ; FROM orders ; GROUP BY snum, odate ; HAVING MAX(amt) > 200 ONUM AMT ODATE 002 325 10.10.2000 003 221 10.10.2000 HAVING GROUP BY, ,

.

,

SELECT

HAVING

odate, .

, 10.10.00 SELECT snum, MAX(amt) ; FROM orders ; WHERE odate = '10/10/2000' GROUP BY snum

:

ORDER BY , и и SELECT FROM WHERE [ORDER BY Э

, .

_1 [ASC | DESC ][,

_2 [ASC | DESC ]][, ...]]] SELECT,

ORDER BY: ,

,

,

, (ALL, DISTINCT, DISTINCTROW SELECT. .

SQL, TOP) , FROM. . WHERE,

Microsoft Jet

WHERE. Д

_1,

и

_2

,

ия ORDER BY

. . (

"A"

" "

0

9).

SQL : SELECT sname ; FROM salespeople ; ORDER BY sname DESC

SELECT sname ; FROM salespeople ; ORDER BY sname ASC ( " " "A" 9 ,

0),

. SQL , SELECT snum, COUNT (onum) ; FROM orders ; GROUP BY snum ; ORDER BY COUNT (onum) DESC

:

ORDER BY

. ORDER BY,

,

, . .

WHERE. ,

FROM,

, . (

SQL sname " " SELECT sname, cname ; FROM salespeople, customers ; where salespeople.city = customers.city SELECT sname, cname ; FROM salespeople JOIN customers using city

"

" (

). cname ):

SQL

. ,

(

. )

, SQL

WHERE

, .

ё .

. "

, SELECT *; FROM Orders; WHERE snum = ; (SELECT snum; From Salespeople; WHERE sname= " ( ), SQL ( ) WHERE: Salespeople , snum

".

")

,

sname ,

,

.

: SELECT *; FROM Orders; WHERE snum =001 , WHERE sname= "

. "

WHERE ity= " . . Э

", ,

. ,

,

,

,

.

WITH OWNER ACCESS ,

,

,

,

.

SQL WITH OWNERACCESS OPTION

WITH OWNERACCESS OPTION

. (

, ).

, SELECT snum

:

WITH OWNERACCESS OPTION; , WITH OWNERACCESS OPTION, . , WITH OWNERACCESS OPTION. Э

System.mdw .

.

IN , Jet

, Microsoft Jet.

и

Microsoft dBASE, Paradox

и : IN ; DATABASE = :

[SELECT | INSERT] INTO { | [" "" "] | ["" [ FROM { | ["

IN "] | ["" [

""

]]}

; DATABASE =

]]}

SELECT,

Э

IN:

, .Э , INNER JOIN,

. ,

!

.. ,

. , dBASE III, dBASE IV, Paradox 3.x Д

и

, Microsoft Jet ( Paradox 4.x).

,

ия IN .

.

, ,

.dbf .

, ")

. , DATABASE.

, 'dBASE IV;'

,

(;) "dBASE IV;".

, dBASE, FoxPro .db.

Paradox

Microsoft Jet, (' ')

("

:

иц IN "" [dBASE IV; DATABASE=C:\DBASE\DATA\SALES;]; иц IN "C:\DBASE\DATA\SALES" "dBASE IV;"

... FROM ... FROM

ALL, DISTINCT, DISTINCTROW, TOP SQL. и и SELECT [ALL | DISTINCT | DISTINCTROW | [TOP n [PERCENT]]] FROM SELECT, : Э ALL SQL , ALL. Microsoft Jet , , SQL. DISTINCT , . , , SELECT, . DISTINCTROW , . DISTINCTROW , . DISTINCTROW , . TOP n [PERCENT] , , ORDER BY. TOP . ASC . , TOP Integer . TOP . , . . :

1( S#

P#

SNAME

PNAME

STATUS

COLOR

). SITY

2( WEIGHT

-

). CITY

3???? Y#

YNAME

S#

SITY

P#

4??????. QTY

Y#

SQL. 1.

, ,

,

2-

1-

,

. ,

2. . 3. 4. 5. 6. 7. 8. 9.

. ,

,

, ,

. 2. .

,

. 2.

, , " " ,

10.

" ". 800 ,

S2,

.

11.

"№

12.

"№

-№ . -№ .

13.

"№ ,

14. 15. 16.



-№



",

,



",

,

", .

, ,

" ". " "

" ". 1-

, 2-

.

17.

,

18. ,

ё

ё

, ,

, .

.

19.

, .

20. 21.

,

S1. 1,

S1.

22.

,

,

,

. 23

, 200.

24. 25. 26. 27.

,

S1.

,

S1. ,

-

" ". ,

, S1.

28.

,

, ,

. 29. 30. 31.

,

S1.

,

. ,

,

,

32.

J1.

,

1

, 33. " ". 34. 35. 36. 37. 38. , 39. " ". 40.

. , ,

S1.

,

,

" ".

,

.

,

S1.

,

,

. , "

" ", -

",

. 41.

, .

,