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

9

1. Transact-SQL
(MS SQL Server)
Microsoft, ,

SQL,

Transact-SQL.

ANSI SQL-92,
. SQL Server
CASE, .
CASE
WHEN 1 THEN 1
WHEN 2 THEN 2
...
WHEN n THEN n
END

. .
UPDATE ( )
SET = CASE
WHEN <1
THEN
WHEN <5
THEN
WHEN <20
THEN
WHEN <50
1

THEN
ELSE
END
100 .
CASE WHEN,
,
.
. , , ,
, .
:
.(N, )
._(N, N, , )
SELECT .N, ., , )
=
CASE
WHEN .<0
THEN
WHEN .
BETWEEN 0 AND 10
THEN
WHEN .<0
BETWEEN 11 AND 30
THEN
ELSE
THEN
END
FROM ,
WHERE .N=.N
2

2. SQL.
SQL
SQL
.
SQL :


SQL,
SQL SELECT:
SELECT [ALL | DISTINCT] < >
INTO < >
FROM < >
[WHERE <>]
. : STUD (NS, FIO, GR,
SPEC)
Transact SQL
( Ms SQL Server) @
DECLARE @p1 int,
DECLARE @p2 char(20), @p3 char(4), @p4 char(30)
SET @p1=205
SELECT *
INTO @p2, @p3, @p4
FROM STUD
WHERE NS=@p1

,
.
SQL.
DECLARE < > CURSOR
, .
FOR <>
OPEN <> - ,

FETCH <> INTO < >

CLOSE <> -
.
DECLARE q CURSOR
FOR SELECT *
FROM STUD
WHERE SPEC=230102
OPEN q
WHILE .T.
FETCH q INTO A, B, C, D,
DO PROC
END WHILE
CLOSE q
. , .
S(N, , )

P(N, , , , )

J(N, , )
SPJ(N, N, N, )


,
,
.
MAIN
DEFINE PS.* LIKE S.*
DEFINE PJ.* LIKE J.*
DECLARE CS CURSOR FOR
SELECT N, , ,
FROM S
ORDER BY N
DECLARE CJ CURSOR FOR
SELECT N, ,
FROM J
WHERE N IN
(SELECT N
FROM SPJ
WHERE N=S.N)
ORDER BY N
OPEN CS
LET V=1B
LET R=1B
WHILE V
IF STATUS=NOTFOUND
THEN MESSAGE NO ROW FOUND
EXIT WHILE
END IF
FETCH CS INTO PS.NP, PS., PS., PS.
DISPLAY PS.NP, PS., PS., PS.
OPEN CJ
5

WHILE R
FETCH CJ INTO PJ.N, PJ., PJ.
DISPLAY PJ.N, PJ., PJ.
END WHILE
CLOSE CJ
END WHILE
CLOSE CS
END MAIN
SQL
, ,
(, ),
SQL, ,
.
,
.
SQL.
SQL
:
PREPARE
EXECUTE
:
DEFINE -SQL CHAR
DECLARE -SQL
-SQL=DELETE FROM SP
WHERE <100
PREPARE -SQL FROM -SQL
EXECUTE -SQL


1.
2.

MS SQL Server.

3. .
4. .
5. .
6.

7. ?
8.

SQL

9.

FETCH INTO?

10.

SQL?

10


, .
:
1.

2.

3.

4.

5.

6.

, .

7.

, .

8.

9.

10. - .
11. .
7

12. .
13. .
14. .

1.

2.

3.

4.


1.
.
:

1.

2.

. N

. N .
, .
5.1:

xyz

3.

xyz

- .

. , .
4. .
,
. , , .
.

.1.
8

,
f(x). f().
: .
,
.
.

f(x)

1312

4752

86

5472

76

6836

120

...
d1d2d3d4
f(x)=2*(d1*d4+d2*d3)mod(d1d2d3d4)
x=4752

f(x)=2*(8+35)=86

1.
1.

00
11

00
00

11
00

11
00

11
00

01
00
01
01

00
00
00
01

11
00
00
00

00
00
01
01

00
11
11
01

00
01
01
01

00
00

: 00 , 01 , 10 ,
11
2.

.
CREATE VIEW <> [] AS<>
CREATE VIEW spec 2202 AS SELECT *
FROM STUD
WHERE SPEC=2202

:
GRANT SQL
GRANT <> [ON_ ] TO <>
GRANT SELECT ON TABLE stud TO
GRANT SELECT, UPDATE ON TABLE stud TO
GRANT ALL PRIVILEGES ON TABLE stud, disc, st TO
GRANT SELECT ON TABLE stud TO PUBLIC
. .
CREATE VIEW prim1 AS
SELECT fio, gr
FROM stud
GRANT SELECT ON prim1 TO ,
GRANT
U1 U2
GRANT ( WITH GRANT OPTION
GRANT)
U2 U3 ..
U1 ->U2 -> U3

WITH GRANT OPTION

U1
GRANT SELECT ON TABLE STUD TO U2 WITH GRANT OPTION
U2
GRANT SELECT ON TABLE STUD TO U3 WITH GRANT OPTION
10

U3

U4
REVOKE
REVOKE <> [ON_ ]
REVOKE SELECT ON TABLE stud

FROM <>
FROM U2

U1 U2,
.
3.

(),
.

. , ,
.

,
, , , ,
.
:
1.

2.

3.

,
.
, .
11

.
. ,
>150 .

.
35 . 18 80
.
.
5.4: 250 .
.

.
5.5: 1) . 2)
4 .
SQL :
CHECK
NULL
DEFAULT
UNIQUE
PRIMARY KEY
5.6: ISO

CREATE DOMAIN <_> [AS]
[DEFAULT <>]
[CHECK <>]
, (SEX)
CREATE DOMAIN sex_type AS CHAR CHECK (Value IN(M,F))

12

Sex_type,
M F. Sotr(fio, sex, dolgn, ) sex.
sex , sex_type.

4.

, .
, ,


.

1.

2.

, .
C=(a*P+S)modK, a - , , S
.
3.

.
=+*(mod27)

1<=K<=27

C=P+2*(mod27)
:
0

10

11

12

13

14

15

16

17

18
13

19
A B C D E F G H I

4.

():

.
,

. ,
.
, DECODER. PIES

1.

2.

3.

4.

5.

6.

SQL ?

7.

GRANT?

8.

GRANT?
14

9.

10.

11.

11

2-3 . , ,
, .
2003. France Telecom 30000 , Alexa
Internet Archive 500000 .
1989. 1 .
,
. (1 = 1000 , 1 = 1000
, 1 = 1024 ).
-
- . Data
Mining. Data Mining ( Knowledge Discovery In Data)
() .
,
, ,
.
(DSS, Decision Support System).
:
- OLTP (Online transaction processing);
- ();
- .
15

:
-
SQL;
-

OLAP

(Online

analytical

processing);
- Data Mining (
).
1.
1988. 1992. .
.
,
.
-, ,
,

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

. ,
.

16

O LTP

O LTP

O LTP

O LA P

O LAP

.1. ()
:
- ( );
- (
);
- ( ).
,
. ETL
(E extraction, T transformation, L loading) ,
.
2.

.

().

17

.2.
:
( ).
( ).
(measures) , (
, , ..).
(Slice) .
(Rotate) .
(Drill Up) .
(Drill Down)
3. OLAP
OLAP (On-Line Analytical Processing)
,
,
.
18 , OLAP:
- ,
- ,
- - ,
18

- ,
- ,
- ..
OLAP
5 .
OLAP
:
- MOLAP ,
- ROLAP ,
- HOLAP .
MOLAP . .
. , ,
, .
,

.
,
.
.
. (
).
ROLAP
.

: .

(Fact Table) (Dimension Table).
:
19

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

.3.
,
. ROLAP
.
HOLAP
,
ROLAP MOLAP. MOLAP ,
ROLAP , .
4.
(Data Mining )
OLAP .
, .
20

, ,
. ,
,
.

.
- 1996.
.
Data Mining (,
) ,
, , ,
.
:
- , ,
- ,
- ,
- .
Data Mining .
: , ,
. : , ,
.

1.

2.

3.

, , ?

4.

5.

6.

7.

OLAP ?

8.

OLAP .
21

9.

MOLAP ROLAP.

10.

11.

12.

Data Mining.

12

90 ,

. Internet. Internet -
,
.
WWW .

,
Web- .
:
WWW (World Wide Web) - .
-.
,
(URL Uniform Resource Locater). URL
.
http://URL
:

22

: http://kai.kazan.ru
,
html.

1. HTML
HTML (Hyper Text Markup Language)
. HTML .
, <>.
:
1.

2.

3.

4.

5.

6.

7.

8.

(, , ActiveX)
HTML

<HTML> </HTML>
:
<HTML>
<HEAD> <TITLE> <> </TITLE>
</HEAD>
<BODY> < >

23

</BODY>
</HTML>

H1-H6 (<H1> </H1>)


: <H1 ALIGN=center> </H1>

<P> - .
:
<P>
1
<P>
2

<BR> -

<I> </I> -
<B> </B> -
<U> </U> -
<TT> </TT> -

<BASEFONT> - ( 1 7)
<FONT> -
:
<P>
< BASEFONT SIZE=4>

<P>
<FONT SIZE=+1>
24

1
<P>
<FONT SIZE=7>

FONT

FACE COLOR.
<FONT FACE=Helvetica SIZE=7 COLOR=Blue>
2.
:

<UL>

<OL>

:
<UL>
<Li>
<Li>
<Li>
</UL>
:

<LH> - ,
.
<HTML>
<HEADE>
<TITLE> </TITLE>
</HEADE>
<BODY>
<H1> </H1>
25

<UL>
<LI>
<UL>
<LI>
<LI>
<LI>
</UL>
<LI>
<UL>
<LI>
<LI>
<LI>
</UL>
</UL>
</BODY>
</HTML>

3.


().
.
<A> anchor
().
, HREF
Hyper Text Reference
<A HREF=URL_> </>

26

<A HREF=.htm> </>


: .htm
<A>
Name
<A HREF=#GO> </A>

<A NAME=GO> </A>



.
<A HREF=example.html # first> </A>
<A NAME=first> </A>
:
<HTML>
<HEAD><TITLE> </HEAD>
<BODY>
<H1> </H1>
<UL>
<LH> </LH>
<LI> <A href=#SOTR> </A>
<LI> <A href=#STUD> </A>
</UL>
<A NAME=SOTR> </A>
<P>
<BR>
<BR>
<BR>
<A NAME=STUD> </A>
<P>
<BR>
<BR>
27

<BR>
</BODY>
</HTML>

<IMG>
SRC
<A HREF=DOM.HTML><IMG SRC=DOM.GIF></A>
DOM.HTML ,
DOM.GIF , .

.1.
4. .
.
<TABLE> </TABLE>
BORDER ()
CAPTION
TH
TR
TD
:

-
28

1973

1964

1978

.2.
<TABLE BORDER>
<CARTION ALIGN=TOP> </CAPTION>
<TR>
<TH> </TH>
<TH> </TH>
<TH> </TH>
</TR>
<TR> <TD> </TD> <TD> </TD> <TD> 1973 </TD>
<TR> <TD> </TD> <TD> </TD> <TD> 1964 </TD>
<TR> <TD> </TD> <TD> </TD> <TD> 1978 </TD>
</TABLE>
5.
,
, , .
HTML.
1

.3.

29

<FRAMESET>.
COLS ROWS
. .
.
<FRAMESET COLS=100, 200, *>
<FRAMESET ROWS=30%, 70%>
HTML :
<FRAME SRC>
.
<FRAME SET COLS=100, 200, 300>
<FRAME SRC=A.HTM>
<FRAME SRC=B.HTM>
<FRAME SRC=C.HTM>
.
<FRAMESET ROWS=50%,50%>
<FRAME SRC=top.htm NAME=Top>
<FRAMESET COLS=50%,50%>
<FRAME SRC=fleft.htm NAME=BottonLeft>
<FRAME SRC=fright.htm NAME=BottonRight>
</FRAMESET>
</FRAMESET>
TARGET.
:
<A HREF=New.html TARGET BottonRight> </A>
New.html BottonRight

1.

WWW. ?

2.

HTML?

3.

?
30

4.

5.

6.

IMG ?

7.

8.

9.

31