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

.

MS SQL SERVER 2000



- Microsoft SQL Server 2000.
,
, .
, ,
, ,
, .
, ,
.
SQL Server 2000.
.

I. SQL SERVER 200 0


1. SQL Server 2000







Web





2. SQL Server 2000
SQL Server 2000
MSSQLServer
SQLServerAgent
Jobs
Operators
Alerts
Microsoft Search
MSDTC
SQL Server 2000
Master

1
3
5
5
5
6
7
8
8
9
9
11
12
13
14
15
16
16
16
17
18
18
19
20
20
21
22

Model
Tempdb
Msdb
3. SQL Server 2000


SQL Server 2000
Enterprise Manager

SQL Server Service Manager


SQL Server Profiler
Query Analyzer
Upgrade Wizard
Import and Export Data
Client Network Utility Server Network Utility


. SQL SERVER 2000
4. SQL Server 2000





Windows NT
Windows 2000



Unicode
SQL Server 2000

Windows NT 4.0

Windows 2000





5. SQL Server 2000
SQL Server 6.x

24
25
26
28
28
31
32
32
33
34
35
37
37
38
38
41
43
45
46
50
50
51
52
55
57
63
64
65
66
66
68
69
69
70
73
74
74
75
78
81
82



-

SQL Server 7.0
SQL Server
6. SQL Server 2000


SQL Server 2000



.
7. SQL Server 2000
,
SQL Server Service Manager
Enterprise Manager
Services

Transact-SQL
SQL Server 2000

Enterprise Manager
Services
SQL Server 2000


8. SQL Server 2000
MSSQLServer
General
Memory
Processor
Security
Connections
Server Settings
Database Settings
Replication
SQLServerAgent
1
Advanced

84
85
87
88
90
90
92
94
113
113
120
121
125
131
133
134
135
137
140
146
147
147
149
150
153
155
157
159
161
161
163
167
169
174
175
178
181
185
185
186
187

Alert System
Job System
Connections
npone,nypbisp_configure
9. SQL Server 2000


Windows NT
SQL Server

Transact-SQL
SQL Server
Windows NT
Enterprise Manager






TransactSQL



Transact-SQL


Transact-SQL

TransactSQL


Transact-SQL




189
191
192
193
198
199
200
202
205
205
206
208
212
213
221
221
224
224
225
227
227
233
233
235
238
239
242
244
247
247
248
250
250
254
257
258
260


10.





Transact-SQL







Enterprise Manager





Transact-SQL







Enterprise Manager
11.



Data Transformation Service
DTS
DTS Export Import Wizard




262
264
265
268
269
279
280
283
283
288
289
292
293
295
298
298
300
303
304
306
307
308
308
311
312
315
317
318
319
319
323
324
325
328
328
330
335
336
338
341
342
344

Column Mappings
Transformations
Constraints













DTS Designer


File Transfer Protocol Task
ActiveX Script Task
Transform Data Task
Execute Process Task
Execute SQL Task
Data Driven Query Task
Copy SQL Server Objects Task
Send Mail Task
Bulk Insert Task
Execute Package Task
Message Queue Task
Transfer Error Messages Task
Transfer Databases Task
Transfer Master Stored Procedures Task
Transfer Jobs Task
Transfer Logins Task
Dynamic Properties Task


12. SQL Server 2000


346
350
352
355
356
357
359
361
362
363
365
366
370
372
374
375
376
378
379
3 81
384
387
417
415
422
427
425
430
436
440
446
448
453
453
454
456
463
465
468
469
470
471




Create Job Wizard
Enterprise Manager




Transact-SQL


Create Alert Wizard
Enterprise Manager
Transact-SQL

475
476
477
477
481
481
484
488
491
492
494
495
495
498
501
502

502

Enterprise Manager
Transact-SQL






Database Maintenance Plan Wizard
13.











Transact-SQL

502
505
505
507
507
508
512
513
515
525
526
527
529
530
532
534
535
538
539
541
542
543
544
549


Enterprise Manager

Transact-SQL



Enterprise Manager
14.



580

Snapshot Agent
Log Reader Agent
Queue Reader Agent
Distribution Agent
Merge Agent





582
583
584
585
586
588
596
597
601
605
608

550
551
558
563
563
565
566
567
572
574
576
576
579

614
615
619
620
625
626
628
638
645
646
647
662
669
669
670
681















15.

Performance Monitor
Task Manager
Event Viewer
SQL Server Profiler

Sessions
Objects
Scans
TSQL
Cursors
Stored Procedures
Error and Warning
Transactions
Locks
Databases
Performance
Server
Security Audit
User Configurable


Transact-SQL
16.

682
683
685
686
687
689
690
691
692
693
693
703
710
718
719
720
722
732
735
736
737
742
743
744
745
746
747
748
750
751
752
753
754
754
760
761
767
770
771
772
775


RAID


IV.
17.










18.









19.






,






777
778
780
781
783
785
785
787
788
789
794
795
797
801
801
804
806
807
807
811
820
821
825
827
835
839
845
845
848
851
852
853
855
856
858
859
860
861
864
867
869







20.







Transact-SQL



Enterprise Manager
Create Database Wizard

Transact-SQL
spdboption




Enterprise Manager



21.


Check
Null
Default
Unique
Primary Key
Foreign Key
No Action
Cascade

870
872
872
874
877
878
881
881
881
883
884
885
885
891
892
894
897
898
900
906
911
912
912
917
918
920
926
931
938
942
945
946
947
947
948
949
950
951
952
953
953




Transact-SQL










Enterprise Manager







22.

Transact-SQL
Enterprise Manager
Create View Wizard







23.





954
955
956
958
958
961
963
966
967
968
973
977
979
980
980
982
985
987
989
991
992
993
995
996
996
999
1005
1009
1009
1010
1011
1012
1014
1015
1017
1019
1020
1022
1024
1025
1027



Transact-SQL
Enterprise Manager
Create Index Wizard




24.




V.
25. Transact-SQL



CASE
COALESCE
ISNULL









BEGIN
END
IF
ELSE
WHILE
CONTINUE
GOTO
USE
WAIT...FOR
GO
26. SQL Server 2000

1025
1030
1030
1035
1038
1042
1043
1044
1044
1048
1048
1049
1052
1053
1055
1057
1058
1062
1062
1066
1069
1070
1072
1072
1073
1074
1075
1075
1077
1078
1082
1083
1083
1084
1085
1086
1086
1087
1088
1088
1089


" "





27. SQL Server 2000










,
Scalar
Inline
Multi-statement


28. ,

INSERT
SELECT...INTO



bcp.exe
bcp.exe
bcp.exe

BULK INSERT
29.
SELECT
INTO
FROM
WHERE

1091
1092
1093
1095
1096
1097
1099
1100
1100
1101
1103
1104
1105
1107
1108
1109
1110
1112
1113
1115
1117
1118
1119
1120
1121
1121
1122
1127

1134
1135
1136
1137
1145
1146
1153
1158
1159
1165
1165
1173

GROUP BY
HAVING
UNION
ORDER BY
COMPUTE
FOR
OPTION
30.










31.

Transact-SQL













32.





1177
1185
1186
1190
1192
1197
1198
1200
1201
1202
1204
1207
1208
1209
1210
1213
1214
1216
1217
1218
1220
1220
1221
1222
1223
1223
1224
1228
1229
1232
1234
1236
1237
1237
1239
1239
1241
1242
1246
1247
1247


1249

1253

ALTER FUNCTION 1119
@
ALTER PROCEDURE 1214
CONNECTIONS 1101
@@CPU_BUSY1112
ALTER TABLE 970
@@CURSOR_ROWS 1103, 1237
ALTER TRIGGER 1246
@@DATEF1RST11O1
ALTER VIEW 1011
@@DBTS 1101
AND 1078
@@ERROR1110
ANY 1079
@@FETCH_STATUS 1103, 1238
APP_NAME()1111
@@IDENTITY1111
AS 1162
@@IDLE1112
ASC1190
@@IO_BUSY1112
ASCII 1109
@@LANGID1101
ASIN1106
@@LANGUAGE1101
ATAN1106
@@LOCK_TIMEOUT 1102
ATN21106
@@MAX_CONNECTIONS 176, 1102
AVG1178
@@MAX_PRECIS1ON 1102

@@NESTLEVEL1102
BACKUP DATABASE 526, 544, 549
@@OPTIONS1102
BACKUP LOG 550, 926
@@PACK_RECEIVED 1112
BEGIN DISTRIBUTED TRAN 861
@@PACK_SENT1113
BEGIN TRAN 853
@@PACKET_ERRORS 1113
BEGIN...END 1083
@@PROCID1107
BETWEEN 1078
@@REMSERVER1102
bigint 1089
@@ROWCOUNT1111
binary 64, 1094
@@SERVERNAME 1102
bit 1098
@@SERVICENAME 1102
bitwise NOT 1072
@@SPID1102
BULK INSERT 1153
@@TEXTSIZE1102
bulkadmin 222
@@T1METICKS1113

@@TOTAL_ERRORS 1113
CASCADE 953
@@TOTAL_READ 1113
CASE 1066
@@TOTAL_WRITE 1113
CAST 1099
@@TRANCOUNT 864, 1111
CEILING 1106
@@VERSION1102
CHAR 1109
A
CHARINDEX1109
ABS1105
CHECK 948
ACOS1105
CLOSE 1236
ALL 1079, 1159, 1181, 1187
COALESCE 1069
ALTER DATABASE 938
COL LENGTH 1107

COLNAME1107
COLLATION PROPERTY 889, 1111
COLUMNPROPERTY 1107
COLUMNS_UPDATED() 1248
COMMIT IRAN 854
COMPUTE 1192 console.exe 39
CONTAINS 1176
CONVERT 1099
COS 1106
COT 1106
COUNT 1178
CREATE DATABASE 892
CREATE DEFAULT 828
CREATE FUNCTION 1115
CREATE INDEX 1030
CREATE PROCEDURE 1204
CREATE RULE 836
CREATE STATISTICS 1048
CREATE TABLE 958
CREATE TRIGGER 1242
CREATE VIEW 996
CUBE 1182
CURRENTTIMESTAMP 1111
CURRENTUSER 1111
cursor 1098
CURSOR_STATUS 1103
D
DATABASEPROPERTY 1107
DATABASEPROPERTY() 922
DATABASEPROPERTYEX() 922
DATALENGTH1111
DATE ADD 1104
DATEDIFF1104
DATENAME1104
DATEPART1105
datetime 1092
DAY 1105
dbaccessadmin 234
dbbackupoperator 234
dbdatareader 234
dbdatawriter 234
dbddladmin 234
dbdenydatareader 234

dbdenydatawriter 234
DBID1107
DBNAME1107
dbowner 234
dbsecurityadmin 234
DBCC:
DBREINDEX 1042
SETINSTANCE 725
SHOW_STATISTICS 1052
SHOWCONTIG 1044
SHRINKDATABASE 930
SHRINKFILE 927
SQLPERF925
dbcreator 222
dbo227
DEALLOCATE 1237
decimal 1090
DECLARE 1059
DECLARE CURSOR 1224
DEFAULT 950
DEGREES 1106
DELETE 1134
DENY 258
DESC1190
DIFFERENCE 1109
diskadmin 222
DISTINCT 1160
distrib.exe 40, 585
DROP DATABASE 945
DROP DEFAULT 831
DROP FUNCTION 1120
DROP INDEX 1044
DROP PROCEDURE 1216
DROP RULE 837
DROP STATISTICS 1053
DROP TABLE 980
DROP TRIGGER 1247
DROP VIEW 1016
dtsrun.exe 333
dtsrun.exe 39
dtswiz.exe 39
E
EXISTS 1080, 1176

1106
EXPAND VIEWS 1199
F
FAST 1198
FETCH 1229
FILE ID 1107
FILENAME1107
FILEGROUPJD1107
FILEGROUP_NAME 1108
FILEGROUPPROPERTY 1108
FILEPRQPERTY1108
float 1091
FLOOR 1106
FOR 1197
FORCE ORDER 1198
FORMATMESSAGE 1111
FREETEXT1176
FROM 1165
FULL OUTER 1169
FULLTEXTCATALOGPROPERTY
1108
FULLTEXTSERVICEPROPERT
Y1108
G
GETANSINULL1111
GETDATE()1105
GO 1087
GOTO 1085
GRANT 254
Grid Pane 391
GROUP BY 1177
guest 227
GUID 609, 1097
H
HAS_DB ACCESS 1108
HAVING 1185
HOST_ID()1111
HOST_NAME()1111
I
IAM813
IDENTINCR1111
IDENTSEED1111
IDENTITY 956, 1

IDENTITYCOL1161
IF...ELSE 1083
IN 1080
INDEXCOL1108
INDEXPROPERTYH08
INNER 1168
INSENSITIVE 1225
INSERT 325, 1122
int 1089
INTO 1165
IS_MEMBER1108
IS_SRVROLEMEMBER 1108
ISDATE1105
ISNULL1070, 1111
ISNUMERIC1106
isql.exe 39
isqlw.exe 39
itwiz.exe 39

KEEP PLAN 1199


KEEPFIXED PLAN 1199
L
LEFT 1109
LEFT OUTER 1168
LEN1109
LIKE 1081
LOG 1106
LOG10 1106
logread.exe 40, 583
LOWER 1109
LTR1M1109
M
makepipe.exe 39
Master 22
MAX 1178
MIN1178
Model 24
money 1091
MONTH 1105
Msdb26
msmergecontents 610, 611
msmergetombsto'ne 610
msrepltransactions 603

N
nchar 1095, 1109
NEWIDQ1112
NO ACTION 953
NOT 1078
ntext 1096
NULL 949
NULLIF1112
numeric 1090
nvarchar 1096

OBJECTNAME1108
OBJECTPROPERTY 1108
odbccmpt.exe 39
odbcping.exe 40
OPEN 1228
OPTION 1198
OR 1078
ORDER BY 1190
osql.exe 40
OUTPUT 1209
P
PARSENAME1112
PATINDEX1109
PERCENT 1160
PERMISSIONS 1112
PI 1106
POWER 1106
PRINT 1059
processadmin 222
Profiler 34
Q
qrdrsvc.exe 584
QUOTENAME1109
R
RADIANS 1106
RAID 778
RAND 1106
READ ONLY 1225
readpipe.exe 40
real 1091
rebuildm.exe 40, 120, 540'
RECOVERY 774

Remsetup.exe 79
REPLACE 1110
REPLICATE 1110
replmerg.exe 40, 587
RESTORE DATABASE 563, 565
RESTORE LOG 566
RETURN 1213
REVERSE 1110
REVOKE 259
RIGHT 1110
RIGHT OUTER 1169
ROBUST PLAN 1198
ROLLBACK TRAN 854
ROLLBACK WORK 854
ROLLUP1182
ROUND 1106
ROWCOUNT_BIG() 1112
ROWGUID 609, 610
ROWGUIDCOL 609, 950, 1162
RTRIM1110
S
sa221
SAVE TRAN 853
scm.exe 40
SCROLL 1225
securityadmin 222
SELECT 1159
SELECT INTO 325
SELECT...INTO1127
SERVERPROPERTY 1112
SESSION_USER1112
SET:
ANSI_NULL_DFLT_OFF 949
ANSI_NULL_DFLT_ON 949
DEADLOCKPRIORITY 880
IDENTITYINSERT 957
IMPLICITTRANSACTION
OFF 852
ON 856
LOCKITIMEOUT 867
QUOTEDIDENTIFIER 824
REMOTE PROC TRANS 861

TRANSACTION ISOLATION LEVEL


869
setupadmin 222
Setupsql.exe 75, 77
SHUTDOWN 147
SID 203, 1093
SIGN 1107
SIN 1107
smalldatetime 1092
smallint 1089
smallmoney 1091
snapshot.exe 40, 582
SOME 1079
SOUNDEX1110
spaddalert 501
s p a d d j o b 493
spaddoperator 505
spaddapprole 244
spaddextendedproc 1202
spaddgroup 241
spaddlinkedserver 283
spaddlinkedsrvlogin 290
spaddlogin 208
spaddremotelogin 313
spaddrole 240
spaddrolemember 236
spaddserver 308
spaddsrvrolemember 223
spaddtype 840
spadduser 231
spattachdb 542, 944
spattachsinglefiledb 944
sp_bindefault 829
spbindrule 837
spchangedbowner 919
spchangeobjectowner 825,1016
spconfigure 162, 193
allow update 230, 492
allow updates 179
cost threshold for parallelism 173
default language 179
fill factor 183
'locks' 865

'max server memory' 168


'max worker threads' 171
'min memory per query' 169
'min server memory' 168
'nested triggers' 180
'priority boost1 172
'query governor cost limit' 180
'recovery interval' 184
'remote access' 177
'remote proc trans' 177, 861
'remote query timeout' 177
'set working set size' 169
'show advanced options' 163
'two digit year cutoff 181
'user connections' 176
spdboption 912
spdepends 978,1015
spdetachdb 542, 942
spdropapprole 246
spdroplinkedsrvlogin 295
spdropremotelogin 318
spdroprole 242
spdroprolemember 237
spdropserver 298
spdropsrvrolemember 224
spdroptype 842
spdropuser 233
spfkeys 979
sp_grantdbaccess 231
spAgrantlogin 212
spjielp 974, 1012
sphelpdb 920
spjielpfile 921
sphelpfilegroup 921
sphelplinkedsrvlogin 292
sphelpremotelogin 315
sphelprolemember 237
sphelprotect 260
sphelpsrvrole 224
sphelpsrvrolemember 223
spjielptext 206
sphelpuser 231
spremoteoption 317

sprename 1010,1043
sp_renamedb918
sprevokedbaccess 232
spserveroption 295
spsetapprole 245
spspaceused 924
spunbindefault 831
spunbindrule 837
spupdatestats 1051
spusercounter 724
SPACE 1,110
sqlvariant 1098
sqlagent.exe 40
sqlcli.bat 78
sqlcst.bat 78
sqldiag.exe 40
sqlftwiz.exe 41
sqlins.bat 78
sqlmaint.exe 40
sqlrem.bat 78
sqlservr.exe 40, 147
sqltrace.exe 761
sqlupg.bat 78
SQRT1107
SQUARE 1107
STANDBY 774
STATSDATE1112
STDEVU93
STDEVP1193
STR1110
STUFF 1110
SUBSTRING 1110
SUM 1178
SUSER_SID1109
SUSER_SID() 230
SUSERSNAME1109
sysadmin221,222
sysalerts 474
sysdatabases 891
sysdepends 1015
sysindexes 1048
syslogins 206
sysoperators 505

sysservers 281
SYSTEMUSER1112
systypes 840
sysusers 228
sysxlogins 206, 289
T
TAN 1107
Tempdb 25
text 1096
timestamp 617, 1097
tinyint 1089
TOP 1160
TRIGGER_NESTLEVEL([object_id])
1248
TYPEPROPERTY 1108
u
UNION 1186
UNIQUE 951
UPDATE 1130, 1248
UPDATE STATISTICS 1049
UPPER 1110
USE 1086
USERID1109
V
VAR1193
varbinary 1094
varchar 1095
VARP1193
VARYING 1210
vswitch.exe 41, 90
W
WAITFOR 1086
WHERE 1173
WHILE...CONTINUE 1084
WITH TIES 1160
A
264
120
468
526
791
719

:
884
806
184
885
938
917
883
427
885
820
542, 942
918
881
920
541, 942
785, 794
: 184
881
579
787
21
891
945
926
911
785
845, 847
864
:
865
866
877
849
848, 878
848
:
849
850
849
850
872
870

867

575
775
227
180
410
172
773
1058
799
776
1158
1062

1060

609, 1097
575
772
:
279
811
809

824

860

73

663
662
Windows NT
205
11216, 1122, 1127
204
791
3
379
430
788, 791
1057


180
-
177
173
:
SQL Server 2000 147, 155, 157, 159
419
417
780
779

203,
1093
200
798
1130
73, 122
324
1027
820, 1017
1019
1022
1020
1043
1042
1027
1030
1044
1024
1029
1025
DTS Designer 376
379
ActiveX Script 384
Bulk Insert 430
Copy SQL Server Objects 427, 448
Data Driven Query 423
Dynamic Properties 456
Execute Package 436
Execute Process 417
Execute SQL 419
File Transfer Protocol 381

Message Queue 440


Send Mail 429
Transfer Database 454
Transfer Error Messages 446,453
Transfer Jobs 453
Transform Data 387
378
169

169

537
792
737
737
775, 777
- 786
126
792, 820
65
738, 791
1062
184
181
178
586

616, 858
423
526, 535,
543
791
1217
1229
1223
1237
1236
1232
1223
1221
1224
1237
1228

1219, 1222
1219
1220
1234

:
1061
53

536
790

175
1135
RAID 779
41
:
849, 866
858
1085
788
582, 597
719
Event Viewer 735
Performance Monitor 722
SQL Server Profiler 736
Task Manager 732
720
737
761
741

63, 65
885
171
799

81

859
722
265
821


823
1062
:
189
190
1062, 1072

821, 839

821
776
790, 791

DTS 330, 456, 463


1087

395
1058, 1063
:
188
508
325
52, 63
1064
788, 791
:
224
53
53
63, 64
171
180
55, 234, 247
821, 835
820, 995
761

74, 122
:
858
858
182, 517

184
772
185, 572
221, 234

280
269
69, 121
198
179
120
1025
:
SQL Server 2000 16, 119, 161
328
472, 737
TCP/IP 74, 122
66 Unicode
63
189
823
1048
517
45
791
811
791
790, 791
120
722

790, 820, 946


RAID 778
1088

853
845, 854
821, 1239

1134
307
820, 827
:
507
167
268
531
45, 74, 92
38
205, 209, 221

76
- 786
807
181, 1025
1063, 1100
X
821, 1200

173

324
811
429

178

1057


Microsoft SQL Server 2000.
.
SQL Server 2000 Web. XML,

,
. , SQL Server 2000 ,
, , .
, SQL Server 2000 Active Directory Windows 2000.
, .
, SQL Server 2000,
.
SQL Server 2000,
. . .
, .
SQL
Server 2000 .
.
SQL Server 2000, , , , , .
SQL Server 2000 ,
, , . SQL Server 2000 .
.

. ,
, .
SQL Server 2000, . -

.
.
, .
SQL Server 2000.

SQL Server 2000, ,
, , . , , Transact-SQL.
, , ,
. , .
.
, SQL Server, Microsoft MCSE+1,
MCDBA MCSD.

I.
SQL SERVER 2000
1. SQL Server 2000
2. SQL Server 2000
3. SQL Server 2000

SQL Server 2000


SQL Server 2000,
,
SQL Server. , SQL Server 2000
. SQL Server 2000
. ,
, (, total cost of owner),
, .
, ,
, ,
,
, . ,
,
.
SQL Server 2000,

.


SQL Server 2000 ,
SQL Server 7.0. , .
, ,
.


,
, SQL Server 2000
. SQL Server 7.0 SQL Server 7.0 SQL Server 6.x.
- .
SQL Server .
SQL Server 2000
() SQL Server 2000,

I. SQL Server 2000

(MSSQLServer SQLServerAgent),
.
. SQL Server
, .
.
, . ,
. (default instance). , , (named
instance),
. , TRELON
STORAGE STORAGE\TRELON.

SQL Server 7.0 SQL


Server 6.x. SQL
Server 2000. , SQL
Server 2000, , , SQL Server 7.0.

SQL Server 2000 . SQL Server 2000


, Unicode.
(collation),
.
SQL Server 2000 SQL Server 7.0 , . ,
.
, SQL Server 7.0
,
. ,
Unicode . , , , ,
- . , SQL Server 2000
, pubs Northwind.
, ,
SQL Server 2000 . , ,

1. SQL Server 2000

. . , , (case insensitive),
, .
AUTHORS Authors .
, . , (case insensitive),
.

, , . ,
. , SQL Server 2000
.


SQL Server 7.0
, Microsoft .
. , , . . ,
, , , , . ,
, . ,
, , , . .
SQL Server 2000 . ,
, .
,
. t a b l e . , . ,
GetPeople, , ,
:
SELECT * FROM GetPeople(' 1 )

,
27.

I. SQL Server 2000


. , , SQL Server 2000. , SQL Server 2000
, INSTEAD OF. SQL Server , , , ,
. , , . SQL Server 2000
AFTER.
INSTEAD OF (instead) , . , , , INSTEAD OF.
, . SQL Server 2000 , . ,
,
.
INSTEAD OF. .


.

(computed columns), SQL Server.
. .
SQL Server 2000
. , . ,
, ( ) .
, ,
Tempdb. Tempdb
. 23.

1. SQL Server 2000


SQL Server
.

,
. - , .

.
SQL Server 7.0 , .
SQL Server 2000 , . . SQL Server 2000
.

Web
, SQL Server 2000,
. ,
SQL Server 2000. ,
, , SQL Server 2000.
, . ,

.
SQL Server
. .
Web Assistant Wizard , , , HTML-.
. , , . , . .

10

I. SQL Server 2000

SQL Server 2000


. Web Assistant Wizard XML,
,
SQL Server 2000.
, , SQL Server 2000
XML. , . SQL
Server 2000 . ,
.
XML SQL Server 2000 ! SELECT, FOR. FOE
XML,
XML. , (
RAW), ( AUTO) ( EXPLICIT).
authors
pubs:
SELECT TOP 3 au_lname FROM authors FOR XML RAW

:
XML_F52E2B61-18Al-lldl-B105-00805F49916B
<row au_lname="Bennet"/>
<row au_lname="Blotchet-Halls"/>
row au_lname="Carson"/>
(3 row(s) affected)

, Query Analyzer.
, XML. , -. . Address Internet Explorer :
http: /7storage/matrix?sql=select+'<ROOT>'; select+top+3+au_lname+from+authors
+for+xml+raw;select+'</ROOT>'

('

, Internet Information Server (MS)


XML SQL Server 2000,
(virtual directory). , HTML
Web Assistant Wizard IIS . ,
intranet, - Web-,
Internet Information Server, Microsoft Windows 2000.

1. SQL Server 2000

1J_

. 1.1. - , XML , ,
, .

. 1.1.




. SQL Server (fail-over support)
(standby server). SQL Server 2000,
.
,
. ,
, . , .
,
. , .
. . ,
. ,
, (node).

I. SQL Server 2000

. .
,
, , . , ,
. ,
.

RAID, . , . RAID .
. RAID
16.
SQL Server . SQL Server 2000 ,
. SQL Server 2000 .
SQL Server 2000.
, ( )
. , .
SQL Server 2000 , (). , . 16.

SQL Server 2000


. , , SQL Server 7.0 ,
.
,
, , .
SQL Server 7.0 SQL Server 6.x. (merge replication), (immediately update subscriber).
, . , , ,

1. SQL Server 2000

13_

() .

. .
.
.
SQL Server 2000 (Queue updating), , ,

,

(). (queue), , .
. , SQL Server 2000
.
, .
, ,

,
, .
( ),
, .
, ,
. SQL
Server 7.0, , .
,
, 14.


SQL Server 2000 SQL Server 7.0, , :
b i g i n t "" integer,
8 . , SQL Server 7.0 i n t , 4 . , .
i n t -,
,

14

I. SQL Server 2000

.
b i g i n t .
sqi v a r i a n t , , .
s q l v a r i a n t ,
SQL Server 2000. ,
( , ),
, , . .
table ,
. t a b l e
, . . . ,
t a b l e , , . . ,
. table
INSERT, DELETE, UPDATE SELECT,

. table
(user-defined
function) .
SQL Server 2000,
, 26.
27.


, .
SELECT,
.
. . ,
,
. SQL Server , .
SQL Server 2000 . ,
, . ,
. , .

, .
, . , , ,

1. SQL Server 2000

15_

. , .
,
. ,
, , . SQL
Server 2000 . , , .
, . 23. ,
.

, SQL Server 2000 .


SQL Server 2000 ,
Windows 98, . ,
SQL Server 2000, , (engine) . SQL Server 2000
. , , SQL Server 2000.
,
SQL Server 2000 ,
.
, SQL Server 2000
(Personal Edition), Windows 98 ( ), Enterprise Edition,
32 64 , .
, , SQL Server 2000 Windows
DNA 2000, Web-,
, -
Business Internet.
2 . 1207

SQL Server 2000


SQL Server 2000
, ,
. Microsoft SQL Server 2000,
. SQL Server 2000, .
SQL Server 2000, .

SQL Server 2000


,
Windows NT Windows 2000, Microsoft SQL Server 2000 ,
. SQL Server:

MSSQLServer;

SQLServerAgent;

Microsoft Search (MSSearch);


Microsoft Distributed Transaction Coordinator (MSDTC).
SQL Server 2000 , ,
.
Windows 95/98 , SQL Server 2000

. , SQL Server 2000 . Microsoft Windows 95/98, Windows NT. SQL Server 2000.

MSSQLServer
MSSQLServer SQL Server 2000 . MSSQLServer -

2. SQL Server 2000

17_

, , , , ,
.
MSSQLServer
SQL Server 2000 . MSSQLServer SQL Server . , .
MSSQLServer ""
.
MSSQLServer,
SQL Server 2000. MSSQLServer
, SQLServerAgent, .

SQLServerAgent
SQLServerAgent, , SQL Server 2000.
. SQLServerAgent
,
. ,
. .
SQLServerAgent
MSSQLServer. SQLServerAgent, SQLServeiAgent MSSQLServer. SQLServerAgent
SQL Server 2000 ,
. ,
SQLServerAgent, , ,
, MSSQLServer.
SQLServerAgent MSSQLServer
, .
SQLServerAgent :
Jobs ();
Operators ();
Alerts ().
2*

18

I. SQL Server 2000

, , Msdb. SQLServerAgent .
"" , SQLServerAgent .
, .
Enterprise Manager. Transact-SQL.
SQL-DMO.
, , . SQLDMO .
SQLServerAgent
, . SQLServerAgent . ,
SQL Server 2000.
SQL Server 2000
12.
SQLServerAgent.

Jobs
, . (schedule)
. , (on demand), . . . (step).
Transact-SQL, , Windows, VBScript JavaScript .
SQLServerAgent , .
. ,
, SQLServerAgent ,

. SQLServerAgent
, ,
.

Operators
. , . .

2. SQL Server 2000

19_


.
, ,
. , , ,
. . . , . , ,
. . ,
, . , .
SQL Server 2000 , , , . SQLServerAgent.
,
.
SQLServerAgent
. ,
NET SEND, . NET SEND , , , - . NET
SEND .

Alerts
Alerts , SQL
Server 2000.
SQLServerAgent
. SQL Server 2000
,
SQL Server 2000. , .
, , .

.
. , , .
SQL
Server 2000 .

20

I. SQL Server 2000

Microsoft Search
Microsoft Search (MSSearch), Full-Text Search,
SQL
Server 2000. SQL Server 2000
.
Microsoft Search (full-text
search).
, , .
, .
Microsoft
. , Microsoft Internet Information Server
Index Server,
HTML-.
SQL Server 2000 (full-text catalog) (full-text index).

. MSSearch. MSSQLServer MSSearch
(full-text provider).
MSSearch
(repopulation) .
, (rebuild)
. ,
.
. ,
.

MSSearch Windows NT
Windows NT Server. SQL Server Desktop Engine. MSSearch SQL Server Standard Edition SQL Server Enterprise Edition.
, , Windows 95/98 Windows NT
Workstation,
MSSearch.

MSDTC
SQL Server 2000 . , -

2. SQL Server 2000

21_

. ,
Microsoft SQL Server 2000, ,
OLE DB.
, Oracle, FoxPro, MS Access . .,
, ,
MS Excel .
SQL
Server 2000 (distributed transaction).
(Distributed Transaction Coordinator). SQL Server 2000 MSDTC.
, . , . MSDTC
.
, . MSDTC , .
(2, two-phase commit protocol). . " " 14.

, ,
, , SQL Server 2000 .

SQL Server 2000


SQL Server 2000 .
SQL Server 2000
.
. Windows, .
.
SQL
Server 2000. :
Master;

Model;

Tempdb;

Msdb.


, . , . . . SQL Server 2000. -

22

I. SQL Server 2000

SELECT, INSERT,
UPDATE DELETE. , SQL Server 2000
. ,
SELECT.
SQL Server 2000
, . Microsoft , .
, . Microsoft
SQL
Server. SQL Server 2000
, , . Microsoft , . , ,
SQL Server 6.x, , SQL Server 2000,
SQL Server .

Enterprise Manager
SQL-DMO. SQL Server 2000 20. .

Master
SQL Server 2000.
, Windows.

. Master , , , .
. 2.1 Master,
.
2.1. Master

Sysaltfiles

Master, , , , . .

Syscacheobjects

2. SQL Server 2000

23

2.1 ()

Syscharsets

Sysconfigures

,
,

Syscurconfigs

, . .
, .
Sysconf igures

Sysdatabases


, ID, , . .

Sysdevices


. SQL Server 2000
SQL Server 6.x

Syslanguages

,
, . . . .
, . .

Syslockinfo


, "", , , ID

Syslogins

, , , ID . .

Sysmessages

.
, ,
,

Sysoledbusers

.
,

Sysperfinfo

SQL Server 2000.


Performance Monitor

Sysprocesses


, SQL Server

1. SQL Server 2000

24

2.1 ()

Sysremotelogins

, . , SUID,
SID, ID . .

Sysservers

SQL Server,
OLE DB SQL Server 2000

Master Data SQL Server 2000. :


Master.mdf , .
8 ;
Master.ldf ,
. I .

Model
.
SQL Server 2000 : Model
.
, , Model.
, . Model. , Enterprise Manager, Transact-SQL SQL-DMO.
.
Model,
. , Model
. Model , ,
.
,
Model. , , ,
, ,
Model,
.

2. SQL Server 2000

25

SQL Server 2000 Model


1,5 . Model Data
0,75 :
Model.mdf , ;
Model.ldf , .

Tempdb
, ,
. SQL
Server 2000 . # ##.
. . , . .
#, @.
, , . .
##,
@@.
Tempdb, Temporary DataBase,
SQL Server 2000 , . ,
, ,
Tempdb. Tempdb , .
Tempdb , , . , , , . SQL Server 2000 Tempdb . ,
Tempdb .

.
Tempdb, , Model.
. , Model.
. , Tempdb

26

I. SQL Server 2000

.
, Tempdb
. Tempdb .
.
.

Tempdb,
, ,
. Tempdb
Model, Tempdb .
Tempdb , Data
SQL Server 2000.
Tempdb.mdf , . 8 ;
Tempdb.ldf .
0,5 .

Msdb
Msdb , SQL Server 2000,
. ,
.
Msdb , SQLServerAgent. . 2.2
Msdb.
2.2. Msdb

Sysalerts

(alerts),

Syscategories

, Enterprise
Manager ,

Sysdownloadslist

Sysjobhistory

.
.
Enterprise Manager

2. SQL Server 2000

27
2.2 ()

Sysjobs


(jobs),

sysjobschedules

sysjobservers

sysjobsteps

. -

sysnotifications

sysoperators


,
SQLServerAgent

systargetservergroupmembers

,
(multiserver group)

Systargetservergroups

Systargetservers

Systaskids


(tasks) SQL Server 6.x (jobs)
SQL Server 2000

SQL Server 2000


.
. ,
.
. , SQL
Server 2000, , ,

:
(OLAP, Online Analytical Processing);
(OLTP, Online Transaction Processing).
, . , ,
,
. SQL Server 2000 .
OLAP OLTP ""
,
.



,
(DSS, Decision Support System)
.
.
,

3. SQL Server 2000

29_

. ,
. , .
. , . , ,
.
.
. .
,
. , , .
, ,
,
. , , ,
. , ,
. ,
, , . . ,
.
, , .
, , .
,
, . (OLAP).
OLAP , . , , .
, OLAP " ". , . . . ,
100%, .
OLAP .
. OLAP , .

30

I. SQL Server 2000

. OLAP .
.
.

, .
. .
, .
, . , .
OLAP , . SQL
Server 2000, SQL Server 6.x, Oracle, MS Access . OLAP
,
, .
,
.
.

. .
OLAP
.
OLAP,
. Microsoft
OLAP Microsoft Decision Support4ystem (MS DSS).
DSS :
, ""
. OLAP
Services, . SQL Server 2000
. OLAP Service SQL
Server 2000, ,
.
, ,

3. SQL Server 2000

37

. PivotTable Service. PivotTable Service . ,


.
DSS -
.
.
Microsoft
. ,
,
Microsoft .




,
.

(OLTP, Online Transaction Processing).
OLAP, OLTP ,
, ,
.
.
, , .
.
. , ,
. - ,
. ,
, . .

. , , . . , $100 000 . ,
- - -

32

I. SQL Server 2000

. , , , ,
$90 000. .
, ,
$100 000, . , ,
. ,
.

19.

. ,

.
, , ,
. OLTP
, OLAP.

SQL Server 2000


, SQL Server 2000 ,
, .

SQL Server 2000. , .
, , SQL Server 2000 (. .
engine). SQL Server 2000 ,
SQL Server 2000
. , SQL Server 2000
SQL Server 7.0.
SQL Server 6.x , .

Enterprise Manager

:
;
;

3. SQL Server 2000

33

;
;
SQL Server 2000;
;
, ;
;
, DTS.
, ,
Enterprise Manager .
, .
SQL Server 2000
:
Transact-SQL;
Enterprise Manager;
(wizards).

.
Transact-SQL, . . ,
Query Analyzer (
). Transact-SQL .
Enterprise Manager
,
. , Microsoft . Enterprise Manager ,
, . , Transact-SQL. He Enterprise Manager
,
Transact-SQL, . Transact-SQL
, . Enterprise
Manager
.

SQL Server Service Manager


SQL Server Service Manager ,

24

I. SQL Server 2000

SQL Server 2000. , .


Service Manager SQL Server 2000
.
Service Manager
(taskbar). , ,
SQL Server 2000,
.
Service Manager . " SQL Server Service Manager" 7.

SQL Server Profiler


SQL Server Profiler ,
SQL Server 2000. ,
Performance. , , Transact-SQL, , , SQL Server 2000
.
. SQL Server Profiler .
.
SQL Server 2000, . , , SQL Server 2000 .
SQL Server 2000
(events). SQL Server 2000
, .
- (event classes),
. SQL Server Profiler
Performance Monitor. SQL Server Profiler, Performance Monitor, . ( ) .
SQL Server . (category).
15.

3. SQL Server 2000

35

Query Analyzer
. Query Analyzer Enterprise
Manager.
, . ,
, Query Analyzer Execute
Query, . SQL Query Analyzer.
:
USE pubs
SELECT TOP 10 au_id, au_lname, au_fname FROM authors

:
au_id

au_lname

au_fname

409-56-7008
648-92-1872
238-95-7766
722-51-5454
712-45-1867
427-17-2319
213-46-8915
527-72-3246
472-27-2349
846-92-7186

Bennet
Blotchet-Halls
Carson
DeFrance
del Castillo
Dull
Green
Greene
Gringlesby
Hunter

Abraham
Reginald
Cheryl
Michel
Innes
Ann
Marjorie
Morningstar
Burt
Sheryl

(10 row(s) affected)

Query Analyzer , . 3.1. , SQL Query Analyzer .


(Object Browser), ,
,
. , .
<F8> Tools Object Browser, Show/hide. . ,
Query Analyzer, .

. Debug. Debug
Procedure, , . (break points),
.
, Query Analyzer
. -

36

I. SQL Server 2000

(estimated) (execution plan) , Query, Display Estimated Execution Plan Display


Execution Plan. ,

. . ,

. , ,
. - .

. 3 . 1 . Query Analyzer

. 3.2 . .
, ,
.

3. SQL Server 2000

37

. 3.2.

Upgrade Wizard
Upgrade Wizard
SQL Server 6.5 SQL Server 2000. SQL Server 2000
,
, , , , , , . ,
. . ,
.
Upgrade Wizard 5.

Import and Export Data


, / ,
DTS, . .

38

I. SQL Server 2000

,
. , DTS,
, .
,
. MS Excel, . ,
.
, DTS, 11.

Client Network Utility Server Network Utility


SQL Server 2000.
, ,
, (Network Library).
(DLL, dynamic link library) .
,
, IPC.
SQL Server 2000,
. , Server Network Utility, SQL Server 2000. .
, .

. Client Network Utility, SQL Server. Enterprise Manager, Query Analyzer
. , ,
, ,
.
6.


, , SQL
Server 2000 ,
. -

39

3. SQL Server 2000

SQL Server 2000,


.
. 3.1 . Binn SQL Server 2000, , . .
PATH.
,
.

, . , ,
.
3.1.

(Bulk Copy Program).



.
28

console.exe

dtsrun.exe

DTS , , .
, , SQL
Server 2000

dtswiz.exe

, DTS (DTS Import/Export Wizard)

isql.exe

, DB-Library.
TransactSQL, . SQL
Server 2000
Query Analyzer

isqlw.exe

, Query Analyzer

itwiz.exe

Index Tuning Wizard


. ,
, , ,

makepipe.exe

readpipe

odbccmpt.exe

( )
SQL Server 6.5 ODBC

1. SQL Server 2000

40

3.1 ()

odbcping.exe


SQL Server 2000 ODBC

osql.exe

, ODBC. Transact-SQL

rebuildm.exe

Master

readpipe.exe

.
makepipe.exe

distrib.exe

, Distributor
Agent. SQLServerAgent.
.

logread.exe

Log Reader Agent,


. SQLServerAgent.
.

replmerg.exe

Merge Agent, . SQLServerAgent.


.

snapshot.exe

Snapshot Agent, . SQLServerAgent. .


scm.exe

(,
) SQL Server 2000

sqlagent.exe

, SQLServerAgent. ,

sqldiag.exe

SQL
Server 2000 . ,
. ( SQLdiag.txt Log)

sqlmaint.exe


. ,
. . , , HTML-

sqlservr.exe

SQL Server 2000, MSSQLServer. ,


3. SQL Server 2000

41_
3.1 ()

sqlftwiz.exe

Full-Text Indexing Wizard,

vswitch.exe

( 6.x
8.0) SQL Server,

,
Transact-SQL,
Enterprise Manager (wizards). . .
.
,
. , Enterprise Manager . . ,
Transact-SQL.
, .
. 3.2 SQL Server 2000. ,
. , . Enterprise Manager Run a wizard.
Select Wizard, .
3.2. SQL Server

Backup Wizard

Failover Setup Wizard

Configuring Publishing and


Distribution Wizard

Create Alert Wizard

Create Database Wizard

Create Diagram Wizard

Create Index Wizard

Create Job Wizard

1. SQL Server 2000

42

3.2 ()

Create New Data Source


Wizard

ODBC- ODBC-

Create Login Wizard

SQL Server

Create Publication Wizard

Create Stored Procedure

Wizard
Create Trace Wizard
Create View Wizard
Create Maintenance Plan
Wizard

Profiler

Disable Publishing and


Distribution Wizard

DTS Export Wizard

DTS- SQL Server

DTS Import Wizard

DTS- SQL Server

Full-text Indexing Wizard

Index Tuning Wizard

Make Master Server


Wizard

Make Target Server


Wizard

Register Server Wizard

Enterprise
Manager

Pull Subscription Wizard

Push Subscription Wizard

SQL Server Upgrade


Wizard

SQL Server 6.x

Web Assistant Wizard

Web-

II.
SQL SERVER 2000
4. SQL Server 2000
5. SQL Server 2000
6. SQL Server 2000


SQL Server 2000
SQL Server 2000,
, . Microsoft
(Total Cost of Owner) . SQL Server 2000 .
, , SQL Server 2000. (typical)
, ,
.
.
,
(custom) . ,
,
.

.
.
, SQL Server 2000. SQL
Server 2000 SQL Server 2000
.

. , , ,
.

SQL Server SQL Server 2000. 6
Setup Wizard, SQL
Server 2000.

46

II. SQL Server 2000

, SQL
Server 2000 . ,
SQL Server 2000,
.


, SQL Server 2000,
(edition).
, . , ,
, 32-
.
, SQL Server 2000. , . , . SQL
Server 2000, , , , .
SQL Server 2000 :
Standard Edition. . SQL
Server 2000 Standard Edition , . 2 .
Enterprise Edition. , . SQL Server 2000 Enterprise Edition Web-,
(OLTP, Online Transaction Processing), (Data
Warehousing System) (DSS, Decision
Support System). Enterprise Edition
64 . ,
. SQL Server 2000 Enterprise
Edition .
Desktop Engine. - ,
(engine) , Books Online, (code samples) ,

4. SQL Server 2000

47_

. . . Desktop Engine Windows


Installer, . SQL
Server 2000 Desktop Engine API, . API
. Desktop Engine , , .
, , , . ,
,
. Desktop Engine , (CAL,
Client Access Licenses). SQL Server 2000
Desktop Engine off-line.
Windows Edition. SQL Server 2000
Microsoft Windows . .
, SQL Server 2000 Enterprise Edition SQL
Server 2000 Standard Edition.
Personal Edition. , Desktop Engine, ,
Enterprise Manager, Query Analyzer . Personal Edition
. Desktop Engine,
. SQL Server 2000 Personal Edition
. , SQL Server 2000
" " , Windows 98,
Windows NT Workstation 4.0 Windows 2000 Professional, Personal Edition
. .
Developer Edition. Enterprise Edition,
.
.
'

Evaluation Edition.
Web- Microsoft. ( )
Enterprise Edition. To SQL Server 2000 ,
3

.1207

II. SQL Server 2000

48

. SQL Server 2000


Evaluation Edition 120 .
, SQL Server 2000
, . ,

Windows SQL Server 2000. . 4.1 .
4.1.
Developer Desktop Windows
Edition
Engine CE Edition

Enterprise
Evaluation
Edition

Enterprise
Edition

Standard
Edition

Personal
Edition

Windows 2000
Datacenter

Windows 2000
Advanced Server

Windows 2000
Server

Windows 2000
Professional

Windows NT
Server 4.0 Enterprise Edition

Windows NT
Server 4.0

Windows NT
Workstation 4.0

Windows 98

Desktop
Engine

Windows CE

. 4.2 SQL Server 2000, ().


4.2.

Enterprise
Edition

Standard
Edition

Personal
Edition

Developer Desktop Windows


Edition
Engine CE Edition

Enterprise
Evaluation
Edition

49

4. SQL Server 2000

4.2 ()

Enterprise
Edition

Standard
Edition

Personal
Edition

4-


Enterprise Manager

Developer Desktop Windows Enterprise


Edition
Engine CE Edition Evaluation
Edition
+

_f.

DBCC

CREATE
INDEX

. 4.3
SQL Server 2000.
4.3.

Enterpri
se Edition

Standard
Edition

Personal
Edition

"!

3*

Developer Desktop Windows


Engine CE Edition
Edition

Enterprise
Evaluation
Edition

II. SQL Server 2000

4.3 ()

Enterpri
se Edition

Standard
Edition

Personal
Edition

Developer Desktop Windows


Edition
Engine Edition
.

Enterprise
Evaluation
Edition


,
SQL Server 2000, .
:
CJ ;
;
SQL Server 2000.
. ,
- .


SQL Server 2000 . . SQL Server 2000 ,
.
. 4.4 , SQL Server 2000. , , SQL Server 7.0.
, SQL Server 2000 , SQL
Server 7.0.

51

4. SQL Server 2000


4.4.

Pentium 166, Pentium Pro

Pentium II Pentium III

32
(64 Enterprise Edition)

6 4 - 1 2 8 {128-256
Enterprise Edition)

180 : ;
170 : ;
65 : ;
90 :
;
+50 : OLAP;
+12 : English Query


,

,

,
SQL Server 2000 . . Pentium II.
.
. , SQL Server 2000 Enterprise Edition
64 .


SQL Server 2000. , . ,
Windows 98 ,
( 816 ) , Windows 2000 Advanced Server
128 . , SQL Server 2000.


, , SQL Server 2000
,
.
. . 4.1 SQL Server 2000 Windows.
SQL Server 2000
:

52_

II. SQL Server 2000

Windows 98;
Windows NT Workstation 4.0;
Windows NT Server 4.0;
Windows 2000 .

~^

, SQL Server 2000 Windows 95. , SQL Server 2000.


SQL Server 2000
Windows NT Server Windows NT Workstation
Service Pack 5.0 . , SQL Server Books Online Microsoft Management Console (MMC) Internet Explorer
5.0 ( ). SQL Server 2000 Windows 2000
, . .
Internet Explorer 5.0.
SQL Server
, . SQL Server 2000 ,
. ,
, SQL
Server 2000.
SQL Server 2000 Windows 2000: NetBEUI,
IPX/SPX TCP/IP. , AppleTalk
ADSP, Banyan VINES .

. " " .
, SQL Server 2000
XML.
Microsoft Internet Information Server (IIS). ,
XML, Internet Information Server. , . . XML
.


, SQL Server 2000.
, -

4. SQL Server 2000

53

, , . ,

.
Windows NT Windows 2000 . ,
. ,
, ,
. , , SQL Server 2000, NTFS ,
MSSQLServer,
SQL Server 2000, .

NT,
. . Windows 2000. Windows 98
. SQL Server 2000 . , SQL Server 2000
, , .

NT
:
Local System ( ). .

. ,
, . .
.

. SQL Server 2000
, ,
SQL Server 2000.
Local User ( ). ,
. SQL Server 2000 , ,
SQL Server 2000,
.
User for Domain ( ).
(domain controller) Windows NT
Windows 2000 ,, . .

54

II. SQL Server 2000

,
SQL Server 2000, , ,
MSSQLServer, :
\Program Files\Microsoft SQL Server\Mssql;
mdf, ndf ldf;
:

HKEY_LOCAL_MACHINE\Software\Microsoft\MSSQLServer;

HKEY_LOCAL_MACHINE\System\CurrentControlset\Services\MSSQLServer.

, SQL Server 2000


. ,
.
, ,
,
. , ,
.
MSSQLServer. (SQLServerAgent, Microsoft
Search MSDTC) MSSQLServer.
, SQLServerAgent MSDTC,

(fixed server role) sysadmin. , . , Domain Admins.
SQL Server 2000
(jobs).
SQL Server 2000.
, .

Microsoft Search
. MSSQLServer
, MSSQLServer.
,
SQL Server 2000. , ( , )
. , , :
;
;
, ;

4. SQL Server 2000

;
SQL Server 2000;
.
, , . , ,
SQL Server 2000. ,
.
(

~)

SQL Server 2000 , Services Control Panel ( ) Enterprise Manager.


SQL Server 2000 8.

Windows NT
Windows NT User Manager for Domains (. 4.1),
.
,
. , ( ) (Administrator)
(Account Operator).
User New
User. (. 4.2), (Username), (Full Name)
(Description). , Password Confirm Password
. , ,
User Must Change Password at Next Logon, . ,
Password Never Expires, . Add .
SQL Server 2000
. , ,
,
. (rights) Windows NT
.
Windows NT,
. , ,
, . .

56

II. SQL Server 2000

. 4 . 1 . User Manager For Domains

. 4 . 2 . New User User Manager for Domains

SQL Server 2000 :


(Act as a part of the operating
system);

57

4. SQL Server 2000

(Log on as a
service);
(Increase quotas);
(Replace a process level token).
Policies
User Manager for Domains User Rights. , . 4.3. Right , . Grant To
, .
Add.

. 4 . 3 .
User Rights Policy

, SQL Server 2000 , . User Manager for Domains SQL Server 2000.

, Windows 98 . SQL Server 2000 Windows NT, .

Windows 2000
Windows 2000 Windows NT 4.0. Windows NT 4.0
Windows 2000.
Windows 2000 (, Windows 2000, ) Active Directory Users and Computers (. 4.4).

II. SQL Server 2000

58

. 4.4. Active Directory Users and Computers

,
Local Users and Groups\Users Computer Management (. 4.5).

~^

, SQL Server 2000,


Windows 2000,

Computer Management .

Windows NT 4.0 Windows 2000 , , .


(. . Active Directory)
,
.
, SQL
Server 2000 .

4. SQL Server 2000

59

. Local Users and


Groups\Users New User. New User (. 4.6), , :
User name. , .
.
Full name.
, , .
Description. , .
, . , , .
Password. ,
.

. 4.5. Computer Management

60

II. SQL Server 2000

Confirm password. ,
. ,
.
.
User must change password at next logon.
.
User cannot change password.
, .
. , .
, .
Password never expires. ""
. .
.
Account is disabled. . , . ,
.

. 4.6. New User


, .
Create,

4. SQL Server 2000

61

. , ,
,
Full name Description.
Windows NT 4.0, Windows 2000 , SQL Server 2000. Windows 2000
.
Local
Security Policy (. 4.7), Local Policies\User Right Assignment.

. 4.7. Local Security Policy


,
.
Local Security Policy Settings (. 4.8) Add, (. 4.9)
.

62

. 4.8. Local Security Policy Settings

. 4.9.

II. SQL Server 2000

4. SQL Server 2000

63

Windows 2000,
, .

Windows NT, Windows 2000 SQL Server 2000, :


(Act as a part of the operating
system);
(Log on as a
service);
(Increase quotas);
(Replace a process level token).

SQL Server 2000.


SQL Server 2000 ,
. (collation) , , . SQL
Server 7.0
(Character Set), (Sort Order) Unicode (Unicode Collation).
. , SQL Server 7.0
. . ,
.
, SQL Server 2000.
SQL Server 2000 ( Unicode) (Unicode) .
. ,
:
Unicode (char, varchar t e x t ) ;
Unicode (nchar, nvarchar ntext);
, Unicode.

64

II. SQL Server 2000

,
SQL Server 2000 .


, SQL Server 2000 . , , . . ,
65, 66, 67 . . , , G, , F, , , , , , F, G.
, .
.
, . ,
. SQL
Server 2000 (sort order).

SQL Server 7.0 Unicode, . .


, . Unicode Unicode
(Unicode Collation). SQL Server 2000 "" .
Unicode, Unicode.

SQL Server 7.0 SQL Server 2000


.
. SQL Server 7.0
,
, SQL Server 2000 :
Binary ,
.
.
Case sensitive , .
SQL Server 2000
.
, .
Accent sensitive .

4. SQL Server 2000

65_


. (check box).
- , .
.


(code page) , char, varchar t e x t .
256 . , 1 , 256 .

(character set).
( 0127) .
, , , ,
, , .
( 128255) .
SQL Server 2000 16
(. 4.5), 1251, .
. Regional Settings Control Panel.
4.5. SQL Server 2000

437

850

874

932

936

()

949
950
1250
1251

()

66

II. SQL Server 2000


4.S ()


1252

Latin 1 (ANSI)

1253

1254

125

1256

1257

1258

Unicode

256. . ,
.
, .

, . . ,
.
SQL Server 2000 Unicode. 256 , . Unicode
1 , ,
2 . 65 536 (2 1 6 ). . SQL Server 2000
Unicode: nchar, nvarchar n t e x t .

Microsoft SQL Server 7.0.


.

SQL Server 2000


, Unicode. SQL

4. SQL Server 2000

67_

Server 2000 . , SQL Server 7.0 ' SQL Server 2000


. , , ,
.
SQL Server 2000 SQL Server 7.0 , . ,
.

SQL Server 7.0


, . , Unicode
.
. ,
, , , . SQL Server 7.0
, . . ( , Unicode).
,
, . ,
, .
. , ,
, Authors authors,
. , , .

SQL Server 7.0 SQL Server 2000


.
SQL Server 2000 ,
:
Windows
, Windows.
.
SQL Server 2000.
, Regional Options Control Panel. -

S8

II. SQL Server 2000

,
SQL Server 2000. , SQL Server 2000 ,
.

SQL SQL Server.



. , SQL
SQL_Latinl_General_CPl_CI_AS (Dictionary Order, Case-insensitive),
1252 (ISO Code Page 1252)
Unicode (General Unicode Collation). SQL Server 2000
, Unicode, SQL Server 7.0.
, SQL
SQL Server.
Windows. ,

SQL Server 2000 . SQL Server 2000 . ,
Windows, SQL
Server 2000 , .
.
,
, .


SQL Server 2000 .
, SQL Server 2000 , . , SQL
Server 2000 . .
, , SQL
Server 2000, , SQL Server 2000, .
' 14.
, SQL
Server 2000. ,
, SQLServerAgent .

4. SQL Server 2000

SQLServerAgent . ,
. SQL Server, .


, SQL Server 2000
, .
, . Windows,
SQL Server 2000, .
,
.

. , . .
SQL Server 2000.

Windows NT 4.0
Windows NT 4.0
Network () (. 4.10), Control Panel ( ). Network Neighborhood (
), Properties ().
Protocols. Network Protocols ,
.
Add. Select Network Protocol
(. 4.11) .
, . Have Disk.
, , .
TCP/IP,
. NetBEUI
, .

,
, .
.

70

. 4.10. Network

II. SQL Server 2000

. 4.11. Select Network Protocol

Windows 2000
Windows 2000
Windows NT 4.0.
Local Area Connection Properties (. 4.12).
,
Start (), Settings (), Network and Dial-up Connections. Network and Dial-up Connections (. 4.13), Local
Area Connection, Local Area Connection Status
(. 4.14). Properties
Local Area Connection Properties (. . 4.12).
Local Area Connection Properties . ,
. SQL Server 2000
. . 4.12 ,
TCP/IP. ,
Uninstall.
Install.
Select Network Component Type (. 4.15), .

4. SQL Server 2000

71

. 4.12. Local Area


Connection Properties

. 4.13. Network and Dial-up Connections

72

. 4.14. Local Area


Connection Status

II. SQL Server 2000

. 4.15. Select Network


Component Type

,
Protocol, Add.
Select Network Protocol (. 4.16),
.

. 4.16. Select Network Protocol


Windows NT,
Windows 2000 .

73

4. SQL Server 2000

. TCP/IP, NetBEUI
.


SQL Server 2000.
, ,
, (network
library). (dll, dynamic link library,) .
,
, IPC.
SQL Server 2000
. . 4.6 , SQL Server 2000.
4.6.

AppleTalk ADSP

Apple Macintosh
SQL Server 2000, AppleTalk, TCP/IP Sockets.
, Apple Talk.
, . Windows 95/98

Multiprotocol

RPC .
IPC Windows NT:
TCP/IP Sockets, Named Pipes, NWLink IPX/SPX . .
Windows NT
,
Windows NT . SQL Server 2000 Windows 98

Named Pipes
(
)

SQL Server 2000 Windows NT Windows 2000


.
Windows. , Windows 98 . SQL Server
\\.\pipe\sql\query. SQL Server, \\.\pipe\MSSQLSinstancename\sql\query

NWLink IPX/SPX

SQL Server 2000 Novell NetWare

74

II. SQL Server 2000


4.6 ()

Shared Memory
,
( ) , .
- . SQL Server 2000,
TCP/IP (
TCP/IP)

TCP/IP
.
IPC. -. TCP/IP
.
SQL Server 2000 1433.
Windows 98 TCP/IP

Banyan VINES

, Banyan VINES IP.


Banyan VINES Sequenced Packet Protocol, Banyan VINES IP, IPC

. 6 , SQL
Server 2000 .
, .


SQL Server 2000 ,
. ,
. SQL Server 2000 :
(Local Installation);
(Remote Installation);
(Unattended Installation).
.


. SQL
Server 2000 , . .
, .

4. SQL Server 2000

75_

, , , .
.

SQL Server 2000


Setupsql.exe.
SQL Server 2000 , ,
, ,
SQL Server 2000. \Program Files\Microsoft SQL Server,
\Data SQL Server 2000 (\MssqI).
, . Setup.iss, \Install SQL Server 2000.
,
.
, , . Sqlstp.log,
,
\WinNT. ,
, Errorlog, \Log SQL Server 2000.
, ,
.


SQL Server 2000 ,
SQL Server 2000
. , ,
. SQL
Server 2000 .
SQL Server 2000 :
;
Systems Management Server (SMS).

76

II. SQL Server 2000


, Microsoft. Microsoft Systems Management Server
, ,
,
Windows. SMS (PDF, Package Definition
Format), SMS
(Package), .
SQL Server 2000 Microsoft SMS
1.2 .
SQL Server 2000 smssql.pdf,
SMS. , SQL Server 2000.

~")

pdf , , Microsoft SMS. smssql.pdf


.
smssql.pdf ,
SQL Server 2000.
- SQL
Server 2000:
d smscli.bat
SQL Server 2000 SMS;
smssqins.bat SQL Server 2000 SMS.

Microsoft SMS
. , .

. , . . ""
SQL Server 2000.
""
,
.
. , , . . .

4. SQL Server 2000

77_

:
Notepad
(). .
Setup.iss,
.
, \WinNT.
, , Setup.iss,
.
Setup.iss .
SQL Server 2000 .
Installation Selected Advanced Options. (Advanced Options) Record Unattended.ISS file. ,
,
,
SQL Server 2000. , , . .
. SQL
Server 2000 .
Setup.iss.
.
,
SQL Server 2000 . , ,
, . ,
, .
,
SQL Server 2000
. SQL Server 2000, .
SQL Server 2000 .
, .

Setupsql.exe. :
-fi i n i t i a l i z a t i o n f i l e p a t h x
.

II. SQL Server 2000

s t a r t /wait. SQL Server 2000.


Setupsql.exe.
-SMS. .
-s. (silent mode). .
SQL Server 2000:
start /wait x86\setup\setupsql.exe -s -m -SMS -fl "sqlins.iss"

, , - SQL Server 2000 bat-,


. :
sqlcli.bat SQL
Server 2000;
sqlins.bat
Server 2000;

(typical)

SQL

sqlcst.bat (custom) SQL Server 2000;


sqlrem.bat SQL Server 2000;
sqlupg.bat SQL Server 2000
Windows NT.

, , , iss.
SQL Server 2000
.

bat iss .


SQL Server 2000
, ,
, , ,
. , , Setupsql.exe.
.

4. SQL Server 2000

79_

. . .
, :
Username ,
SQL Server 2000;
Password ;
Domain , ;
Target Computer , SQL Server 2000;
Target Path (UNC) UNC ,
SQL Server 2000;
Setup Source Files UNC SQL Server 2000 .
, , ,
Setupsql.exe . Setup.iss.
Remsetup.exe. Setupsql.exe .
Remsetup.exe ,
.

, Setupsql.exe . Setup.iss, .
Remsetup.exe Admin$, , , SQL Server 2000,
Setup.iss, . , , Remsetup.exe
SQL Server 2000 Setup.iss,
.

. .
,

, Setupsql.exe,
4

.1207

SO

II. SQL Server 2000

, SQL Server 2000.



Setup.iss. . , , , .
,
Remsetup.exe. , , .
,
Setupsql.exe.

, Remsetup.exe
, . ,
. , , Setupsql.exe . ,
, SQL Server 2000.
.
Remsetup.exe ,
Setupsql.exe. Setup.iss SQL Server 2000 . ,
Setup.iss. .

SQL
Server 2000
SQL Server 7.0 SQL.
Server 6.5 , . .
SQL Server 6 5
SQL Server 7.0. SQL Server 2000. SQL
Server 7.0 SQL Server 2000 , SQL Server 6.5. , SQL Server 2000
.
SQL Server 7.0, SQL Server 6.5 - , SQL Server 2000 .
SQL Server 7.0 , SQL Server 6.x SQL Server 7.0
. SQL Server 2000 ,
SQL Server 2000
SQL Server 7.0.

^)

SQL Server 2000 SQL


Server 6.5 SQL Server 7.0.
SQL Server 6.0, SQL Server 6.5 SQL
Server 7.0, SQL Server 2000.

Microsoft SQL Server 7.0 SQL Server 6.5


SQL Server 2000.
, .
, ,
.

, SQL Server 6.5 7.0 SQL


Server 2000 . ,
SQL Server 6.5
MS Access, SQL Server 2000.
. -

82

II. SQL Server 2000

, .
.
SQL Server 2000 SQL
Server 7.0. , SQL Server 2000 , , SQL Server 2000.
.
SQL Server 2000 .
Installation Selection
Upgrade, remove, or add components to an existing instance of SQL Server.
SQL Server 2000 :
(install over SQL Server 7.0) SQL
Server 7.0 SQL Server 2000;
(adding components)
SQL Server 2000;
(build-to-build upgrades)
, . . SQL Server 2000, ;
(edition and component upgrades) SQL Server 2000;
(upgrading to a cluster)
SQL Server 2000.
. ,
SQL Sei'ver 6.5
SQL Server 2000.
SQL Server Upgrade Wizard, Programs
(), Microsoft SQL Server Switch.
,
, , SQL Server 7.0 SQL Server 2000 , SQL
Server 7.0. (Copy Database Wizard).

SQL Server 6.x


, SQL Server Upgrade Wizard SQL Server 6.5 SQL Server 2000.
SQL Server 2000 -

5. SQL Server 2000

83_

, , , ,
, , , ,
. .
, .
SQL Server 6.0, :
SQL Server 7.0 SQL Server 6.0 SQL Server 7.0.

SQL Server 2000 SQL Server 7.0
SQL Server 2000;
SQL Server 6.0 SQL Server 6.5,
SQL Server 2000 SQL Server 6.0 SQL Server 2000. , SQL Server 6.5
SQL Server 7.0, SQL Server 2000.
- .
SQL Server Upgrade Wizard , ,
. -
SQL Server 2000 SQL
Server 6.5 SQL Server 7.0, .
SQL Server 6.5
SQL Server 7.0, SQL
Server 2000.
, , Transact-SQL,
, , .
, SQL Server 6.5 SQL
Server 7.0 .
SQL Server 2000 ,
. Data Transformation
Services SQL Server 6.5 SQL Server 7.0.
DTS . Data Transformation Services . " Data Transformation Services" 11.
Upgrade Wizard.

SQL Server 6.5.


Upgrade Wizard . SQL Server 4.1 SQL Server 6.5,
SQL Server 2000. SQL Server 4.1 SQL

84

II. SQL Server 2000


Server 7.0 . SQL Server 4.1 SQL
Server 6.0, SQL
Server 7.0, . . SQL Server 2000
SQL Server 6.0.



. Upgrade Wizard ,
SQL Server 2000 SQL
Server 6.x:
,
( mdf ndf);
,
( ldf);
Tempdb.
Tempdb . ,
.
, SQL Server 2000 1,5
, SQL Server 6.5.
8 ( SQL Server 6.x 2 ), .
(fill factor) 3050%. .
Upgrade Wizard Service Pack
5.0 SQL Server 6.5. :
SQL Server 6.5
Windows NT Server 4.0 Windows NT Workstation 4.0;
Service Pack 4.0 .
, (user), (login) SQL Server 6.5 , . ,
. ,
, , .
. , . , , , .

5. SQL Server 2000

85_

, ,
.
, SQL Server 2000.
SQL Server ,
. Upgrade Wizard SQL Server 6.5 SQL Server 2000.

.
,
:
, ,
, ;
SQL Server 6.5. ,
;
, Master;
;
SQL Server 6.5,
, DBCC;
Tempdb
10 ( 25 );

SQL Server 6.5

, Master 3 ;
, SQL Server 6.5,
2000.

. , , ,
.


Upgrade Wizard
SQL Server 6.5 SQL Server 2000 :
,
(tape);
(named pipes).

II. SQL Server 2000

gg

SQL Server 6.5 ,


. , ,
. ,
,
SQL Server 2000. . .
Upgrade Wizard
SQL Server 6.5, .

SQL Server 6.5 .



SQL Server 6.5 SQL Server 2000. SQL
Server 6.5, . .

SQL Server 6.5 , .


, SQL
Server 6.5. , .
, , . , , Windows NT Backup.

Upgrade Wizard (devices) SQL


Server 6.5, . ,
, SQL Server 6.5,
, . , SQL Server 6.5.

,
SQL Server 6.5 . UNC.

SQL Server 6.5 SQL


Server 6.5 , . . , , - SQL Server 6.5, .

, ,
. , , -

5. SQL Server 2000

87_

, , , Windows
NT Backup. Windows NT Backup. Upgrade Wizard
,
.


, SQL Server 2000 ,
SQL Server 6.5, SQL Server 2000, SQL Server 6.5. .

. SQL Server 2000. ,


, .
,
. , Upgrade Wizard
. SQL
Server 6.5, SQL Server 2000
\\.

\pipe\sql\query.



. . SQL Server 6.5, .
, . , . . SQL Server 6.5
, .

(^


: SQL Server 6.5 SQL Server 2000.
SQL Server. SQL Server 6.5 SQL Server 2000. , . ,
SQL Server 6.5 SQL Server 2000 .

-

(Export Server) SQL Server 6.5 (Import Server)
SQL Server 2000.

II. SQL Server 2000

.
SQL Server 2000, Upgrade Wizard.
, SQL Server 6.5. SQL Server 6.5 .
. SQL Server 6.5, SQL Server 2000.
,
.

, sa (system administrator),
. SQL Server 6.5 SQL Server 2000.

.
. , .

. , . SQL Server 2000 SQL Server. , SQL Server 2000,
SQL Server 6.5. SQL Server 6.5 (default instance) SQL
Server 2000. .


, Upgrade Wizard SQL Server 6.5 Transact-SQL, SQL Server 2000.
, , ,
, . .

.
.

SQL Server 2000.
,
SQL Server 2000 SQL Server 6.5. .

5. SQL Server 2000

89_

.
""
, .
SQL Server 2000. , SQL Server 6.5,
SQL Server 2000. .
SQL Server 2000
. ,
. ,
, .
,
.
SQL
Server 6.5 . - ,
.
, .
, .
, SQL Server 2000. , . ,
, SQL Server 6.5. SQL Server 6.5, SQL
Server 2000, , .
SQL Server 2000 , SQL Server 6.5. SQL
Server 6.5 , SQL Server 2000
.
, SQL Server 6.5. , , . .
:
;
;
.
, SQL Server. , Internet Information
Server,
Web-.

II. SQL Server 2000

SQL Server 7.0


, SQL Server 7.0
SQL Server 2000 :
SQL Server 2000. SQL Server 7.0,
. , SQL Server 2000;
, SQL
Server 2000. , SQL Server 2000, SQL Server 7.0. Copy Database Wizard.
SQL Server 7.0, . . .


SQL Server
SQL Server 6.x (default instance) SQL Server 2000. . SQL Server 6.x,
SQL Server 2000. vswitch.exe,
:
vswitch -SwitchTo {60 | 65 I 80} [-Silent {0 | 1}]

-SwitchTo , . 65 ( 60) SQL Server 6.5


( SQL Server 6.0), 80 SQL Server 2000. , SQL Server 6.5, SQL
Server 2000 .
(named instance) SQL Server 2000.
SQL Server Programs () Microsoft SQL ServerSwitch. SQL Server 6.5,
Microsoft SQL Server 2000. SQL Server 2000,
Microsoft SQL Server 6.5.
SQL Server vswitch.exe.
SQL Server 2000
. (
MSSQLServerSO) SQL Server 2000. 8.0. (MSSQLServer 65

5. SQL Server 2000

91_

MSSQLServer_6o)
SQL Server 6.x. (MSSQLServer) .
SQL Server 2000, SQL
Server 6.x. , ,
.
vswitch.exe MSSQLServer
. , , MSSQLServer.
.

.
.

SQL
Server 2000

SQL Server 2000 . SQL Server 2000.
SQL Server 2000 -. - CD-ROM SQL Server Automenu
(. 6.1). , SQL Server
Automenu autorun.exe,
-.

. 6 . 1 . SQL Server Automenu

.
:
Install SQL Server 2000 Prerequisites.
Windows 95 , -

6. SQL Server 2000

93

SQL Server 2000. , :

Install Winsock2 Update for Windows 95


Windows 95, SQL Server 2000;

Install Common Control Library Update Windows 95.


Install SQL Server 2000 Components.
,
SQL Server 2000.
SQL Server, .
-. :
Database Server Choice Edition SQL Server 2000.
, SQL Server Automenu Installation Wizard.
. SQL Server 2000
SQL Server Automenu;

Analysis Services , (Online Analytical Processing, OLTP);

English Query English Query, ,


Transact-SQL.

Browse Setup/Upgrade Help.


SQL Server 2000.
Books Online .
Read the Release Notes. Notepad () readme, . SQL Server 2000, Books Online.
Visit Our Web Site. Internet Explorer, http://www.microsoft.com/sql/,
SQL Server.
SQL Server 2000
. SQL Server Automenu
Database Server Install SQL Server 2000 Components,
Installation Wizard, .
setupsql.exe x86\Setup, . , Z:\SQLSTD\x86\Setup\setup.sql.exe, Z: -.

94

II. SQL Server 2000


, Installation Wizard ,
. '
.
(. 6.2) -
.

. 6.2. Installation Wizard

(. 6.3) ,
. :
Local Computer.
, . . , . , .
.
Remote Computer.
.
, ,
SQL Server 2000 .
,
.
, , Browse.

6. SQL Server 2000

95

Windows 98, SQL Server 2000.

Virtual Server. ,
. , .

. 6.3. Computer Name Installation Wizard

, . .
, . , . , Local Computer, ,
Next.
Installation Selection (. 6.4) . ,
,
. :
Create a new instance of SQL Server. SQL Server 2000.

96

II. SQL Server 2000

. 6.4. Installation Selection Installation Wizard

. 6.5. Existing Installation Installation Wizard


Upgrade, remove, or add components to an existing instance of SQL Server. , _ (Build version) SQL Server 2000. -

6. SQL Server 2000

97

- (beta) (evaluation)
(release). ,
, SQL Server 2000.
Existing Installation (. 6.5)
, .
Advanced options. (setup.iss),
. Advanced Options (. 6.6),
Installation Selection. , setup.iss
.
,
SQL Server 2000. .

. 6.6. Advanced Options Installation Wizard

, SQL Server, SQL


Server 7.0,
,
SQL Server 2000 Installation Wizard.

98

II. SQL Server 2000

, .
Create a new instance of SQL Server (. . 6.4).
User Information (. 6.7).
,
. , , , , SQL Server 2000. SQL
Server 2000.
.

. 6.7. User Information Installation Wizard

,
, Software License Agreement
(. 6.8) ,
SQL Server 2000. , Yes,
. SQL Server 2000 - ,
No,
. ,

. ,
SQL Server 2000 , .

6. SQL Server 2000

99

. 6.8. Software License Agreement Installation Wizard


,
Yes,
SQL Server 2000.
Installation Definition (. 6.9) ,
:
Client Tools Only. SQL Server 2000, Enterprise Manager, Performance Monitor, Query Analyzer, Books Online. .
MSSQLServer SQLServerAgent. , ,
, . , .
Server and Client Tools. ,

MSSQLServer, SQLServerAgent,
MSDTC MSSearch. To
SQL Server 2000.
Connectivity Only. . .
, .
SQL Server 2000.

100

II. SQL Server 2000

Windows . ,
, SQL Server 2000. , . ,
.

. 6.9. Installation Definition Installation Wizard

- ,
SQL Server 2000. ,
Server and Client Tools, .
, Instance Name (. 6.10),
SQL Server 2000. ,
(default instance)
(named instance).
NetBIOS ,
SQL Server 2000. ,
_\_.
,
SQL Server (
), .
Instance Name. ,
Default In-

101

6. SQL Server 2000

stance name. , Default


, . , , SQL Server 7.0.
, Default
. ,
Instance name, , . ,
SQL Server 2000.

, . 6.10 Default
Instance name. , . .
SQL Server 2000.

, ,
.

. 6.10. Instance Name Installation Wizard

, ,
Setup Type (. 6.11),
SQL Server 2000. , . "

102

II. SQL Server 2000

" 4. :
Typical . , Microsoft
. ,
,
.
Minimum . . ,
, , .
Custom .
SQL Server 2000. ,
, ,
, . , Custom. Next
. .

. 6 . 1 1 . Setup Type Installation Wizard

, Setup Type
, SQL
Server 2000, .

6. SQL Server 2000

3_

Destination Folder, Program Files Data Files. ,


SQL Server 2000,
, , , ,
MSSQLServer SQLServerAgent.
\Program Files\Microsoft SQL Server , .
Choose Folder, Browse. , Data Files
, SQL Server 2000.
(master, msdb, model tempdb), a
(pubs Northwind),
.
. ,
.
Setup Type SQL Server 2000 .
, .
, ,
. . , . ,
SQL Server 2000
. , ,
,
SQL Server 2000. Required.
. Available ,
.
(

, . ,
. 6.11, ,
, . . . , , , Available .
, SQL Server 2000
. Required Available. ,
.
,
Custom - . "
Custom
Select Components (. 6.12).

II. SQL Server 2000

104

. 6.12. Select Components Installation Wizard

, Select Components , . , .
,
( Components) ( Sub-Components), . Description
.
, .

,
, .

,
.
Server Components. , SQL Server 2000:

SQL Server , . . MSSQLServer


SQLServerAgent.
. , ' .

Replication Support . , .

Full-Text Search . , SQL Server 2000 .

6. SQL Server 2000

105_

Debug Symbols ,
. ,

( dll).
. , . .

Performance Counters .
SQL Server 2000 Windows NT
(Windows 2000) Performance Monitor. ,
SQL Server 2000.
SQL Server 2000,
Performance Monitor (counters), Performance Monitor . .

Management Tools. SQL Server 2000.


. ,
.
Enterprise Manager SQL
Server 2000.

Profiler SQL Server 2000.


Performance Monitor , SQL Server 2000. ,
, . .

Query Analyzer
( Transact-SQL).
DTC Client Support DTC.
Conflict Viewer , . , . ,
.
Client Connectivity. ( ), SQL Server 2000 DB-Library, ODBC
OLE DB. . Installation Definition
(. . 6.9) Connectivity Only, Installation Wizard
.
Books Online. SQL
Server 2000, . . ,

106

II. SQL Server 2000

.
Books Online:
Books Online on Disk.
. ,
37
. , SQL
Server 7.0 11 .

Books Online on CD. . , , , CD-ROM -


SQL Server 2000, . . . ,
Books Online.

Development Tools. , , , :

Headers and Libraries (*.h)


(*.lib), C++
ODBC, DB-Library, Open Data Services, SQL-DMO
Embedded SQL for MSDTC.

Backup/Restore API , , , , .

Debugger Interface
. . ,
Query Analyzer.

Code Samples. C++, . .

SQL Server .
.
, Select Components , Installation Wizard. , Services Accounts (. 6.13). ,
, MSSQLServer SQLServerAgent. Installation Wizard , Use the same

6. SQL Server 2000

107

account for each service. Auto start SQL Server Service. SQL Server 2000 .

. 6.13. Services Accounts Installation Wizard

. , , Customize the settings for each service.


Services, , . , , Service Settings.

, , Service Settings, .

Service Settings :
Use the Local System account.
( )
.
Use a Domain User account.
( ).

,
:

108

II. SQL Server 2000

Username , ;

Password , ;

Domain , . , ,
SQL Server 2000. , .
(

SQL Server 2000


,
. " " 4.

Auto Start Service, .


, SQL
Server 2000 . Use the same account for each service. Auto start SQL Server Service
.
( " }
, MSSearch MSDTC
. .

SQL Server 2000


, . Authentication Mode (. 6.14). , ,
SQL Server 2000:
Windows Authentication Mode.
Windows NT. To
SQL Server 2000, ( ). ,
SQL Server 2000. , ,
. , .
Mixed Mode (Windows Authentication and SQL Server Authentication).
. Windows NT
SQL Server -

6. SQL Server 2000

109

. , sa:

Enter password , sa. sa


SQL Server 2000. . . ,
, sa
. ,
SQL Server 2000 Windows NT. , , ,
, . , ,
, SQL Server. , , , MSSQLServer.
.
, SQL Server
.

. 6.14. Authentication Mode Installation Wizard

Confirm password ,
. ,
.

II. SQL Server 2000

110

Blank Password (not recommended)


sa,
. . Enter password Confirm password
. sa.

. "" 9.
>

, Collation Settings (. 6.15),


, , pubs Northwind, a

. , , SQL Server 2000,
, .
SQL Server, SQL
Server 7.0, SQL Server 2000 . ,
,
. , .

. 6.15. Collation Settings Installation Wizard

6. SQL Server 2000

(~

111

,
. " " 4.
Collation Settings. ,
, . , SQL
Server 2000 Windows SQL Server. , ,
.
, :
Collation designator.
Windows. .
Cyrfflic_GeneraI. , Sort order:

Binary . .
. ,
.

Case sensitive .
.
Accent sensitive . , . .
. , (, ), .
SQL Collation (Used for compatibility with previous versions of SQL Server).

, SQL Server 2000.
.
, ...for use with 1251
(Cyrillic) Character Set.

, SQL Server 2000 SQL


Server. Windows SQL Server.
.
, , Next,
5 1207

112

II. SQL Server 2000

.
, .

. 6.16. Network Libraries Installation Wizard

. 6.17. Start Copying Files Installation Wizard

, Network Libraries (. 6.16) . , -

6. SQL Server 2000

1J3_

pa . , , . ,
SQL Server 2000.
.
Start Copying Files (. 6.17) .
, Next .
,
. Next .


, ,
. SQL Server 2000 .
. SQL Server 2000
.
SQL Server 2000 ,
.
,
. ,
.

SQL Server 2000


, SQL Server 2000 , .
, . , SQL Server 2000 , .
.
, ,
.
. Windows NT 4.0 User Manager
for Domains, Windows 2000
Computer Management ( )
Active Directory User and Computers (
5*

114

II. SQL Server 2000

). . "
" 4.

. 6.18. Services Windows NT 4.0

. 6.1. Services Windows 2000

SQL Server 2000,


. .
Service, Control

115

6. SQL Server 2000

Panel ( ) Windows NT 4.0, Windows 2000.


, .
. . 6.18 Services Windows NT 4.0, . 6.19
Windows 2000.

. 6.20. Service

SQL Server 2000,


,
MSSQLServer, SQLServerAgent
MSDTC. Services
Windows NT 4.0.
s

Startup
(. . 6.18).
Service (. 6.20),
.

Startup Type :
Automatic. .
, SQL Server 2000
.
Manual. .
,
. , .
Disabled. .
. , ,
Manual Automatic.
Log On As , . System Account,
. .
This Account. .
llif- ,
. Password Confirm Password
.

116

II. SQL Server 2000

,
.
Password Confirm Password

, Log on as service,
.
SQL
Server 2000 Windows 2000
, (. . 6.19)
( 6 21)
. ,
. General
, ,

"

127

. 6.21. + , General

<

117

6. SQL Server 2000

. 6.22.
, Log On
,
. Log On (. 6.22).

. 6.23. Select User


, ,
( Local System account), ( This account). , .

118

II. SQL Server 2000

,
. Browse,
Select User (. 6.23)
.
.
.
SQL Server 2000 Enterprise Manager.
MSSQLServer Enterprise Manager
(,
Properties). (SQL Server Properties
(Configure)) ,
MSSQLServer. Security
(. 6.24).

. 6.24. Security

Startup service account ,
, MSSQLServer. System account,
.
Ibis account, .

6. SQL Server 2000

119

Services,
.
.

SQLServerAgeni .
Management, Enterprise Manager. SQLServerAgent . , , General (. 6.25).

. 6.25. General

SQLServerAgent

Service startup account


(System account), (This account), .
.
MSDTC Enterprise
Manager .
Services Control Panel.
, Microsoft Search
.

120

II. SQL Server 2000

SQL Server 2000 Microsoft Search, MSSQLServer Enterprise Manager. Microsoft


Search MSSQLServer ,
MSSQLServer. Enterprise Manager, Microsoft Search.
Services, . Microsoft Search .
Enterprise Manager.



SQL Server 2000
. . , , Unicode Unicode,
SQL Server 2000.
, ,
. "" , . . .
Master. SQL Server 2000, rebuildm.exe,
\Binn SQL Server 2000.
rebuildm.exe
Master, . ,
, .
rebuildm.exe Master SQL Server 2000, , Unicode, SQL Server 2000.
.
Master ,
. ,
,
SQL Server 2000 , . .
. .
(script),
Transact-SQL,
. SQL Server 2000 Transact-SQL,
.

6. SQL Server 2000

121_

.
, , .
, . , , .
- .
SQL Server 2000. .
. (DTS, Data
Transformation Services),
bcp.exe (Bulk Copy Program).
. DTS
, bcp.exe . DTS Designer, DTS Wizard.
, SQL Server 2000
, , . Data Transformation Services, bcp.exe.
,
Transact-SQL BULK INSERT.


SQL Server 2000. (network library). 4.
, ,
.
. .
SQL Server 2000,
. ,
SQL Server Network Utility
(. 6.26), SQL Server 2000.

SQL Server Network Utility (Programs\Microsoft SQL Server\Server Network Utility).


svrnetcn.exe,
\Program Files\Microsoft SQL Server\80\Tools\Binn\.

122

II. SQL Server 2000

. 6.26. SQL Server Network Utility, General

. , General,
. Instance^) on this server SQL Server 2000, .
, (named instance). :
Named Pipes;
TCP/IP ( TCP/IP);

NWLink IPX/SPX.

,
. , (default instance), ,
SQL Server 2000.
Disabled protocols , ,
Enable. Disabled protocols, Enabled protocols, , , Instance(s) on this server.

6. SQL Server 2000

123

, Enabled protocols Disable.


, .
, , .
, , Properties. , . . . 6.27
TCP/IP ( TCP/IP).

. 6.27. TCP/IP

TCP/IP , . , SQL Server 2000. ,


Hide server "" . ,
TCP/IP ,
.
.

,
. , ,
. . .

General SQL Server Network Utility (. . 6.26)


, :
Enable protocol encryption. , , SSL (Secure Socket
Layer). SQL Server 7.0,
Multiprotocol, SQL Server 2000
. ,

II. SQL Server 2000

124

SQL Server 2000 2,


, .

Enable WinSock proxy. . SQL Server 2000


, Internet. - ,
:
WinSock proxy address -;
WinSock proxy port -, SQL Server 2000.
General . Network Libraries
(. 6.28) ,
.

. 6.28. SQL Server Network Utility, Network Libraries

, dll-, .

6. SQL Server 2000

125



. , . , SQL Server 2000.
, ,
, . , . , TCP/IP TCP/IP,
IPX/SPX NWLink IPX/SPX, SQL Server .

SQL Server 2000 , ,


Windows NT Windows 2000.

SQL Server 2000


SQL Client Network Utility, . General
(. 6.29) .

. 6.29. SQL Client Network Utility, General

SQL Client Network Utility (Programs\Microsoft SQL Server\Client Network Utility).

/26

II. SQL Server 2000


cliconfg.exe,
System ( Windows 98) System32 ( Windows NT
Windows 2000) .

Disabled protocols .
Enable. Disabled
protocols, Enabled protocols by order, , . , Enabled protocols by
order Disable.
,
. ,
, , .
, Enabled protocols by
order, . , , . , , ,
. ,
,
. . , Properties.
. .
Enable protocol encryption. , . ,
, , . Enable protocol encryption .
Enable shared memory protocol.
. , .
, ,
.
,
. ,
, ,

. ,
- , ,
.

(server alias).

6. SQL Server 2000

127

, ,
, .
. , , .

Alias (. 6.30).

. 6.30. SQL Client Network Utility, Alias

,
. Remove, Edit.
,
Add, Add Network Library
Configuration (. 6.31).
Server alias , .
, . .
, Network
libraries. Connection parameters . ,
. , Alias.

128

II. SQL Server 2000

. 6.31. Add Network Library Configuration


DB-Library Option SQL Client Network Utility (. 6.32)
DB-Library,
.

. 6.32. SQL Client Network Utility, DB-Library Option

DB-Library infonnation . , dll-, , .

6. SQL Server 2000

129

,
DB-Library :
Automatic ANSI to OEM conversion. OEM ANSI
, ANSI
OEM .
Use international settings. DB-Library
( , ,
. .), . , .

Automatic ANSI to OEM conversion , Use international settings , 32- .

.
Network Libraries (. 6.33).

. 6.33. SQL Client Network Utility, Network Libraries

, , dll-,
.

III.

7. SQL Server 2000


8. SQL Server 2000
9. SQL Server 2000
10.
11.
12. SQL Server 2000
13.
14.
15.
16.


SQL Server 2000
, SQL Server 2000 .
, SQL
Server 2000, .
, ,
. SQL Server 2000,
.

.
, . SQL Server 2000 ,
.
, . , SQL Server 2000 , . .


SQL Server 2000 .
. " " 3.
, SQL
Server 2000 MSSQLServer.
,
, ,
. SQL Server 2000 , MSSQLServer. ,
SQLServerAgent , .
. , MSSQLServer. SQLServerAgent
, MSSQLServer. SQL

124

III.

Server 2000. MSSQLServer SQL Server 2000.

,
, SQL Server 2000, . ,
. SQL
Server 2000 . , Service Manager, Enterprise Manager Services Control Panel ( )
.
SQL Server 2000,
, .
,
SQL Server 2000.
SQL Server 2000.

, Windows 98 ,
SQL Server 2000 .

(start) , ,
.
, .
. ,
, . MSSQLServer , .

, SQL Server 2000 . , , . ,


, .

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

7. SQL Server 2000

13S_

MSSQLServer ,
, . .
.
npuocmanoe (pause) . , , , . ,
,
.
, . , ,

.
, . , , . SQL Server 2000
, MSSQLServer ,
SQLServerAgent, Full-Text Search MSDTC .

SQL Server Service Manager


SQL Server Service Manager (. 7.1) ,
SQL Server 2000. ,

.
Service Manager
SQL Server 2000

.

Startup (),
Programs () .
. 7.1. Service Manager
,
. ,
, , , -
. Startup Service Manager.
Service Manager (taskbar). -

136

III.

(. . 7.1). ,
SQL Server 2000,
.
. ,
Server, , SQL
Server 2000. SQL Server 2000,
.
.
, Server , Services
, SQL Server 2000.
, , .

Services.
, . . ,
(Pause) (Stop),

(Start/Continue).

,
Service Manager. . , SQL Server 2000.
, , .
Service Manager .
, Service Manager
, .
,
Refresh services. , Service Manager
. Service
Manager ,
5 . ,
Service Manager Options < SQL Server Service Manager Options (. 7.2).
Default service , Service Manager.
Polling interval . Verify
service control action ,
MSSQLServer , (, SQLServerAgent).

7. SQL Server 2000

137

, ,
.

. 7.2. SQL Server Service


Manager Options

Service Manager .
,

.
, Enterprise Manager,
Services Control
Panel , .
Service Manager.

Enterprise Manager
Service Manager SQL Server 2000
, . Enterprise Manager Query Analyzer,
. Enterprise Manager , ,
Service Manager.

Enterprise Manager ,
, , .
Service Manager
, Enterprise Manager . MSSQLServer
Enterprise Manager (. 7.3). , Action
. Service Manager,
.
, , Enterprise Manager , (connect)
(disconnect). Enterprise Manager
, . . , . ,

III.

138

, , Action Disconnect.
,
Connect.

. 7.. MSSQLServer Enterprise Manager


Enterprise Manager ,
. Enterprise
Manager .
(, ). Enterprise Manager .
, SQL Server 2000
MSSQLServer.

, MSSQLServer
Enterprise Manager,
Query Analyzer, Start SQL Server if it is stopped
( SQL Server ) Connect to SQL Server (. 7.4).

7. SQL Server 2000

139

Query Analyzer
Connect File. SQL Server ,
. , .

. 7.4. Connect to SQL Server


MSSQLServer.

SQLServerAgent

MSSQLServer.
SQLServerAgent (. 7.5).
Management .

, Action. ,
SQLServerAgent
Pause, . . .

. 7.5. SQLServerAgent Enterprise Manager

III.

140

Full-Text Search Microsoft Distributed Transaction Coordinator


(MSDTC) MSSQLServer SQLServerAgent.
Full-Text Search, MSDTC Support Services (. 7.6).
, SQLServerAgent, .

. 7.6. Full-Text Search, MSDTC SQL Mail

Services
SQL
Server 2000 SQL Server 2000.
Services.
Services
. Service Manager Enterprise Manager
SQL Server 2000, Services
, .

, Windows 98
. Windows NT, . . Windows 2000.

141

7. SQL Server 2000

Services
Control Panel ( ) .
Services Windows NT 4.0 Windows 2000. .
Windows NT 4.0 Services Control Panel, , Start (), Settings
(), Control Panel ( ).
(. 7.7) Services.

. 7.7. Control
Panel
Services (. 7.8). ,
. :
Service .
Status . ,
Started. .
Startup
. Automatic, Manual Disabled.
.

142

III.

Startup Parameters, . .

. 7 . 8 . Services Windows NT 4.0

,
.
. :
Start - .
Pause .
,
.
Continue , . . .
Stop .
.
, , ' . , , ,
.
SQLServerAgent MSSQLServer,
MSSQLServer, SQLServerAgent.
( ) Services Windows 2000
Windows NT 4.0.
Services Windows 2000 Control Panel
Administrative Tools Programs
(). Services,
Services (. 7.9).

7. SQL Server 2000

143

Windows 2000
Services. , Computer Management.

. 7.9. Services Windows 2000


,
Microsoft (MMC, Microsoft Management Console).
Microsoft
, . Windows 2000
.
Enterprise Manager.
,
. , .
:
Name , .
, .
Description .
6

.1207

144

III.

d Status . , Started. .
Startup Type . Automatic, Manual Disabled.
.
Log On As , .

, . ,
.
:
;
.

,
. , Services
Windows 2000 Restart. . , . ,
.
, .

Action
Properties.
.
General (. 7.10), :
Service name . .
Display name , Services. ,
.
Description . Services.
, .
Path to executable , .
Startup type .

145

7. SQL Server 2000

Service status (, ).
Start .
Stop ,
.
Pause , . ,
.
Resume ,
, . . .
Start parameters ,
.

. 7.10. General

SQL Server 2000


Services .

. ,
SQL Server 2000 Services Service Manager Enterprise Manager . .

146

III.


SQL Server 2000
.

, SQL Server 2000 .
net.exe.
, , , , , , .

(~

net.exe , n e t / ?.

:
net s t a r t
net stop

[service]

[service] ;

net pause [service] ;


net continue [service] .
[service] ,
. , MSSQLServer :
net s t a r t MSSQLServer

:
The MSSQLServer service is starting...
The MSSQLServer service was started successfully.

,
, .
. ,
MSSQLServer Trelon
:
net s t a r t MSSQL$Trelon

net s t a r t .

7. SQL Server 2000

147_

Transact-SQL

. Transact-SQL.
SHUTDOWN, :
SHUTDOWN

[WITH NOWAIT]

WITH NOWAIT, TO . .
.
WITH NOWAIT , . , .
.

SQL Server 2000


SQL Server 2000 , SQL
Server 2000 MSSQLServer. SQL Server 2000 . sqlservr.exe,
\Program Files\Microsoft SQL Server\MSSQL\Binn.

SQL Server 2000 , . , SQL Server 2000


, . , .

, SQL Server 2000


(application log)
SQL Server 2000, .
, SQL Server 2000
.
2001-08-05 22:53:40.64 s e r v e r
Microsoft SQL S e r v e r 2000 - 8.00.100
( I n t e l X86)
Apr 18 2000 01:19:00
Copyright (c) 1988-2000 Microsoft Corporation
Standard Edition on Windows NT 5.0 (Build 2195: )
2001-08-05 22:53:40.69 server
tion.

Copyright (C) 1988-2000 Microsoft Corpora-

2001-08-05 22:53:40.72 server

All rights reserved.

148

III.

2001-08-05 22:53:40.73 server


Server Process ID is 652.
2001-08-05 22:53:40.74 server
Logging SQL Server messages in file
'G:\Program Files\Microsoft SQL Server\MSSQL\log\ERRORLOG'.
2001-08-05 22:53:40.81 server
SQL Server is starting at priority class
'normal'(1 CPU detected).
2001-08-05 22:53:40.93 server
User Mode Scheduler configured for thread
processing
2001-08-05 22:53:40.97 server
Using dynamic lock allocation. [2500] Lock
Blocks, [5000] Lock Owner Blocks
2001-08-05 22:53:41.02 server
Attempting to initialize Distributed Transaction Coordinator.
2001-08-05 22:53:42.14 spid3
Starting up database 'master'.
2001-08-05 22:53:42.62 spid3
0 transactions rolled back in database
'master' (1).
2001-08-05 22:53:42.65 spid3
Recovery is checkpointing database 'master'
(1)
2001-08-05 22:53:42.85 server
Using 'SSNETLIB.DLL' version '8.0.100'.
2001-08-05 22:53:42.92 server
SuperSocket Info: Bind failed on TCP port
1433.
2001-08-05 22:53:42.96 spid5
Starting up database 'model'.
2001-08-05 22:53:42.98 spid3
Server name is 'STORAGE'.
2001-08-05 22:53:42.99 server
SQL server listening on TCP, Shared Memory,
Named Pipes.
2001-08-05 22:53:43.03 server
Ready For Connections
2001-08-05 22:53:43.05 spid7
Starting up database 'itisdb'.
2001-08-05 22:53:43.06 spid8
Starting up database 'pubs'.
2001-08-05 22:53:43.08 spid9
Starting up database 'Northwind'.
2001-08-05 22:53:43.61 spid5
Clearing tempdb database.
2001-08-05 22:53:44.81 spid5
Starting up database 'tempdb'.
2001-08-05 22:53:45.05 spid3
Recovery complete.
SQL Server 2000 ,
, . ,
,
, , . .
, Enterprise Manager.

SQL Server 2000, , net stop MSSQL$lnstName, ,


. SQL Server 2000, ,
Transact-SQL SHUTDOWN,
<Ctrl>+<Break> <Ctrl>+<C>.
SQL Server 2000
Binn . .
, - s . , Trelon

7. SQL Server 2000

149_

\Program Files\Microsoft SQL Server\MSSQL$Trelon\Binn .


sqlservr.exe -strelon

, SQL Server 2000 . , SQL


Server 2000 Storage,
Storage\Trelon.

Enterprise Manager, Query Analyzer


SQL Server 2000, . SQL Server 2000 .
SQL Server 2000,
. ,
. , \Program Files\Microsoft SQL
Server\ MSSQL$InstName
. :
HKEY_LOCAL_MACHINE
\SOFTWARE
\Microsoft
\ Microsoft SQL Server
\[Instance name]

,
. . "
SQL Server 2000" .
. . sysdatabases
Master, .


, , SQL Server 2000, .
, SQL Server 2000 .
4 , SQL Server 2000.
,

150

III.

Windows NT 4.0 Windows 2000. , SQL Server 2000 .



. , .
- ,
.
. , , ,
.
,
. , , ( User Manager
Windows NT 4.0, Active Directory Users and Computers Windows 2000).
.
, , .

SQL Server 2000. . . " " 4
.

Enterprise Manager
MSSQLServer
Enterprise Manager (, Properties).
(SQL Server Properties) ,
MSSQLServer.
Security (. 7.11).
Startup service account ,
, MSSQLServer.
System account,
. This account,
.

(~~

Services, Enterprise Manager


.
.

7. SQL Server 2000

151

. 7.11. Security

SQLServerAgent .
Management, Enterprise
Manager. SQLServerAgent . , ,
General (. 7.12).
Service startup account
( System account),
( This account), .
.
MSDTC Enterprise
Manager .
Services Control Panel.

SQL Server 2000 Microsoft Search,


MSSQLServer Enterprise Manager. Microsoft
Search MSSQLServer ,

152

III.
MSSQLServer.
Enterprise Manager,
Microsoft Search. Services, .
Microsoft Search .
Enterprise Manager.

. 7.12. General

SQLServerAgent

Enterprise Manager , SQL Server 2000,


. Enterprise
Manager . ,
SQL Server 2000.
, MSSQLServer,
,
, .
.
Enterprise Manager .
, Enterprise Manager
MSSQLServer SQLServerAgent.
MSDTC Full-Text Search .

7. SQL Server 2000

153

Services
,
Services .
,
,
.

. 7.13. Service


Services Windows NT 4.0
(. . 7.8) ,
.
SQL Server 2000, ,

MSSQLServer, SQLServerAgent MSDTC.

Startup.
Service (. 7.13),
.

Startup Type :
Automatic. .
, SQL Server 2000
.
Manual. .
,
. , .
Disabled. .
.
, Manual,
Automatic.

Log On As , . System Account,


.
. This
Account. . .
, .
Password Confirm Password .

III.

154

,
. ,
Password Confirm Password .
.

, ,
(Log on as a service), , .
, ,
, . " " 4.


Windows 2000 Services .
, Services, .
. , General (. . 7.10),
.
Startup Type. Services Windows NT 4.0.
, ,
Log On (. 7.14).

. 7.14. Log On

7. SQL Server 2000

155

Service Services Windows NT 4.0. Apply.


. .

SQL Server 2000


, SQL Server 2000
Start ,
.

. 7.15. SQL Server 2000


,
.
Master , .
SQL Server 2000. SQL
Server 2000 . ,
, , SQL Server 2000.
:

156

III.

HKEY_LOCAL_MACHINE
\SOFTWARE
\Microsoft
\MSSQLServer
\MSSQLServer
\Parameters

(. 7.15). ,
sqlservr.exe. . , Enterprise
Manager, .

:
HKEY_LOCAL_MACHINE
\SOFTWARE
\Microsoft
\Microsoft SQL Server
\[Instance name]
\MSSQLServer
\Parameters

. 7.1.
7.1. SQL Server 2000

-d<master_file_patch>

Master (master.mdf).

-l<master_log_path>

Master (mastlog.ldf)

-e<error_log_patch>


SQL Server 2000.
, .
,
SQL Server 2000.
SQL Server 2000

, . 7.1, SQL
Server 2000. .
SQL Server 2000, Microsoft .
MSSQLServer Parameters .

7. SQL Server 2000

157

.
.
.
SQL Server 2000 sqlservr.exe
,
. SQL Server 2000
Master.
Master .
SQL Server 2000 Mast e r . SQL Server 2000.
, SQL
Server 2000, ,
.
Master, .
, .

SQL Server 2000 , SQL Server 2000 ,


. , SQL Server 2000
Master.
. , .


SQL Server 2000 ,
, , ', . . SQL Server 2000
.
SQL Server 2000 ,
, . , ,
Master.

, . .
,

158

III.

, . SQL
Server 2000 (single-user mode).


. , SQL Server 2000 , .
SQL Server 2000
MSSQLServer , .
.
, SQL Server 2000.
-
.
, SQLServerAgent,
.
SQL Server 2000 ,
, .
, , ,
(checkpoint process). , , . , ,
, . ., SELECT,
DELETE,INSERT UPDATE.

SQL Server 2000


. , EXEC sp_configure ' a l l o w updates'. Microsoft SELECT,
UPDATE, INSERT DELETE.
. .
, .
, SQL Server 2000 "" .
, , -

7. SQL Server 2000

159

. -, .
SQL Server 2000 -:
sqlservr.exe -

, SQL Server 2000


. , Parameters SQL Server 2000 -. SQL Server 2000
. SQL Server 2000 , .
.


SQL Server 2000 ,
, . ,
(, )
. , .
. -
, , .

(minimal configuration), .
:
, SQL
Server 2000, , ;
(open databases), (locks),
(open objects), (language in cache), max async asynchronous I/O;
, ;
, . .
SQL Server 2000 ;
,
, ;

160

III.


(
).
SQL Server 2000 -f:
sqlservr.exe -f

SQL Server 2000 , . , .

SQL Server 2000


, SQL Server 2000.
.
, SQL Server 2000 , . ,
.
. , SQL Server 2000
, .
, SQL Server 2000 - . , ,

. , , . .

MSSQLServer
MSSQLServer, SQL Server 2000,
Enterprise Manager,
sp__configure.
.
MSSQLServer Enterprise Manager
SQL Server Properties. Enterprise Manager Properties. ,
. 8.1.
SQL Server Properties ,
. , :
Configured values.
, . -

III.

162

reconfigure . ,
, . Configured values.
Running values. ,
, . .
, . .
, .
Configured values.

i !

. 8 . 1 . SQL Server
Properties

,
SQL Server 2000.
.
sp_conf igure :
sp_configure [[@configname =] 'name'] [, [Sconfigvalue =] 'value']

[Oconfigname =] 'name' , . , , [Oconfigvalue =] ' v a l u e ' .

8. SQL Server 2000

163

,
, exec. ,
exec s p _ c o n f I g u r e .
, exec . exec
.

, .
, . , .
SQL Server 2000 , (advanced)
.
:
sp_configure 'show advanced options', 1

^)

, , .

MSSQLServer.

General
General (. . 8.1) SQL Server Properties
, , , SQL Server, , , , , SQL Server 2000 .
Autostart policies when the operating system starts SQL Server 2000. .
.
Startup Parameters,
(. 8.2), SQL Server 2000, SQL Server 2000,
SQL Server 2000 . SQL
Server 2000 . 8.1. Startup Parameters. , SQL Server 2000
s q l s e r v r s q l s e r v r . e x e .

, , .

III.

164

SQL Server 2000


s q l s e r v r s q l s e r v r . e x e
.
SQL Server 2000

. " SQL Server 2000 " 7.

. 8.2. Startup Parameters


8.1. SQL Server 2000

SQL Server 2000


(singleuser mode). SQL Server 2000,

-f

SQL Server 2000 .


, . .
. " "

-d<master_file_path>

SQL Server Master.


, \Program
Files\Microsoft SQL Server\Mssql\Data\Master.mdf.
,

-e<error_log_path>

.
, \Program Files\Microsoft
SQL Server\Mssql\Log\Errorlog

-l<master_log_path>


Master. , \Program Files\Microsoft SQL
Server\Mssql\Data\Mastlog .Idf
SQL Server 2000 .
. " SQL Server 2000
" 7
-s
, SQL Server 2000
(Windows NT Service Control
Manager).

8. SQL Server 2000

/65

8.1 ()

SQL Server 2000 (application log) . - ,


.

-p<precision_level>


, decimal numeric.
< p r e c i s i o n _ l e v e l > 1 38.
SQL Server 2000
38

-T<trace#>

SQL Server 2000 .


.

, ,
Books Online

-v


SQL Server 2000.

, SQL Server 2000,

-g<memory_to_reserve>
, SQL
Server 2000.
-

DCOM
(Distributed COM), ,

-y<error_number>


(error log)
<error__number>,
-

SQL Server 2000


:
HKEY_LOCAL_MACHINE
\SOFTWARE
\Microsoft
\MSSQLServer
\MSSQLServer .
\Parameters

III.

166

, Startup Parameters (. . 8.2), . SQL


Server 2000 Startup Parameters , SQL Server 2000.
. 8.3 Registry Editor (regedit.exe) ,
SQL Server 2000.
. . " SQL Server 2000
" 7. SQL Server 2000 -s.

. 8.3. , SQL Server 2000

SQL Server 2000 , , .

General Network Configuration. SQL Server Network Utility, .


. " " 6.

167

. SQL Server 2000

Memory
, Memory (. 8.4)
, SQL Server 2000.

. 8.4. SQL Server


Properties, Memory
SQL Server 7.0 . SQL Server 7.0 SQL Server 2000 . ,
, SQL Server 2000.
SQL Server 2000 , . ,
, .

, SQL Server 2000. ,
,
. .
, . . SQL

168

III.

Server 2000 , .
, .
Dynamically configure SQL Server memory
Memory SQL Server Properties
, SQL Server 2000.
Minimum (MB) Maximum (MB)
, . 0 ,
.
4 . , SQL Server 2000,
sp_configure 'max server memory', <_>.

:
sp_configure 'min server memory', <_>.

SQL Server 2000


, 5
/ 200 .
.
, SQL Server 2000 . .
5 , SQL Server 2000
.

, -, 16 .
( Full-Text
Search), SQL Server 2000
50%.
SQL Server 2000 .
, Use a fixed memory size (MB).
, SQL
Server 2000.
SQL Server 2000, , .

8. SQL Server 2000

169

Minimum (MB) Maximum (MB) (


) , , .
Windows NT ( Windows 2000) .
(pagefile swapfile). , .
SQL Server 2000,
, SQL Server 2000 .
, Reserve physical memory for SQL
Server. SQL
Server 2000 . :
sp_configure 'set working set size', 0 | 1

, SQL Server 2000,



, . . ,
SQL Server 2000 .
, SQL Server 2000.
Memory Minimum query
memory (KB). , .
512 2 . ,
, . ,

. , , :
sp_configure 'min memory per query', <_>.

Processor
Processor (. 8.5) , SQL
Server 2000 .

III.

170

. 8.5. SQL Server


Properties, Processor

, ,
SQL Server 2000.
, SQL Server 2000
.
. , , , SQL
Server 2000.

, Windows NT 4.0, Windows 2000, Windows NT. ,


.

SQL Server 2000


Windows NT 4.0 Windows 2000, , Microsoft, 32 . Windows NT Windows 2000 . ,
,
.

8. SQL Server 2000

171

Windows NT Server 4.0 4 ,


Windows NT Server 4.0 Enterprise Edition - 32, Windows NT Workstation 4.0
2. Windows 2000 Professional 2
, Windows 2000 Advanced Server
32 .
Windows NT ,
(process), . , , .
, ,
(threads). , .
. , . .
SQL Server 2000 . Processor , . Maximum worker
threads. ,
SQL Server 2000.
Transact-SQL :
sp_configure 'max worker threads', < >

10 1024.
255.
,
. SQL Server 2000 . . ,
,
, .
, SQL Server 2000 ,
. .
.
, ,
!.
, -

172

, . .
Windows NT
(protected mode). , SQL Server 2000,
(user mode).
, . ,
. SQL Server 2000 (fibers).
Windows NT . , . . , , . .
. SQL Server 2000, Use Windows NT fibers.

Use Windows NT fibers , SQL Server 2000


Windows 98. ,
Windows 98 .
Boost SQL Server priority on Windows NT/2000 SQL Server 2000 ,
. , SQL Server 2000 .
, SQL Server 2000 ,
. ,
SQL Server 2000.
,
, SQL Server 2000 . Boost SQL Server priority on Windows NT/2000 , , Enterprise Manager.
Boost SQL Server priority on Windows NT/2000 , SQL Server 2000
.
SQL Server 2000 Transact-SQL :
sp_configure 'priority boost', I 1

^)

p r i o r i t y boost SQL Server 2000


13. , 7. p r i o r i t y boost .

8. SQL Server 2000

173_

Parallelism , .
Use all available processors.
, . Use .
.
, . . ,
,
.
. ,
.
, , .
, (parallel execution cost). , .
(statistics).


.
.
(update).
UPDATE S T A T I S T I C S , -


sp_update_stats.

,
. , , , . ,
. Minimum query plan threshold for considering queries for
parallel execution (cost estimate). ,
5 .
Transact-SQL :
sp_configure ' cost threshold for parallelism1, < >

III.

174

Security
Security (. 8.6) SQL Server 2000.

. 8.6. SQL Server


Properties, Security

SQL Server 2000 : (mixed) Windows NT.


,
SQL Server, Windows NT. SQL Server .
, SQL
Server 2000, Authentication.
SQL Server and Windows NT/2000,
.
Windows NT/2000 only, SQL
Server,
Windows NT.

9.

8. SQL Server 2000

175_

Audit level (),


SQL
Server 2000. None, .
Success SQL Server 2000
.
, Failure. All , .

SQL Server 2000 Enterprise


Manager, Management\SQL Server Logs . Current. . .
Startup service account ,
MSSQLServer.
System account
. This account,
.

,
SQL Server 2000, . " " 4.

Transact-SQL SQL
Server 2000. 7.

Connections
Connections (. 8.7) ,
, .
Maximum concurrent user connections (0 =
unlimited), ,
. 0, , SQL Server 2000, 32 767.
SQL Server 2000 ,
7 1207

III.

176

, .
40 ,
.

. 8.7. SQL Server


Properties, Connections
0, SQL Server 2000 , .
.

:
sp_configure 'user connections', <0 - 32767>


@@MAX_CONNECTIONS:
SELECT

@@MAX_CONNECTIONS

:
32767
(1 row(s) affected)

8. SQL Server 2000

177_


sp_conf igure:
sp configure 'user connections'
:
name
minimum
maximum
user connections

327 67

config_value run__value
0

, 0, 32 767.
Allow other SQL Servers to connect remotely to this SQL Server using RPC
SQL Server 2000
(RPC, Remote Procedure Call).
, ,
.
, . :
sp_configure 'remote access', 0 11

Query time-out (sec, 0 = unlimited)


, .
,
.
Query time-out (sec, 0 = unlimited) 0. .
, . , , (deadlocks).
- :
sp_configure 'remote query timeout', <0 - 2147483647>
Enforce distributed transactions (MTS), (MSDTC, Microsoft Distributed Transaction Coordinator).

ACID.
:
sp_configure 'remote p r o c t r a n s ' , Oil
Connections Default connection options, .
.
SET. ,
, ,
.
7*

III.

178

Server Settings
Server Settings (. 8.8) . , , .

. 8.8. SQL Server


Properties, Server
Settings
Server Settings
Default language for user, ,
. SQL Server 2000 . SQL Server 2000
, , .
sysmessages
Master. , .

8. SQL Server 2000

179

Default language for user , Language. . ,


, Language,
SQL Server Login Properties.
.
SQL Server 2000 ,
.
, . , Default language for user. :
sp_configure 'default language', <0 - 9999>

.
syslanguages Master.

, , ,
SET LANGUAGE.
Server behavior
. :
Allow modifications to be made directly to the system catalogs
.
INSERT, UPDATE DELETE. ,
SELECT. . Microsoft
.
SQL Server. Microsoft , , . , ,
SQL
Server.
:
sp_configure

'allow updates',

Oil


, -

180

III.

, . ,
, .
Allow triggers to be fired which fire other triggers (nested triggers) (nested triggers). , ,
.
. , ,
. . , . 16.
, , .

, , SQL Server 2000 , . .


:
sp_configure

'nested

triggers',

Oil

Use query governor to prevent queries exceeding specified cost , .


, .
, , ,
.
.
:
sp_configure 'query governor cost l i m i t ' , <0 - 2147483647>

- - . , .
.
.
SQL Mail Start mail session using profile,
,
MSSQLServer . Change

8. SQL Server 2000

181_

, , .
MSSQLServer. , , MSSQLServer
. Server Settings .

MSSQLServer SQLServerAgent .
.
, .
SQLServerAgent .
Server Settings Year 2000
support, , SQL Server 2000
, .
(datetime smalldatetime) . . .

. 1950 and 2049.
, 50 99
XX , 0 49 XXI . ,
"39".
datetime smalldatetime 2039.
78, 1978. :
sp_configure

'two digit year c u t o f f ,

<1753 - 9999>

, 2049.

Database Settings
Database Settings (. 8.9) , .
Settings,
(fill factor) . ,
, . .
.

III.

182
jgj

. 8.9. SQL Server


Properties, Database
Settings

Database Settings . , . .
, . . .
, . .
, , . .
, , .
. ,
(split page).
,
. , , . "", .
,
, .

8. SQL Server 2000

183_

,
. ,
,
. , . , , 100%. (DSS,
Decision Support System) , .

(~

, ,
, 100%. 500 ,
800 .
, Fixed ,
. .
SQL Server 2000 B-depeea (B-tree).
Fixed , , 100%, .

.
Fixed ,
,
. , , ,
.

:
sp_configure ' f i l l f a c t o r ' , %>
Backup/restore
. ,
Time-out period ,
:
Wait indefinitely . , .
Try once then quit , ,

.
Try for ,
. -

184

III.

, .
Default backup media retention (days) , , SQL
Server 2000 . . .
10.
Database Settings Recovery interval (min).
, SQL Server 2000
(recovery database). SQL Server 2000. ,
(rollback) (commit)
, . 0 , SQL Server 2000
. .
, ,
SQL Server 2000 (check point). ,
SQL Server 2000.
, , , .
, SQL Server 2000 .
SQL Server 2000 , . , Recovery interval (min), .
:
sp configure 'recovery i n t e r v a l ' , <0 - 32767>

, .

tion.
,
.

New database default loca ,



:

Default data directory. , (mdf ndf). ... |


, , .
Default log directory.
.

8. SQL Server 2000

185

Replication
SQL Server 7.0, ,
SQL Server Properties SQL Server 2000
.
SQL Server 2000 Replications (. 8.10).

. 8.10. SQL Server


Properties, Replication
Replications .
,
14.

SQLServerAgent
MSSQLServer,
SQL Server 2000.
SQLServerAgent, SQL Server 2000.
SQLServerAgent SQL Server Agent Properties (. 8.11).

III.

186

Enterprise Manager ,
, \Management SQLServerAgent Properties.

. 8.11. SQL Server


Agent Properties

General
General (. . 8.11) SQLServerAgent. Service startup account
, SQLServerAgent.
System account .
, This account
. SQLServerAgent
MSSQLServer , .

,
SQL Server 2000, . " " 4.
Mail session , . Mail profile
, . -

8. SQL Server 2000

1_87_


SQLServerAgent . Mail profile.
Test, Mail profile .
Save copies of the sent messages in the "Sent Items"
folder, \ .
.
Error log SQLServerAgent. : , . File name ,
. View.
. , Include execution trace messages. He .
.

SQLServerAgent.
Unicode
. .
, ,
Write OEM File. ,
.

SQLServerAgent ,
. ,
.
General Net send recipient. NetBIOS ,
(pop-up messages) SQLServerAgent.
Windows NT
NET SEND.

Advanced
Advanced (. 8.12)
,
.

III.

188

. 8.12. SQL Server


Agent Properties,
Advanced
Restart services , SQL Server 2000 :
Auto restart SQL Server if it stops unexpectedly
MSSQLServer.

Auto restart SQL Server Agent if it stops unexpectedly


SQLServerAgent.

,
,
SQL Server 2000 . - .
SQL Server event forwarding SQL Server 2000, , (application log) Windows NT .
.

, .
, .
Forward events to a different server,
. Server -

8. SQL Server 2000

189_

SQL Server 2000,


. Events , :
Unhandled events. ,
(alerts).
All events. , .
, , (severity
level) . ,
, If event has severity of or above.

("""

,
, 12.
Advanced Idle CPU condition. . (jobs) SQLServerAgent
. , .
Tire
computer is idle when Average CPU usage falls below . And remains below this level for ,
Average CPU usage falls below . , .

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

Alert System
Alert System (. 8.13) , .
Address formatting for pager e-mails , .
, -

III.

190

Alert System,
.
. , ,
Prefix Suffix, Subject ,
.

. 8.13. SQL Server


Agent Properties,
Alert System
Include body of e-mail in notification page
. .
, .
Fail-safe operator (failsafe operator). Notify using :
E-mail ;
Pager ;
Net send NET SEND.

,
. , ,

191

8. SQL Server 2000

.
. , , 12.

Job System
Job System (. 8.14)
: ,

.

. 8.14. SQL Server


Agent Properties,
Job System
SQLServerAgent ,
, . , Msdb.

. ,
.
Job history log ,
. , SQLServerAgent
, .
, limit size of job history log. Maximum job history log size (rows)

\Q2

III.

, .
Maximum job history rows per job
.
, , Current job
history log size (rows). Clear Log
, .
Shutdown time-out interval (seconds) Job execution ( ) , , SQLServerAgent.
. Master SQLServerAgent
(MSX) server ,
.
Non-SysAdmin job step proxy account , ActiveX .
, ActiveScripting CmdShell
sysadmin.
CmdShell
SQLAgentCmdExec,
SQL Server 2000. CmdExec - , , SQLAgentCmdExec . , -
,
.
SQLAgentCmdExec
User Manager for Domains.
CmdShell . SQLAgentCmdExec Reset
Proxy Account Job System. Reset Proxy Password
.

Connection
MSSQLServer SQLServerAgent
, .
Connection (. 8.15)
SQLServerAgent MSSQLServer.
SQL Server connection ,
SQLServerAgent. Windows NT. ,
SQLServerAgent,
sysadmin.
.
, MSSQLServer SQLServerAgent
.

8. SQL Server 2000

193

. 8.15. SQL Server


Agent Properties,
Connection
Use SQL Server Authentication,
SQL Server 2000, .
sysadmin.

Login time-out ( ),
SQLServerAgent

MSSQLServer.
.
Local host server (aliases) , .
. SQL Server
Client Network Utility.


sp_configure
, SQL Server 2000 . Enterprise Manager.

III.

194

Transact-SQL, ,
sp_configure.
, Enterprise Manager. sp_configure. . 8.2 ,
MSSQLServer.

, ,
(*). (+) , SQL Server 2000
SQL Server 7.0.

0.
,
. 0
, .
8.2. sp^con figure

a f f i n i t y mask *

2 147 483 647

SQL
Server 2000 ,

allow updates *



INSERT, UPDATE, DELETE
SELECT

awe enabled +



64 (AWE, Address Windowing Extensions)

c2 audit mode +

2, ,

Transact-SQL

cost threshold

32767

for
parallelism *

195

8. SQL Server 2000

8.2 ()

cursor
threshold

-1

2147483647

-1

1
,

default f u l l text language +

2147483647

1033

,

,

default
language *

gggg

fill

100

704

2147483647

5000

2147483647

max degree of
parallelism*

32

max server
memory *

2147483647 2147483647
,
SQL Server 2000

max text repl


size

2147483647

65536

max worker
threads *

10

32767

255

factor*

index create
memory
lightweight
pooling

locks


( t e x t , n t e x t
image),

,
SQL Server 2000

1
,
.

III.

196

8.2 ()

no

365

512

2147483647

1024

min server
memory *

2147483647

, SQL Server 2000

nested
triggers *

512

65536

4096

open objects

2147483647

priority
boost *

, SQL
Server 2000
(13) (7)

query governor
cost l i m i t *

2147483647

.

,

query wait

-1

2147483647

-1


,
.

-.
-1 25
.
0

recovery
interval *

32767

remote access *

media
retention *
min memory per
query *

network packet
size

197

8. SQL Server 2000

8.2 ()

remote login
timeout

2147483647

20

remote proc
trans *

ACID MSDTC

remote query
timeout *

2147483647

,
,

-

scan for
startup procs

1
,

set working
set size *

SQL Server 2000

show advanced
options

1753

9999

2049

user
connections *

32767

user

16383

two d i g i t
cutoff *

year

options


SQL Server 2000

SQL Server 2000. , . . .
.
, ,
, .
. . .
.
, , . , ,
.
,
. ,
, .

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

9. SQL Server 2000

199_

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

, . ,
, .
,
, . SQL
Server 2000 , .
SQL Server 2000.
, ,
. ,
.


SQL Server 2000 , .
:
;
.

. , , .
.
:
(authentication);
(login);
(fixed server roles).
:
(database user);
(fixed database role);

200

III,

(users database role);


(application role).
,
.


, - , . .
, , , , . . .
.
, . . Windows NT SQL Server 2000. ,
. ,
. .

.
SQL Server 2000 (Authentication Modes):
Windows NT (Windows NT Authentication);
SQL Server 2000 (SQL Server Authentication).
.
, . .

. SQL Server 2000 . SQL Server 2000
:
Mixed Mode ( ).
SQL Server 2000
Windows NT, SQL
Server. . ,
Windows NT, ,
Windows NT.
;

201

9. SQL Server 2000

Windows Authentication Mode ( Windows).



Windows NT.
. , ,
, Windows NT , SQL Server.
Enterprise Manager.
. , ,
Properties. Security (. 9.1).

. 9 . 1 . Security

Security Authentication,
.
SQL Server and Windows NT/2000 .
SQL Server, Windows NT/2000 only.

SQL Server 2000


SQL Server.

202

III.

Audit level , :
None. SQL Server 2000 .
Success. , . , .
Failure. . .
. , , , .
Windows NT (Windows NT application log),
SQL Server 2000 (error log), . Windows NT ,
.
Programs, Administrative Tools. SQL
Server 2000 Enterprise Manager. \Management\SQL Server Logs\Current,
SQL Server 2000 .
\Archive#.
Windows NT SQL Server .

Windows NT
Windows NT . Windows NT,
. SQL Server 2000 ,
,
. SQL Server 2000 .
. . , .

SQL Server 2000 Multiprotocol Named Pipes.


Windows NT, , , SQL Server 2000.
SQL Server 2000
Windows NT.

9. SQL Server 2000

203_

(logins), , , ,
, . .
(login ID) , -, (SID, Security Identification),
.
. NTFS. NTFS (ACL, Access Control List). (, Access Control Entries),
.
, login ID ACL . ,
.
,

.
. , ( , , . .) ,
. SQL
Server 2000 , , , .

Windows 98 , SQL Server 2000, ,


Windows NT. SQL Server 2000.
Windows NT
Master SQL Server 2000
(login ID). ,
. . . SQL Server 2000.
Windows NT SQL Server 2000
. -
, ,
SQL Server 2000 .
Windows NT .
,
. SQL Server 2000. , -

204

III.

. .
, . , Windows NT
.
,
. , . . .
, Windows NT
SQL Server 2000.

, , ,
. SQL Server 2000 (login) SQL Server 2000 (user) SQL Server 2000. Windows NT . . . Windows NT , .
Windows NT (trusted relationships) . SQL
Server 2000 , "" . , , , SQL Server 2000.
SQL Server 2000,
, ,
SQL
Server.
, . ,
.
, SQL
Server 2000 .
, .
SQL Server 2000 . Windows NT
, . , Windows NT,
, .

9. SQL Server 2000

205_

SQL Server
SQL Server 2000. Master. , SQL Server,
. . , . , .
, .
SQL Server ,
Windows NT. , Novell NetWare, Unix . . SQL Server 2000 Internet
, SQL Server.
, SQL Server
Windows 98, . . (trusted connection
API) , , Windows NT.
SQL Server ,
Windows NT SQL Server 2000. SQL Server 2000 . , .


, SQL Server 2000 , (account login)
. Windows NT
, Windows NT (SAM, Security Account
Manager). .
Windows NT, , , . Windows NT
SQL Server 2000.
, .
SQL Server 2000 ,
: .
.

206

III.

. ,
. , , Windows NT
User Manager for Domains. , SQL
Server 2000 Windows NT.
,
SQL Server 2000, .
SQL Server . SQL
Server, Windows NT.
Enterprise Manager Transact-SQL.
Transact-SQL , SQL
Server 2000 .

Transact-SQL
SQL Server 2000, Windows NT sysxlogins Master.
. sysxlogins ,
, , .

,
10.
, sysxlogins
.
sysiogins,
sysxlogins, srvid
( ) NULL.
Transact-SQL, sysiogins.
sp_helptext:
USE master
EXEC sp_helptext 'sysiogins'

(~

sp_helptext ,
, . . .

9. SQL Server 2000

207

:
Text
CREATE VIEW syslogins AS SELECT
sid = convert(varbinary(85), sid) ,
status = convert(smallint,
8+CASE WHEN (xstatus & 2)=0 THEN 1 ELSE 2 END),
createdate = convert(datetime, xdatel),
updatedate = convert(datetime, xdate2),
accdate = convert(datetime, xdatel),
totcpu = convert(int, 0 ) ,
totio = convert(int, 0 ) ,
spacelimit = convert(int, 0 ) ,
timelimit = convert(int, 0 ) ,
resultlimit = convert(int, 0 ) ,
name = convert(sysname, name),
dbname = convert(sysname, db_name(dbid)),
password = convert(sysname, password),
language = convert(sysname, language),
denylogin = convert(int, CASE WHEN (xstatussl)=1 THEN 1 ELSE 0 END),
hasaccess = convert(int, CASE WHEN (xstatus&2)=2 THEN 1 ELSE 0 END),
isntname = convert(int, CASE WHEN (xstatus&4)=4 THEN 1 ELSE 0 END),
isntgroup = convert(int, CASE WHEN (xstatus&12)=4 THEN 1 ELSE 0 END),
isntuser = convert(int, CASE WHEN (xstatus&12)=12 THEN 1 ELSE 0 END),
sysadmin = convert(int, CASE WHEN (xstatus&16)=16 THEN 1 ELSE 0 END),
securityadmin=convert(int, CASE WHEN (xstatus&32)=32 THEN 1 ELSE 0 END),
serveradmin=convert(int, CASE WHEN{xstatus&64)=64 THEN 1 ELSE 0 END),
setupadmin=convert(int, CASE WHEN(xstatus&128)=128 THEN 1 ELSE 0 END),
processadmin=convert(int, CASE WHEN(xstatus&256)=256 THEN 1 ELSE 0 END),
diskadmin=convert(int, CASE WHEN(xstatus&512)=512 THEN 1 ELSE 0 END),
dbcreator=convert(int, CASE WHEN(xStatus&1024)=1024 THEN 1 ELSE 0 END),
bulkadmin=convert(int, CASE WHEN(xstatus&4096)=4096 THEN 1 ELSE 0 END),
loginname = convert(sysname, name)
FROM sysxlogins WHERE srvid IS NULL

,
s y s l o g i n s ,
(SELECT), (UPDATE, DELETE INSERT).
s y s x l o g i n s .
sysxlogins INSERT, UPDATE DELETE,
.
.
.
.
8

.1207

208

III.

SQL Server Windows NT , SQL Server Windows NT . SQL Server Windows NT.

SQL Server
SQL Server
sp_addiogin, :
sp_addlogin [Sloginame =] 'login'
[, [@passwd =] 'password']
[, [Odefdb =] 'database']
[, [@deflanguage =] 'language']
[, [@sid =] sid]
[, [@encryptopt =] 'encryption option']

sysadmin securityadmin.
.

[@loginame =]

'login'

, SQL Server. sysname,


128 . . name sysiogins ,
.
:
Server: Msg 15025, Level 16, State 1, Procedure sp__addlogin, Line 56
The login '' already e x i s t s .

[gpasswd =]

'password'

, .
sysname, 128
Unicode, NULL. . .
NULL.
s p a d d i o g i n .
pwdencrypt ().
password sysxiogins, varbinary (256), . . .

9. SQL Server 2000

209

, , ,
sp_addlogin.
s p j n e i p t e x t .
EXEC sp_helptext ' s p _ a d d l o g i n ' .
[@defdb =] 'database'
,
. sysname
Master.
. name sysdatabases
Master , Sdefdb.
s p h e l p d b .
,
:
Server: Msg 15010, Level 16, State 1, Procedure sp_addlogin, Line 63
The database '' does not exist. Use sp_helpdb to show available databases.


, , USE .
[@deflanguage =] 'language'
, . ,
.
sysname NULL. ,
NULL, TO , ' d e f a u l t language'
s p c o n f i g u r e Default
language for user Server Settings SQL Server
Properties. . " Server Settings" 8.
, @defianguage, , .
a l i a s syslanguages Master. , SQL Server 2000.
8*

210

III.

sp_helplanguage.
@def language , :
Server: Msg 15033, Level 16, State 1, Procedure sp_validlang, Line 10
'' is not a valid official language name.


SET LANGUAGE '
'. , 1
SET LANGUAGE ' r u s s i a n .
[@sid =] s i d
,
(SID, Security Identification number) . varbinary (16).
S U S E R S I D O .

. ,
,
.

sa 0x01.
sid sysxiogins.
SQL Server
16 , Windows NT 28 . ,

UPDATE, .
@sid
.

, .
:
SELECT sid FROM syslogins

@sid NULL ( @sid), sp_addlogin .

9. SQL Server 2000

211

[Sencryptopt =] 'encryption_option'


, password sysxiogins.
:
NULL . ,

@encryptopt

sp_addiogin. pwdencrypt();

' skip_encryption' ;
' s k i p e n c r y p t i o n o l d ' SQL
Server 2000 ( pwdencrypt ()). ,
.
@ p a s s w d = c o n v e r t ( s y s n a m e ,

convert

( v a r b i n a r y (30) ,

convert (varchar (30), @passwd))). SQL Server 7.0. SQL Server.


SQL
Server s p s d d i o g i n .
:
USE pubs
EXEC sp_addlogin 'Diesel'

, Master ,
. .
:
USE pubs
EXEC sp_addlogin 'Andrey' ,
'analitik',
@sid = OxOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOFF

, ,
sp_addiogin .
wizards, . pubs.

.
USE pubs
EXEC sp_addlogin 'Wizards' ,
'gfhfgcb[jkjubz',
'pubs',
'russian',
OxOlOOOOOOOOOOOOOOOOOOOOOOOOOOOOFF,
'skip_encryption'

212

III.


' gfhfgcb [ j k j u b z ' . - ,
.
, , . , . , , . ,

(dictionary attack), , . .
, , , .
,
sysxlogins,
, sysiogins:
USE master
SELECT name, SID, dbname, password, language
FROM sysiogins
WHERE createdate BETWEEN '23 aug 2001' AND '24 aug 2001'

:
name

SID

dbname

Andrey
0XOOOOOO0O0000O00000O0OO000000O0FF
Diesel
0x20D455C65B42D14A8C93CC7F61FAFBB9
Wizards
OX010000000000000000000000000000FF
(3 row(s) affected)

master
master
pubs

password

language

????????
NULL
gfhfgcb[jkjubz

us english
us~english
russian

Windows NT

SQL Server.
Windows NT sp_grantlogin,
:
sp_grantlogin [Sloginame =] 'login'

Windows NT,
SQL Server 2000 Windows NT.
SQL Server Windows NT.
SQL Server 2000,
. Windows NT
. , SQL Server 2000,
.

9. SQL Server 2000

213

s p _ g r a n t l o g i n sysadmin securityadmin.
s p g r a n t i o g i n ,
Windows NT,
SQL Server 2000. , Windows NT. gioginame Windows NT.
Windows NT
, .
,
.
,
. ()
(\). , SQL Server 2000
SQL_Users matrix :
EXEC sp_grantlogin 'matrix\SQL_Users'

:
EXEC sp_grantlogin [matrix\SQL_Users]

, sp_grantlogin , . Windows NT
.
Master, , .

Enterprise Manager sysxlogins.

Enterprise Manager

Enterprise Manager .
Enterprise Manager , , , \Security\Logins. Enterprise Manager,
,
syslogins (. 9.2).
:
Name. . 128 .

III.

214

. 9.2. Logins
Type. :

NT User ( Windows NT);

NT Group ( Windows NT);

Standard ( SQL Server).

Server Access. SQL Server 2000:

Permit ();

Deny ().

Default Database. .
User. , .
Default Language. , .

.
, . -

215

9. SQL Server 2000

Enterprise Manager
Delete. , , Delete.

New Login. SQL Server
Login Properties - New Login,
. . , General
(. 9.3), .

. 9 . . General

Authentication , . Windows NT
Authentication, Domain
, . (
, .) Name. , Windows NT , SQL Server 2000 , .
Security access:
Grant access. . .
Deny access. .

III.

216

, , SQL Server 2000. , , .


, Windows NT, . , , ,
. Grant access . , Windows NT, SQL
Server 2000, ( SQL Server 2000), .
SQL Server ( SQL Server Authentication), Password , SQL
Server 2000.
Name. .
Windows NT Windows NT, SQL Server 2000.
. Name Windows NT,
Domain. ,
(. 9.4),
^ 1 .

. 9.4.

9. SQL Server 2000

217

SQL Server, Name


SQL Server 2000. . SQL Server
. , .
. , sysxiogins .
.
Defaults ,
. Database
, . SQL Server 2000 ,
, ,
Database. Master.
Language
, , (Russian), , .
General .

. 9 . 5 . Server Roles

218

III.

Server Roles (. 9.5)


(fixed server role).
.
Server Roles , SQL Server 2000.
, . Description .
Properties.
Server Role Properties - sysadmin . , General (. 9.6), ,
. Add.
Remove.

. 9.6. General Server Role Properties - sysadmin

Permissions (. 9.7) ,
, , .
Server Roles .
(Database Access) . (. 9.8) . , SQL
Server 2000. Permit,
. Database. . , , -

9. SQL Server 2000

219

, , .
User. Permit
, .
.
, .

. 9.7. Permissions Server Role Properties - sysadmin


. , ,
. ,
, .

, , , .

. Properties,
Database Role Properties (. 9.9), , :
. , Permissions,
,
.

220

III.

. 9.8. Database
Access

. 9.9. Database
Role Properties
db owner

9. SQL Server 2000

221


SQL Server 2000. ,
SQL Server 2000 :
sa (system administrator). SQL Server. ,
. SQL Server 2000 , . , sa
.
sysadmin, SQL
Server 2000, . , sa. sa, .
.
BUILTIN\Administrators.
Windows NT Administrators , SQL
Server 2000,

BUILTIN\Administrators , . .
. SQL
Server 2000 ,
. BUILTIN\
Administrators sysadmin.


SQL Server 7.0 (roles),
SQL Server 6.x. SQL Server 2000 , .

.
, . . SQL Server 2000 :
(server role);
(database role).

.
.

III.

222

. , , .
(fixed server roles). . 91
.
9.1.

sysadroin
(System Administrators)

SQL
Server 2000. ,

setupadmin
(Setup Administrators)


, , SQL Server 2000, setupadmin

serveradmin
(Server Administrators)

,
.
(SHUTDOWN), (sp_conf igure),
(RECONFIGURE),
(sp_fulltext_service)

securityadmin
(Security Administrators)


,
,
,
securityadmin SQL Server

processadmin
(Process Administrators)

, SQL
Server2000, .. K I L L .
processadmin

diskadmin


SQL Server 7.0.
(device).
diskadmin ,
, , SQL Server 2000 ,

(Disk Administrators)

dbcreator
(Database Creators)

, ,

bulkadmin

SQL Server 7.0.


bulkadmin
,

(Bulk Insert administrators)

SQL Server 6.x . , ,


.

9. SQL Server 2000

223

, .
SQL Server 2000 .
, .
.
.

Server Roles (. . 9.5) sp_addsrvrolemember,
:
sp_addsrvrolemember [@loginame =] 'login' , [Srolename =] ' r o l e '

sysadmin
. ,
, .
@ioginame , . ,
, @roiename. , .
Windows NT
Admin STORAGE sysadmin:
EXEC sp_addsrvrolemember 'STORAGE\Admin', 'sysadmin'

, ,
, Windows NT . ,
Windows NT SQL Server 2000 Windows NT,
.
.
,
, :
sp_helpsrvrolemember [ [@srvrplename =] 'role']

, , . , , Osrvroiename.
sysadmin:
EXEC sp_helpsrvrolemember sysadmin'

224

III.

. 9.1.
:
EXEC sp_helpsrvrole

:
ServerRole

Description

sysadmin
securityadmin
serveradmin
setupadmin
processadmin
diskadmin
dbcreator
bulkadmin
(8 row(s) affected)

System Administrators
Security Administrators
Server Administrators
Setup Administrators
Process Administrators
Disk Administrators
Database Creators
Bulk Insert administrators


spt_vaiues, .

sp_dropsrvroiemember, :
sp_dropsrvrolemember [@loginame =] 'login' , [@rolename =] 'role'

sp_addsrvroiemember, .



. SQL
Server 2000. , . ,
sysadmin. , , ,
, .

(user)
,
. , ,
,

9. SQL Server 2000

225

. ,
.
SQL Server 2000 ,
. , SQL Server 2000. .
,
. , , .



. (. . " Enterprise Manager" ).
, Database Access.

Enterprise Manager. Enterprise Manager ,
, Users. (. 9.10)
, , :
Name. . 128 .
.
Login Name. ,
.
Database Access. , (Permit), , , (Deny).
Enterprise Manager User ( ) New
Database User. Database User Properties - New
User (. 9.11), .
Login name , .
, , ,
. User name
, . , ,
. . , . .
Enterprise Manager .

226

III.

. 9.10. Users

,
.
. Properties,
, , .
.
Database User Properties - New User Permissions, . ,
, ,
.
.
,
Properties
. ,
. , ,
.

227

9. SQL Server 2000

. 9 . 1 1 .
Database User Properties - New
User


:
dbo (database owner). , .
. dbo . dbo sa, . ,
dbowner .
dbo db_owner ;
guest. ,
guest.

, . guest, , ,
, SQL Server 2000. guest
.

Transact-SQL
Enterprise
Manager. -

III.

228

. , , Transact-SQL. ,
, Enterprise Manager
.
Transact-SQL,
, .

, ,
sysusers, , . . 9.2
sysusers .

sysusers . .
9.2. sysusen

uid

smallint

(),
.
dbo 1.
guest 2. 16 384, 16 400

status

smallint

,
(). .

sysname

, () .
,

varbinary(85)

, .
SQL Server s i d
s y s l o g i n s Master.
Windows NT
syslogins
{ ,
Windows NT)

sid

9. SQL Server 2000

229

9.2 ()

roles

varbinary(2048) , . , 1. ,
SQL Server 2000 16 384

createdate

datetime

()

updatedate

datetime


()

altuid

smallint

.
.

password

varbinary(256)

. , NULL

gid

smallint

,
.
s i d ,

environ

varchar(255)


NULL

hasdbaccess

int

1,

islogin

int

1,
(SQL Server,
Windows NT)

isntname

int

1,
Windows NT

isntgroup

int

1, Windows NT

isntuser

int

1, Windows NT

issqluser

int

1, SQL Server

isaliased

int

1, .
SQL Server 6.x

///.

230

9.2 ()

issqlrole

int

1,

isapprole

int

1,

, sysusers . , . , (attach)
,
. ,
,
. ,
, .

Windows NT, . . . ,
( ), (
, ) .
, -
sid . SQL Server 2000
S U S E R _ S I D O ,
SQL Server,
Windows NT. , SUSER_SIDO, s i d sysusers.
, sp_attach_db, L i i i y a
Windows NT L i i i y a matrix,
:
USE pubs
UPDATE sysusers SET sid = SUSER_SID('matrix\Liliya')
WHERE name = 'Liiiya1

,
.
EXEC sp__configure ' a l l o w
update', 1.

9. SQL Server 2000

231


SELECT .
sysusers .
, , , , sysusers
, Master.

spheipuser:
USE pubs
EXEC sp_helpuser

:
UserName

GroupName

LoginName

DefDBName

UserlD SID

Admin
Casper
dbo
guest

public
public
db owner
db datareader

NULL
Casper
sa
NULL

NULL
pubs
master
NULL

6
5
1
2

0x0542A973F5
0x04456EC274
0x01
0x00


Windows NT, . . .

, Admin ,
. ,
Windows NT, Windows NT.


:
sp_adduser.
SQL Server .
sp_grantdbaccess. SQL Server 2000
, SQL Server 7.0.
spadduser, sp_grantdbaccess, :
sp_grantdbaccess [Ologiname =] ' l o g i n 1
[,[@name_in_db =] 'name_in_db' [OUTPUT]]

232

III.


sysadmin dbowner
db_accessadmin.
gioginame ,
.
. @name_in_db ,
.
.

s p g r a n t d b a c c e s s . pubs
Admin, STORAGE\Admin:
USE pubs
EXEC sp_grantdbaccess 'STORAGE\Admin', 'Admin'

, @loginame
, ,
Windows NT, SQL
Server 2000 Windows NT.

sp_revokedbaccess, :
sp_revokedbaccess [@name_in_db =] 'name'
((~


sysadmin db_owner
db_accessadmin.
, . , , , .
, DROP,
sp_changeobjectowner.
, Admin :
EXEC sp_revokedbaccess 'Admin'

9. SQL Server 2000

233_

sprevokedbaccess
s p d r o p u s e r , sp_revokedbaccess :
sp_dropuser [@name_in_db =] ' u s e r '

, s p a d d u s e r , SQL Server 2000 .


. " " ""
. SQL Server 2000, ,
: . . " "'
, . , .
SQL Server 2000 :
(fixed database role);
(user database role);
(application role).
( ),
. . . , .
.



, .
.
,
.
SQL Server 2000 , SQL Server Windows NT,
Windows NT .

, Enterprise Manager . , SQL Server 2000


,
.

III.

234

. 9.3 .
9.3.

db_securityadmin

db_owner

, . .

db_denydatawriter

db_denydatareader

db_ddladmin

db_datawriter

, ,

db_datareader

, ,

db_backupoperator

db accessadmin


: ,

, , . . 9.3 ,
public. . , , public, .
public. , . .
public.
public
(default right). public, , , , . public guest. ,
. , guest, . ,
, guest , . public
, guest.

9. SQL Server 2000

235


Transact-SQL

,
.

, ,
. -

UPDATE, INSERT DELETE -

sysusers,
.
(,
Enterprise Manager)
. , s p d r o p r o l e , , . ,
db_ddiadmin:
USE pubs
EXEC sp_droprole 'db_ddladmin'

:
Server: Msg 15142, Level 16, State 1, Procedure sp_droprole, Line 46
Cannot drop the role 'db_ddladmin'.

DELETE:
USE pubs
DELETE FROM s y s u s e r s WHERE name = 'db_ddladmin'

. . , , NewFixedRoie:
USE pubs
INSERT INTO sysusers (uid, s t a t u s , [name], s i d ,
createdate, updatedate, a l t u i d , [password], r o l e s )
SELECT 16395, 0, 'NewFixedRoie1 , NULL,
GETDATEO, GETDATEf), 1, NULL, 0x00

, ,
, sysusers,
uid 16 384 16 399 , . , 16 395 .

M o d e l , .

236

III.
, syspermissions.

,
- ,
. ,

. , ,
, . , .

.

.

sp_helprole:
USE pubs
EXEC sp_helprole
:
RoleName

Roleld IsAppRole

public
db__owner
db_accessadmin
db_securityadmin
db_ddladmin
'
db_backupoperator
db_datareader
db_datawriter
db_denydatareader
db_denydatawriter
NewFixedRole
(11 row(s) affected)

0
16384
16385
16386
16387
16389
16390
16391
16392
16393
16395

0
0
0
0
0

, ,
, , .

,
sp_addrolemember, :
sp_addrolemember [grolename =] ' r o l e 1 , [gmembername =] 'security_account'
Sroiename ,
.

9. SQL Server 2000

237

. .
spaddroiemember
.
( , )
,
. , ,
@membername.

AccessedUser dbaccessadmin:
EXEC sp addrolemember 'db_accessadmin',

'AccessedUser'


, ,

. :
sp_helprolemember [[Srolename =]

'role']

, .
, grolename, .

:
USE pubs
EXEC sp_helprolemember

:
DbRole

MemberName

MemberSID

AccessedUser
db accessadmin
db datareader
db owner
db owner
db owner
NewFixedRole
NewFixedRole
(8 row(s) affected)

Access
AccessedUser
guest
Access
AccessedUser

NULL
NULL
0x00
NULL
NULL
0x01
0x43940DBCA5C63C4D9F407BFCCCB34CD9
NULL

dbo
Casper
Mayor


,
sp_droprolemember,
:
1

sp_droprolemember [Qrolename =] ' r o l e ,


[Smembername =] ' s e c u r i t y account 1

III.

238

,
. .
, dbaccessadmin AccessedUser :
USE pubs
EXEC sp_droprolemember 'db accessadmin',

'AccessedUser'


,

.
,
, ,
.
, ,

. SQL Server 2000
SQL Server 6.x Windows NT.

. 9.12. Rotes

239

9. SQL Server 2000

Roles (. 9.12)
Enterprise Manager. :
Name ;
Role Type . Standard ( )
Application ( ).
Enterprise Manager Roles New Database Role. Database Role Properties - New Role (. 9.13)
Name , .
Database role type
. Standard role,
Add
. Application role, , . .

. 9.13.


Transact-SQL

Transact-SQL, , . . , 9

.1207

240

III.

sysusers, .
, sysusers , ,
. ,
,
i s s q i r o i e . 1, . . .
gid. ,
sid, . , (
sid) 16 400.

, p u b l i c 0.

,
:
USE pubs
SELECT * FROM sysusers WHERE issqiroie = 1 AND sid = gid
SELECT * FKOM sysusers WHERE gid .'= 0
SELECT * FROM sysusers WHERE sid >= 16400


s p h e l p r o l e , . Role id 16 400.



s p a d d r o l e , :
sp_addrole [Srolename =] 'role' [, [@ownername =] 'owner']

sysadmin db owner
db_securityadmin.

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

9. SQL Server 2000

241

, , :
Server: Msg 15023, Level 16, State 1, Procedure sp__addrole, Line 58
User or role '' already exists in the current database.

(
dbo). , dbo . ,

Sownername. . .
Accesseduser,
guest:
USE pubs
1
EXEC sp_addrole 'Accesseduser , 'guest'

, SQL Server 7.0 . . SQL Server 6.x


SQL Server 2000 , . , . ,
spaddgroup.
:
sp_addgroup [@grpname =] ' g r o u p '

,
. , . :
USE master
EXEC s p _ h e l p t e x t 'sp_addgroup'

:
Text
create procedure sp_addgroup
Sgrpname
sysname
name of new role
as
declare Sret int
execute @ret = sp_addrole @grpname
return @ret

, spaddgroup -
sp_addroie, , . ,
, SQL Server 2000 .

,

9*

242

III.

, ,
. , spaddrolemember,
sp_droprolemember.

sp_droproie, :
sp_droprole [Orolename =] ' r o l e '
, .
, spdroproiemember.
, .
,

sp_changeobjectowner, .

AccessesUser:
USE pubs
EXEC sp_droprole 'AccessesUser'


,
.
. SQL Server 2000 (application role).
, ,
,
- .
SQL Server 2000 , . ,
,
. , , .
, SQL Server 2000, .

^)

. ,
.

9. SQL Server 2000

243_

Enterprise Manager . . , , . .
, . ,
. .
.
. SQL Server Windows NT SQL
Server 2000.
, ( ).
, .
, .
, SQL Server 2000
. , ,
, . , SQL Server 2000 , , .
.
, , .
.
,
, .
.
, , ,
,
. guest, .

, guest.
, guest
public.
,
. , ,
guest,
. .

244

III.


Transact-SQL

Transact-SQL, sysusers, .
. , ,
isapprole. 1,
. ,
password , . (
) password NULL.
,
:
OSE pubs
SELECT * FROM s y s u s e r s WHERE i s a p p r o l e = 1

s p h e i p r o i e ,
. isapprole
!, 0.

s p a d d a p p r o i e , :
sp_addapprole [Srolename =] 'role', [Spassword =] 'password'

sysadmin db_owner
db_securityadmin.

, .
. , .
. gpassword , .
password sysusers.
Mayor
marshal:
USE pubs
EXEC sp_addapprole 'Mayor', 'marshal'

9. SQL Server 2000

245



:
sp_setapprole [Srolename =] ' r o l e ' ,
[gpassword =] {Encrypt N 'password'} | 'password'
[,[@encrypt =] ' e n c r y p t _ s t y l e ' ]

.
.
, .
, USE .
.
[grolename =] ' r o l e '
, .
. ,
:
Server: Msg 2763, Level 16, State 1, Procedure sp_setapprole, Line 41
Could not find application role ''.

.
[Spassword =] (Encrypt N 'password'} I 'password'
, . ,
. , :
Server: Msg 2764, Level 16, State 1, Procedure sp_setapprole, Line 41
Incorrect password supplied for application role ''.
ODBC Encrypt, [gpassword =]
Encrypt N 'password'. Encrypt
Unicode, N,
Unicode.
[Sencrypt =] 'encrypt__style'
. :

' ' ;

246

III.
odbc'
ODBC Encrypt.


SETUSER . SETUSER
sysadmin dbowner
.

Mayor:
USE pubs
EXEC sp_setapprole 'Mayor', 'marshal'
.
, :
USE pubs
EXEC sp_setapprole 'Mayor', Encrypt N ' m a r s h a l '
EXEC sp_setapprole 'Mayor', ' m a r s h a l ' , 'odbc'


USE.
, , .

s p d r o p a p p r o l e , :

sp_dropapprole [@rolename =] ' r o l e '

sysadmin dbowner
db_securityadmin.
, .
, . :
Server: Msg 15014, Level 16, State 1, Procedure sp_dropapprole, Line 29
The role '' does not exist in the current database.

9. SQL Server 2000

247

Mayor,
:
USE pubs
EXEC sp dropapprole 'Mayor'

, - . .
,
sp_changeobjectowner.


, .

.
:
;
;
Transact-SQL.
, , . . ,
, Dbcreator.

.
, . , ,
. .
,
.
.


:
INSERT.
. , INSERT
.

248

III.

UPDATE. , , , .
DELETE. .
INSERT, DELETE
.
SELECT. . , .
REFERENCES. .
,
'.
REFERENCES , . ,
.

REFERENCES SQL Server.



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

d b d a t a r e a d e r ,
.


,
(EXECUTE).

.
REFERENCES, , .
, .
. , Enterprise Manager.

9. SQL Server 2000

249

Enterprise Manager
Stored Procedures. Enterprise Manager
, . Object Properties (. 9.14),
Permissions
,
All Tasks, Manage Permissions.

. 9.14. Object Properties matrix

, EXEC. ,
.
. .
. Enterprise Manager
Enterprise Manager User Defined
Functions. Enterprise Manager , .
Object Properties (
. 9.14), Permissions
,
All Tasks, Manage Permissions.

250

III.


,
Permissions .

Transact-SQL
, .
Transact-SQL

.
Transact-SQL:
CREATE DATABASE. . .
CREATE TABLE. .
CREATE VIEW. .
CREATE PROCEDURE. .
CREATE FUNCTION. .
CREATE RULE. .
CREATE DEFAULT. .
BACKUP DATABASE. .
BACKUP LOG. .
ALL. .
sysadmin dbowner ALL.
, .


,
SQL Server 2000.
.
,
.
p u b l i c ,
, .
, (allow access)
.
,
.

9. SQL Server 2000

251_


. ,
Transact-SQL.
Windows NT , .
, Windows NT SQL Server. . Reader
, (login) SQL Server
Liiiya. ,
L i i i y a , Windows NT,
NTGroup3.
Editor, ,
Reader.
, .

, d b _ d a t a w n t e r .

d b _ d a t a r e a d e r .

, ,
.
Transact-SQL. .

SQL Server 7.0


Transact-SQL. SQL Server 2000
Enterprise Manager.

Enterprise Manager :
. Enterprise Manager , ,
,
Properties.
Permissions, Object Properties
(. 9.15). , ( dbo), , ,
public.

III.

252

. , .
,
, - . Object , .
Object.

, . . ,
SELECT . , EXECUTE .

. 9.15. Object Properties matrix


Co . Enterprise Manager , .
Users, .
Database User
Properties (. 9.16), Permissions
. ,
, .
.

9. SQL Server 2000

253

Database user ,
.
Database user.
dbo. , , .
dbo .
. . ,
Permissions , . ( ) Roles, .

public.
. , Enterprise
Manager, SQL Server 2000,
,
. Database User
Properties Columns. Column Permissions (. 9.17), .

. 9.16. Database User Properties pubs

III.

254

. 9.17. Column
Permissions


GRANT, :
GRANT
{

ALL

[PRIVILEGES]

permission

[,...n]

[( column [,...n] )] ON {table I view)


I ON {table I view} [( column [,...n] )]
I ON {stored_procedure I extended_procedure}
I ON {user_defined_function}
}
TO security_account [,...n]
[WITH GRANT OPTION]
[AS (group I role}]

:
ALL


.
, sysadmin
db owner.

9. SQL Server 2000

255

PRIVILEGES
PRIVILEGES
.
ANSI SQL-92.
permission [,...n]
,
. :
SELECT , ;

INSERT ;

DELETE ;

UPDATE ,
;

REFERENCES , ;

EXECUTE .

Enterprise Manager
REFERENCES DRI (declarative referential integrity,
).
[,...]

, GRANT .
(column [, . . . ] )

. GRANT
.
.
SELECT UPDATE.
ON (table I view}

,
. (column [, .. . ] ) ,
. .
SELECT,
UPDATE, DELETE, INSERT REFERENCES.

256
ON { t a b l e | view}

III.
[( column [ , . . . n ] )]

,
. {table | view}
,
(column [, .. .]) , .
ON {stored_procedure I extended_procedure}


.
. , , .
,
Master. .
EXECUTE.
d ON {user_defined_function}

.

EXECUTE REFERENCES.
security_account

[,...n]

, . GRANT,
.
WITH GRANT OPTION

, ,
, .
WITH GRANT OPTION -

. .
AS {group I role}

, - .
, ,
, . AS ,
.
Transact-SQL
GRANT :
GRANT {ALL I statement[,...n]} TO security_account [, .. .n]

9. SQL Server 2000

257

ALL Transact-SQL. sysadmin


dbowner.
Transact-SQL s t a t e m e n t ! , .. .]. . " Transact-SQL" . secur i t y a c c o u n t [, .. .] .

, ,
GRANT.

Accesseduser au_id, au_lname, aulname s t a t e authors


pubs:
GRANT SELECT (au__id, au_lname, au_lname, state)
ON authors
TO AccessedUser
, .

.


SQL Server 2000

. , Windows NT,
SQL Server,
.
Windows NT. SQL Server 2000

.
, , , .
, .
,
(deny access) , ,
. , , .
. ,
, , , .
.

258

III.

,
(DEMY) , (GRANT).
,
SQL Server 2000 ,
,
Windows NT.
db_owner. .

db_denydatawriter db_denydatareader, .
DENY, :
DENY
{ ALL [PRIVILEGES] I p e r m i s s i o n [ , . . . n ] }
{
[( column [ , . . . n ] )] ON { t a b l e I view}
I ON { t a b l e | view } [( column [ , . . . n ] )]
I ON { s t o r e d _ p r o c e d u r e I e x t e n d e d _ p r o c e d u r e }
I ON { u s e r _ d e f i n e d _ f u n c t i o n }
}
TO s e c u r i t y _ a c c o u n t [ , . . . n ]
[CASCADE]

DENY GRANT. ,
.
CASCADE. DENY CASCADE, TO . , , ,
CASCADE . -,
.
Transact-SQL DENY:
DENY{ALL | s t a t e m e n t [ ,

n]} s e c u r i t y _ a c c o u n t [ , . . .n]


: (GRANT)
(DENY). (revoke access). ,

9. SQL Server 2000

259_

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

. ,
" " . SQL Server 2000 ,
,
.

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

, REVOKE :
REVOKE [GRANT OPTION FOR]
{ ALL

[PRIVILEGES]

permission

[,...n]

[( column [,...n] )] ON {table I view}


I ON (table I view} [( column [,...n] )]
I {storedjorocedure I extended_procedure}
}
{ TO I FROM }
security_account [,
n]
[CASCADE]
[AS { group I role }]

260

III.

DENY, REVOKE
GRANT, . , . REVOKE, GRAND DENY
, GRANT OPTION FOR.
.
GRANT OPTION FOR , WITH GRANT OPTION.

FROM .
FROM '
, . .
Transact-SQL
REVOKE :
REVOKE {ALL I statement[,...n]} FROM security_account [, . . .n]


Enterprise Manager . ()
Permissions. ,
Transact-SQL.
sp_heiprotect, :
sp_helprotect [[@name =] 'object_statement']
[, [@username =] 'security_account' ]
[, [Sgrantorname =] 'grantor']
[, [Spermissionarea =] 'type']

(~

Public. ,

.
.
[@name =]

'object_statement'

,
.
Transact-SQL:

9. SQL Server 2000

26?

CREATE DATABASE;

CREATE DEFAULT;

CREATE FUNCTION;

CREATE PROCEDURE;

CREATE RULE;

CREATE TABLE;

CREATE VIEW;

BACKUP DATABASE;

BACKUP LOG.

gname NULL, TO .

[gusername =]

'security_account'

,
.
NULL, TO .
[@grantorname =] ' g r a n t o r '

, , .
.
[@permissionarea =]

'type'

, . :

s' ;

' ' ;

' s1 ,
.
.

s p h e l p r o t e c t
authors:
USE pubs
EXEC spjielprotect 'authors'

:
Owner

Object

Grantee

Grantor ProtectType Action

dbo
dbo
dbo

authors
authors
authors

guest
guest
guest

dbo
dbo
dbo

Grant
Grant
Grant

Column

Delete
Insert
References (All+New)

262
dbo
authors
dbo
authors
(5 row(s) affected)

III.
guest
guest

dbo
dbo

Grant
Grant

Select
Update

(All+New)
(All+New)

, . :
owner. .
objects. , .
Grantee. ,
.
Grantor. ,
.
ProtectType. ,
.
Action. , .
column. ,
. , (Aii+New).
,
guest:
USE pubs
sp_helprotect NULL, 'guest', NULL, 's'

:
Owner Object Grantee

Grantor ProtectType Action

guest
guest
guest
guest
guest
(5 row(s) affected)

dbo
dbo
dbo
dbo
dbo

Grant
Grant
Grant
Grant
Grant

Create
Create
Create
Create
Create

Column
Default
Procedure .
Rule
Table
View


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

9. SQL Server 2000

263

. ,
,
, .
.
, Liliya Tabiei.
viewi,
Tabiei. Liliya John
viewi. John
Tabiei viewi,
Tabiei.

viewi 2,
Liss,
viewi, Liss John Table2.
, ,
. -
,
, ,
. - , ,
, , .
. 9.18 ,
.
Joe.procedurel

J
Joe.procedure2 |

| Sue.procedure3

Joe.viewi
Sue.view2
i

Suetabel

Joe.table2

Sue,table3

. 9.18.

Joe Sue
Procedure 1, . SQL
Server 2000 sue
Procedurel, Procedure3, View2, Table2 .
Procedure2 Tabiei , . . Procedure2 Tabiei
.

10


, , ,
. . , SQL Server 2000, .
:
SQL Server 2000
, . ,
, ,
SQL Server 2000,
, , . .
, , , , , , ,
. .
. , ,
. ,
,
.

, , SQL Server 2000 .



. ,
. , . . . ,

10.

265

,
. . *
, , .
, ,
SQL Server 2000 , . .
, , .


, SQL Server 2000
.

, . . .
, Windows NT.
:
SQL Server. , (Service Pack)
(Patches). , SQL Server
. .
, ,
. , , , , . ,
, . ,
SQL Server 7.0 ,
23 Microsoft,
. , , . ,
.
SQL Server 2000. SQL Server 2000
sysadmin serveradmin . . SQL Server 2000
. ,
, , ,
.

266

III.

. ( SQL
Server 2000),
, .

.
, SQL
Server 2000. MSSQLServer , .
SQL Server 2000.
.
, , , , , . SQL Server 2000 Enterprise Manager 8.
.
Windows NT SQL Server, SQL Server 2000. . " " 4.
. , , .
.
, . .
13.
.
.
. , SQL Server 2000 . ,
.
. SQL Server 2000 .
.
SQL Server 2000 17.
.
.
,
. ,

10.

267

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

268

III.


. .
, ,
. .

SQL Server 2000 ,


. .
,
, .
9.


SQL Server 2000 . . , SQL Server 2000
,
.
SQL Server 2000
SQL Server 2000, .

. .
.
. ,
, . , SQL Server 2000 (13), . . (7).
, .
,
, . SQL
Server 2000 8.
SQL Server 2000,
Enterprise Manager .
,
. ; Enterprise Manager

10.

269

SQL Server 2000, .


Enterprise Manager,
. , , , (linked) (remote) .
Enterprise Manager, .


, Enterprise Manager
SQL Server 2000,
, .
,
. , , .
:
, . . ;
,
Server 2000;

SQL

, Enterprise
Manager ;
SQL Server
SQL Server, .
.
Registed SQL Server Properties. Enterprise Manager
.
Register SQL Server Wizard.
, .

Enterprise Manager, SQL Server 2000,


SQL Server 7.0. SQL Server 7.0 SQL Server 2000.

Registered SQL
Server Properties.
Enterprise Manager
New SQL Server Registration. Registered SQL Server Properties (. 10.1), -

270

III.

. , New SQL Server Registration.

. 1 0 . 1 . Registered SQL
Server Properties

Server SQL Server 2000


SQL Server 7.0, . , NetBIOS , SQL
Server 2000. ,

_\_.
SQL Server 2000, , Active
Directory. SQL Active Directory Search (. 10.2),
^ J , Server.
In .
Name SQL Server 2000, . .
1 . Name , , . 1

, , ,
(?) (*). .

10.

271

. Version 7.0 8.0


(SQL Server 2000). Version ,
.
, Find Now. .
, Server.

. 10.2. SQL Active Directory Search

SQL Server, Windows 95/98, .


. , Windows 95/98, ( ). , SQL Server,
. .
Connections (. . 10.1) ,
Enterprise Manager SQL
Server 2000. , :
Use Windows NT authentication.
Windows NT.
10 . 1207

272

III.

.
Use SQL Server authentication. SQL Server
.
:

Login Name ,
. , ;
Password ;

Always prompt for login name and password. , , . Enterprise Manager


. , Enterprise Manager
, .
Password , Login Name
, .
(

, SQL Server
Always prompt for login name and password. .
. SQL Server 7.0 (XOR). . , (patch),
.
, ,
Enterprise Manager .
Options.
Server Group. ,
.
. .
,
Server Groups (. 10.3),
^ J , Server Group.
. .

273

10.

. - . . Microsoft 5060
SQL Server,
.

Display SQL Server state in console. Enterprise Manager.


Enterprise Manager
.
Show system databases and system objects.
, , , ,
. , , (,
, ). , Enterprise Manager, .
, .
Enterprise Manager .
Automatically start SQL Server when connecting. SQL Server 2000
.

. 10.3. Server Groups

Enterprise
Manager, .

10*

274

III.

Enterprise Manager, . .
.
. , Enterprise Manager . , ,
Enterprise Manager ,
, .
- . . ,
, , Server . , , , , , .
(

^)

Windows NT,
SQL Server,
"Login failed" ( ). , SQL Server
.
Registered SQL Server Properties.
Register SQL Server Wizard. Enterprise Manager Run a Wizard,
Register Server Wizard
. .
(. 10.4) . From now on, I want to
perform this task without using a wizard.
, , , Registed SQL Server Properties, Next
,
Registered SQL Server Properties, . ,
From now on, I want to perform this task without using a wizard
.
(. 10.5)
. , .
(Available servers),
. ,
. Added
servers, Add . . -

275

10.

. - ,
Remove.

. 10.4. Register SQL Server Wizard

ill

. 10.5. Register SQL Server Wizard

III.

276

SQL Server,
Windows 95/98, , . .
, .
(. 10.6) , Enterprise Manager
. Connect using. SQL Server , .

. 1 0 . 6 . Register SQL Server Wizard

(. 10.7) (Login name)


(Password) SQL Server, .
. . , Prompt for the SQL Server account information when connecting. Login name Password ,
Enterprise Manager
, .

10.

277

. 10.7. Register SQL Server Wizard

Windows NT
.

(. 10.8) .
, Add the SQL
Server(s) to an existing SQL Server group
Group name .
, Create
a new top-level SQL Server group Group name .

, .

Register SQL Server Wizard .

. (. 10.9)
, .
Finish ,
.

III.

278

, . , , Enterprise Manager.

. 10.8. Register SQL Server Wizard

. 10.9. Register SQL Server Wizard

279

10.


SQL Server 2000,
Enterprise Manager . Enterprise Manager
.
, . ,
, .
, .

Enterprise Manager SQL


Server 2000. , ,
Enterprise Manager. ,
, .
,
. Server
Groups (. 10.10), .

. 10.10. Server Groups


Name.
, . Level Top level group,
, . . Console Root.
, Sub-group of.
,

280

III.

, .
, , .
Delete. , Enterprise Manager , , , .
.
(

Enterprise Manager . ,
,
.
Rename Server Group
(. 10.11), , Rename SQL Server Group
.
Rename the server group to .

. 10.11. Rename Server Group

MATRIX


(data source) SQL
Server 2000, .
,
. .
,
. SQL Server 2000,
. SQL Server 2000
OLE DB, ,
. , , OLE DB
(OLE DB Provider). SQL
Server 2000 ,
SQL Server 2000 .
OLE DB.

10.

281

OLE DB ,

OLE DB.
.
ODBC, OLE DB
.
SQL Server 2000 ,
, Oracle, DB2, ADSL ODBC, Exchange . ,
, ,
, , .
, , . . , SQL Server 2000
(linked servers).
sysservers
Master. OLE DB, , ,
, (, ), , .
(

sysservers , SQL Server 2000: , , , , ,


SQL Server 2000.
, SQL Server 2000 sysservers
. . OLE DB,
, .
, , (remote query) (distributed query), . , ,
, .
, :
SELECT t i t l e FROM storage.pubs..titleauthor as ta,
[storage\trelon].pubs.dbo.authors as a, p u b s . . t i t l e s as t
WHERE ta.au_id = a.au_id AND t . t i t l e _ i d = t a . t i t l e _ i d
AND a.state = 'CA'

282

III.

. . , .
, . , . ,
.
SQL
Server 2000 .
, , SQL Server 2000. , SQL Server 2000

sysservers. SQL Server 2000,
, . , ,
.
sysadmin
setupadmin. ,
.

SQL Server 2000 (remote servers).


SQL Server 2000 SQL Server 7.0.
, .
. ,
. ,
OPENDATASOURCE OPENROWSET.

, .
.
- .
. SQL
Server 2000 .
SQL Server 2000
.

,
, .

10.

283

,
:
Transact-SQL ;
Enterprise Manager.

.

Transact-SQL
,
. , sysservers. , (
) INSERT.
.

. , , , . ,
.
,
.



sp_addlinkedserver, :
sp_addlinkedserver [gserver =] 'server'
[, [Ssrvproduct =) 'product_name']
[, [@provider =] 'provider_name']
[, [Sdatasrc =] 'data_source']
[, [Olocation =] 'location']
t, [@provstr =] 'provider_string']
[, [Scatalog =] 'catalog']

. ,
. .


. ,

284

III.

sp serveroption

'ServerName' ,

'data a c c e s s ' ,

EXEC

'TRUE'.

:
[@server =]

'server'

,
. , , . @server .
. sysname,
.

Sserver ,
. (, ),
, . ,
, , , .
[Ssrvproduct =]

'product_name'

, . ,
.
Microsoft SQL Server,
'SQL s e r v e r 1 .
(@provider), (gdatasrc), (siocation),
(gprovstr), (gcataiog).
@server SQL
Server 2000 , .
nvarchar (128), NULL.
d

[@provider =]

'provider_name'


OLE DB, . .
, .
. 10.1 ,
SQL Server 2000. Sprovider nvarchar (128), NULL.

285

10.

.
HKEY_CURRENT
USER\Software\ Microsoft\Microsoft SQL Server\80\DTS\ Enumeration\OLEDBProviders.

10.1. , SQL Server 2000


Sprovider

Microsoft OLE DB Provider


for SQL Server

SQLOLEDB

SQL Server

Microsoft OLE DB Provider


for DTS Packages

DTSPackageDSO

,
DTS

SQL Server Replication OLE


DB Provider for DTS

SQLReplication.OLEDB

MSDataShape

MSDataShape

OLE DB Provider for Microsoft ADsDSOObject


Directory Services



,
Active Directory Windows 2000

Microsoft OLE DB Provider


for OLAP Services 8.0

MSOLAP


OLAP, SQL Server 2000

Microsoft OLE DB Provider


for Internet Publishing

MSDAIPP.DSO

Microsoft OLE DB Provider


for Microsoft Search

Microsoft Search
Collator data source

Microsoft Search

Microsoft OLE DB Provider


for ODBC Drivers

MSDASQL


ODBC

Microsoft Jet 4.0 OLE DB


Provider

Microsoft.Jet.OLEDB.4.0


,

(mdb, dbf )

Microsoft OLE DB Simple


Provider

MSDAOSP


SQL Server

Microsoft OLE DB Provider


for Oracle

MSDAORA


Oracle

Microsoft OLE DB Provider


for Indexing Service

MSIDXS

OLE DB, , 3.

286

///.

[gdatasrc =] 'data_source'
. SQL Server 2000 NetBIOS , SQL Server 2000. ,

_\_.

' M i c r o s o f t . J e t . O L E D B . 4 . 0 ' .
nvarchar (4000), NULL.
[glocation =] 'location'
. e i o c a t i o n
, . .
. nvarchar (4 000), NULL.
[Sprovstr =] 'provider_string'
, , .
,
. ,
, .
,
, , . , .
. ,
Sprovstr . ,
Enterprise Manager sp_addiinkedserver.
, , dprovstr .
nvarchar (4000), NULL.
[@catalog =] 'catalog'
, .
. ,
SQL Server 2000 Scataiog . sysname, NULL.
, . , s p a d d i i n k e d s e r v e r . SQL Server 2000:
sp_addlinkedserver 'STORAGE\TRELON',

'SQLServer 1

10.

287

. ,
. .

, SQL Server 2000.


, gserver , SQL Server 2000
. gsrvproduct 'SQL server 1 ,
.

,
SQL Server 2000. , 1
Ssrvproduct, 'SQL s e r v e r . gserver. gsrvproduct
SQL Server 2000 ,
1
o r a c l e ' , , , SQL Server 2000. sysservers.

,
, . Oracle:
sp_addlinkedserver gserver = 'Baxus1,
Ssrvproduct = 'Oracle1,
Sprovider = 'MSDAORA',
@datasrc = 'ServerName'

Baxus, Oracle ServerName.


, Oracle,
Baxus .
,
MS Access Jet:
sp_addlinkedserver 'Access_Pubs',
'OLE DB P r o v i d e r for J e t ' ,
'Microsoft.Jet.OLEDB.4.0',
'C:\MSOffice\Access\Samples\Pubs.mdb'

(gdatasrc) , .
SQL
Server 2000,

268

III.

ODBC.
( Sprovstr):
sp_addlinkedserver Sserver = 'JavaLand',
^provider = 'MSDASQL',
Oprovstr = 'DRIVER={SQL Server};SERVER=JL;UID=sa;PWD=;'

JavaLand, ODBC. Sprovstr


ODBC. , ODBC, (SQL server), ,
( J L ) . , SQL Server, .
, sa,
.
. , . .


,
.
. . :
sysservers;
sp linkedservers.

:
SELECT * FROM s y s s e r v e r s

sysservers.
30 , . sp_iinkedservers, . - SELECT,
7 sysservers.
s p h e i p t e x t ,
Transact-SQL, . s p i i n k e d s e r v e r s
Master :
EXEC sp_helptext 'sp_linkedservers'

:
Text
create proc sp_linkedservers as

10.

289

select
SRV_NAME = srvname,
SRV^PROVIDERNAME = providername,
SRV_PRODUCT = srvproduct,
SRV_DATASOURCE = datasource,
SRV_PROVIDERSTRING = providerstring,
SRV_LOCATION = location,
SRV_CAT = catalog
from master.dbo.sysservers
order by 1

, sp_imkedservers,
,
sp_addlinkedserver.


, . SQL Server 2000
. SQL Server 2000 ,
, ( ) . sp_addlinkedsrviogin
sysxlogins Master. ,
.
sysxlogins, , , .

sysxlogins , SQL Server 2000. , SQL Server, .


, SQL Server 2000, syslogins, sysxlogins, s r v i d NULL.
sysxlogins
( ) .
(self mapping).
,
Windows NT, Windows NT.
,
. SQL Server , . -

290

III.

, ( , )
.
(Login failed).
sp_addiinkedsrviogin :
sp_addlinkedsrvlogin [Ormtsrvname -] 'rmtsrvname'
[, [Suseself =] ' u s e s e l f ]
[, [@locallogin =] 'locallogin']
[, [Srmtuser =] 'rmtuser']
[, [Ormtpassword =] 'rmtpassword']

sysadmin Securityadmin.

:
[@rmtsrvname =]

'rmtsrvname'

, . sysservers.
sysname, .

[Ouseself =]

'useself

varchar(8)
TRUE FALSE. TRUE.

TRUE, TO
Windows NT , .
.
. , ,
Windows NT . Srmtuser Ormtpassword, . .
.
FALSE ,
SQL Server. , . , , ,
Srmtuser @rmtpassword.
[Slocallogin =] 'locallogin'

, . name -

10.

291

sysiogins. NULL
SQL Server, Windows NT. Windows NT
SQL Server, Windows NT. SQL Server
. sysname,
NULL.
d

[Srmtuser =]

'rmtuser'

,
. ,
, ,
,
.
, guseseif FALSE.
sysname NULL .
[grmtpassword =]

'rmtpassword'

, . sysname NULL . NULL , . NULL



.
spaddiinkedsrviogin. .
STORAGE\Treicn
Windows NT storage\Administrator:
EXEC sp_addlinkedsrvlogin 'STORAGE\Trelon',
'false1,
1
STORAGE\Administrator',
sa1,
1
[;k.by@[]wb,f&gfhec'

Windows NT sa. Windows NT


Windows NT:
EXEC sp_addlinkedsrvlogin 'STORAGENTrelon',
'true',
1
STORAGE\Administrator'

@locallogin sysxlogins, , . ,
.

292

III.

sa :
EXEC sp_addlinkedsrvlogin 'STORAGE\Trelon',
'false',
'sa',
'sa',
NULL

NULL. ,
.
NULL .


,
. ,
. . SELECT, sp_helplmkedsrvlogin.
,
SELECT,
, . , spjielplinkedsrvlogin.
-
. npi. sp_helplinkedsrviogin, :
sp_helplinkedsrvlogin [[drmtsrvname =] 'rmtsrvname']
[, [Olocallogin =] 'locallogin 1 ]


.
, , @rmtsrvname .
, , e i o c a l l o g i n . @rmtsrvname,
e i o c a i i o g i n .

10.

293

s p h e i p i i n k e d s r v i o g i n ,
. :
Linked Server , ;
Local Login , ;
is self Mapping 1,
Windows NT Windows NT. SQL Server
0;
Remote Login , , Local Login.
Windows NT ( is
self Mapping 1), NULL.
:
EXEC sp_helplinkedsrvlogin

:
Linked Server

Local Login

JM
NULL
DM
NULL
STORAGE
NULL
STORAGE\TRELON
sa
STORAGE\TRELON
STORAGE\Administrator
TRELON
NULL
(6 row(s) affected)

Is Self Mapping Remote Login


0
1
1
0
1
1

NULL
NULL
NULL
sa
NULL
NULL

,
STORAGE\Trelon:
EXEC sp__helplinkedsrvlogin 'STORAGE\Trelon'

:
Linked server

Local Login

STORAGEXTRELON
sa
STORAGEXTRELON
STORAGE\Administrator
(2 row(s) affected)

Is Self Mapping Remote Login


0
1

sa
NULL


.
. sp_droplinkedsrviogin, sysxlogins DELETE.

294

III.

sysxiogins.

, .

sysservers. srvname , .
srvid. ,
:
SELECT srvid, srvname FROM sysservers
, :
srvid

srvname

(5 row(s) affected)
,
, sysxiogins
. ,
, :
SELECT syslogins.name FROM syslogins, sysxiogins
WHERE srvid = 3 AND syslogins.sid = sysxiogins.sid
. (SID, Security Identificator).
DELETE, SID . DELETE
:
DELETE FROM sysxiogins WHERE s r v i d = 3 AND
SID = Ox010500000000000515000000833D2B4 654190E291525AF47F4010000

. . Server Settings
EXEC sp_configure ' a l l o w updates 1 , l. . " Server Settings" 8.
,
sysxiogins . .

10.

295

sp_droplinkedsrvlogin.
,
. :
sp_droplinkedsrvlogin [Srmtsrvname =] 'rmtsrvname',
[Slocallogin =] 'locallogin'
, , . [Srmtsrvname =] 'rmtsrvname'
, . , ,
[Siocallogin =] ' l o c a l l o g i n ' . sysadmin securityadmin.

Windows NT storage\Administrator,
STORAGE\Trelon:
EXEC sp_droplinkedsrvlogin 'STORAGE\trelon', 'STORAGE\Administrator'
.


, ,
, .
( ), , , .

s r v s t a t u s
sysservers. .
. ,
s r v s t a t u s .
. .
sp_serveroption, :
sp_serveroption [@server =] 'server 1 ,
[@optname =] 'option_name',
[Goptvalue =] 'option_value'


sysadmin Setupadmin.

III.

296

.
G [gserver =]

'server'

, . ,
. . srvname sysservers , Sserver. sysname,
.

[@optname =]

'option_name'

, . . 10.2 ,
. varchar(35),
.
10.2.

297

10.

10.2 ()

[goptvalue =]

'option_value'

, , @optname.
TRUE ON , FALSE OFF
. , ,
, c o l l a t i o n name
SQL Server.

. STORAGEXTrelon:
EXEC sp_serveroption 'STORAGEXTrelon', 'data access', 'TRUE'

298

III.

, , :
EXEC sp_serveroption 'STORAGE\Trelon', 'collation compatible', 'ON'


,
. , .

s p d r o p s e r v e r , :
sp_dropserver [gserver =] 'server'
[, [gdroplogins =] { 'droplogins' I NULL}]

@server ,
.
.

( ),

s p d r o p s e r v e r . gdroplogins,
d r o p l o g i n s ' .
, STORAGE\Treion
:
EXEC sp_dropserver 'STORAGE\Trelon',

'droplogins'

Enterprise Manager

Transact-SQL
, , SQL Server 2000
. , , ,
.
(SELECT, UPDATE, DELETE INSERT)

,

. . , ,
.

10,

299


, -
. , . SQL Server 2000 Enterprise Manager,
.

Enterprise Manager - . , , Enterprise Manager ,


.
Enterprise Manager Linked Servers (. 10.12), Security,
.

. 10.12. Linked Servers



Linked Servers . ,

300

III.

, SQL Server 2000.


, , sysservers .

Enterprise Manager , ,
. Enterprise Manager.
Enterprise
Manager .


Enterprise Manager Linked Server Properties - New Linked Server (. 10.13).
Linked Servers
Action New Linked Server.
,
, ,
. General
(. . 10.13),
,
. ,
,

sp addlinkedserver.

, .
Linked server. , . SQL Server 2000.
,
.
gserver,

sp_addlinkedserver.

SQL Server. Server type


, SQL Server 2000.
, Linked server, SQL Server 2000.
NetBIOS , SQL
Server 2000.

10.

301

_\_.
'SQL s e r v e r ' @srvproduct

sp_addiinkedserver. .
Other data source. Server type
, ,
SQL Server. SQL Server 2000. , , SQL Server 2000. Other
data source ,
.
Provider name. OLE DB, .
, , , . , SQL Server 2000, . .
. 10.1.
Product name. ,
. , mdb MS Access.
Ssrvproduct sp_addlinkedserver.
,
. ,
'SQL server' Server type SQL Server. ,
Server type .
Data source. .
Sdatasrc sp_addlinkedserver,
. " ". " Transact-SQL" . , ,
Odatasrc ,
Data source, OLE DB. ,
Microsoft OLE DB Provider for SQL Server,
SQL Server.
Microsoft Jet 4.0 OLE DB Provider,
.

^)

,
, -

III.

302

, . , .

Provider string. , , . .
. " "
. " Transact-SQL".

Location.
. ,
Data source .
Catalog. ,
. . , SQL Server
.

. 10.13. Linked Server


Properties - New Linked Server

. , spaddiinkedserver ,
General.

303

10.


General Linked Server Properties - New Linked
Server (. . 10.13) Provider Options.
Provider Options (. 10.14), . ,
Provider name.

, Provider Options .
. , SQL Server 2000 .

. 10.14. Provider
Options

, Provider Options,
,
. .
Provider Options .
Linked servers using for this provider,
, .
1 1 1207

304

III.

, , , . .
Linked servers using for this provider.

Provider options,
, (Enable)
( ) ( ).
(Name). .
:
Dynamic parameters. , ? . Dynamic parameters SQL Server 2000
,
. IcommandWithParameters.
Nested queries. , . FROM
, SELECT.
Level zero only. , OLE DB .
Allow InProcess. SQL Server 2000.
(UPDATE, INSERT) (text, ntext image).
, .
, SQL Server 2000 .
Non transacted updates.
, .
.
Index as access path. SQL Server 2000 .
Disallow adhoc accesses. OPENROWSET ()
OPENDATASOURCE (). .
.


Enterprise Manager
Security (. 10.15) Linked Server Properties.
, .
, Properties.

10.

305

. 10.15. Security

, . Local Login , .
, , Remote User. Remote Password
.
Impersonate , ,
.
.
For a login not defined in the
list above, connections will, ,
, :
Not be made , , .
Be made without using a security context
. ,
, , .

306

III.

Be made using the login's current security context , .


Be made using the security context , , .
:
Remote login,
, ;

With password ,
Remote login.

. , ,

,
, .


Transact-SQL spserveroption.

. 10.16. Server
Options

10.

307

Enterprise Manager Server


Options (. 10.16) Linked Server Properties.
Server Options ,
.
:
Option Name, .
Value, .
.
. " " . " Transact-SQL"
.


. ,
, . . SQL Server 7.0 , ,
(remote servers).

, , .
. ,
, .
, . , SQL Server 2000
SQL Server.
, . ,

,
.
,
, MS Access, dbf- . .

SQL Server 2000 SQL Server. SQL Server 7.0, .

308

III,

SQL Server 2000 , .


,
. , , .

.
,
sysservers Master. ,
,
. , SQL Server 2000 ,
, .
, . , servA serve, ServA ServB , , , servB
ServA . , servn
servA.

,

.
. ,
(self mapping).
.
.

Transact-SQL
, , .
Transact-SQL.


Transact-SQL
spaddserver, :
sp_addserver [Sserver =] 'server'
[, [Slocal =] 'local']
[, [@duplicate_ok =] 'duplicate_OK']

10.

309

sp_addserver sysadmin Setupadmin.

sp_addserver
SQL Server. ,
, . sp_addlinkectserver,
.
.
[gserver =] 'server'
.
NetBIOS , SQL Server 2000. ,
\_. .
[@11 =]

'local'

SQL Server 2000,


, , , , , . @@SERVERNAME.

SQL Server 2000 . ,


SQL Server 2000 .
[@duplicate_ok =] 'duplicate_OK']
sp_addserver. ,

, sysservers. sysservers. .
@dupiicate_ok

'duplicatejDK 1 ,
1 :
Server: Msg 15028, Level 16, State 1, Line 1
The server '@server' already exists.

310

III.

, ,
, sysservers.
( srvid). 0.
s p a d d s e r v e r giocal, 'LOCAL 1 , s y s s e r v e r s 0. ,
.
. 0 , @server SQL
Server 2000. , , .
SQL Server 2000 sysservers :
USE master
UPDATE s y s s e r v e r s SET srvname = 'NewServerName' WHERE s r v i d = 0

SQL Server 2000 . ,


. ,
.
SQL Server 2000 ,
. ,
. , SQL Server 2000 STORAGE\Trelon, :
SELECT * FROM [STORAGE\Trelon].pubs..authors

STORAGE\Train :
UPDATE m a s t e r . . s y s s e r v e r s SET srvname = ' S t o r a g e \ T r a i n ' WHERE s r v i d = 0


:
SELECT * FROM [STORAGE\Train].pubs..authors

, . , . ,
SQL Server 2000, -
, .
.
, . ,
. sysservers,

10.

311

, , .
, . , . SQL Server 2000 ,
sysservers
. ,
, , .
sp_addserver, . JL:
EXEC sp_addserver '.JL
NULL,
'duplicate_ok'


,
. ,
SQL Server 2000.
SQL Server 2000 , .
. OLE DB ,
, . OLE DB , .
, .
. , , .
, .

,
. . . -

312

III.

, , , . SQL Server 2000 , .



, , sysxlogins Master.
,

sp_addiinkedsrviogin,
. " " .
, , ,
. , .

SQL Server 2000 , Windows NT , . . s p _ a d a l i n k e d s r v l o g i n guseself, TRUE. ,


.


, . . ,
. , .
(

, . , ,
, ,
. , , ,
, ,
. . .
, ,
:
Server: Msg 11, Level 16, State 1, Line 1
General network e r r o r . Check your network documentation.

10.

313

Server: Msg 7221, Level 18, State 2, Line 1


Could not relay results of procedure 'ProcName' from remote server 'ServerName' .

:
sp_addremotelogin [Sremoteserver =] 'remoteserver'
[, i@loginame =] 'login']
[, [Sremotename =J 'remote_name']

sysadmin Securityadmin.
.
[Sremoteserver =] 'remoteserver'
, . sysservers. ,
.

[@loginame

=]

'login']

, .
,
sysxiogins . sioginame, Sremotename,

.
[Sremotename =]

'remote_name']

, .
,
Casper sa .
EXEC sp__addremotelogin 'STORAGE',
'Casper',
sa'
, ,
.

. , . ,

314

III.

sysxiogins .
@rmtuser .
,
, .
,
.
s p a d d r e m o t e i o g i n

Sremotename .
, .

, @rmtuser
Sremotename, ,
Srmtpassword sp_addlinkedsrvlogin,
( sioginame sp addremotelogin)
.

,
, . .
,
Windows NT. sp_addiinkedsrvlogin @useseif FALSE,
, . . ,
.

^)

. , . ,
. - . , s p s q i e x e c ,
.

. :

10.

315

sp_addlinkedsrvlogin ' STORAGEXTrelon',


'false',
'STORAGE\Administrator',
'RandomName',

, sa
.

:
sp_addremotelogin
' sa',
1
RandomName'

'STORAGE',


, ,
,

sp_helplinkedsrvlogin, . " " . " " ,


.
sp_heiprenrotelogin,
,
. :
sp_helpremotelogin [[Sremoteserver =]
[, [gremotename =] 'remote_name']

'remoteserver']


.
,
@remoteserver .

, ,
Sremotename.
sp_heipremoteiogin ,
. :
server , ;
locai_user_name ,
;

III.

316

remote_user_name , , ;
options , .
,
.
EXEC sp_helpremot.elogin

:
server

! user name

remote user name

STORAGE
STORAGE
STORAGE
JL
DM

sa

Administrator
RandomName
STOPAGE\Administrator
RandomName
RandomName

sa
sa
Casper
Casper

options

@remoteserve, 'STORAGE' , :
server

local user name

remote user name

STORAGE
STORAGE
STORAGE

sa

sa

Admi n i s t r at
RandomName
STORAGE\Admin i s trat

options

@remotename:
EXEC sp_helpremotelogin NULL , 'RandomName1

:
server

local_user_name

remote_user_name

STORAGE
JL
DM

sa
Casper
Casoer

RandomName
RandomName
RandomName

options

sp_neipremoteiogin sysremotelogins,
sysxiogins. sysremotelogins
sysxiogins.
. ,
, sp_helpremotelogin.
sysremotelogins :
remoteserverid , .
, srvid sysservers;

10.

317

remoteusername ,
;
s t a t u s .
small i n t . ,
, . ;
sid (SID) , ,
remoteusername. SID
SUSER_SID ( ' LoginName ' ) ;

changedate .
, . ,
.


, ,
.
- sp_remoteoption, :
sp_remoteoption [[Sremoteserver =]
[, [@loginame =] 'loginame']
[, [@remotename =] 'remotename']
[, t@optname =] 'optname']
[, [goptvalue =1 'optvalue'i

'remoteserver'1

~~)

sysadmin Securityadmin.
.
U [@remoteserver =] 'remoteserver1
, . ,
. ,
. . srvname sysservers.

[Ologiname =]

'loginame 1

, , .
.
eioginame
.

318

III.
[gremotename =]

'remotename'

, .
spaddremotelogin,
.
[goptname =]

'optname'

, . , , . ' t r u s t e d ' .
.
' t r u s t e d ' (@optvaiue='TRUE'), . , , , ,
, .
(goptvalue='FALSE')
.
,
.
CJ [goptvalue =] 'optvalue'

TRUE, , FALSE, .
, STORAGE RandomName,
sa, :
sp_remoteoption 'STORAGE',
'sa',
'RandomName',
goptname = 'trusted',
goptvalue = 'TRUE'


, , sp_droplinkedsrviogin. . " " . " " .
spdropremoteiogin, :
sp_dropremotelogin [@remoteserver =]
[, [gloginame =] ' l o g i n ' ]
[, [gremotename =] 'remote name']

'remoteserver'

10,

319

sysadmin Securityadmin.
, , . @remoteserver,
, . aioginame
,
. , @remotename , .

Windows NT Casper, STORAGE:
EXEC sp_dropremotelogin gremoteserver = 'STORAGE',
Sremotename = 'Casper'
.


, . , , . , ,
, .
,
, . , sp dropserver.
.

.
, SQL Server 2000 . ,
.

Enterprise Manager
,
, -

320

III.

. ,
. , .
Linked Server Properties - New Linked Server. Enterprise Manager .

Remote Servers (. 10.17),
Security .
Remote Server Properties (. 10.18),
New Remote Server
Remote Servers Action.

. 10.17. Remote Servers


Name SQL Server 2000,
. NetBIOS , SQL Server 2000. . ,

321

10.

. , Name. ,
.

. 10.18. Remote
Seiver Properties

,
SQL Server.
.
RPC,

(RPC, Remote Procedure Call).
Remote login mapping , ,
.
Map all remote logins to
(. . ,
, ). , , . <Same Name>. , ,
,

322

III.

. , , , .
.
.
.

, .
Map remote logins to different local
logins
, Name. Remote Login Name , -
. .
Local Login Name , .
,
.
Check Password , .
, , .
.

11



.
, ,
.
.
.
.
,
. , , , DB2,
Paradox, MS Excel, dBase . .

,
.
. ,
. ,
.
. SQL Server 2000
,
. , ,
,
. SQL Server,
, , .
SQL Server 2000 , . SQL Server 6.x , . ,
, .
SQL
Server 2000, . SQL Server 2000
Microsoft , SQL Server 2000.

324

III.

,
SQL Server 2000
.


SQL Server 2000
.
, .
.
SQL Server 2000 , .
SQL Server 2000 .
, SQL Server 2000. ,
. ,
MS Excel, xls-.
(

, " ". ,
.
SQL Server 2000 , . ,
, .
. , , ,
. , SQL Server 2000
, . , , .
/ . SQL Server 2000 .
, SQL Server 6.x SQL Server 2000
. SQL Server 2000.
,
. , SQL

11.

325

Server 2000, , . SQL Server 2000.


.
5.


SQL Server 2000
. . , SQL Server 2000 , .
:
Data Transformation Services (DTS). SQL
Server 2000
DTS. . "
Data Transformation Services" .
Bulk Copy API.
,
. " " .
.
14.
SQL Server.
, -
SQL Server 2000. SQL Server 6.x
SQL Server 7.0.
Distributed Query. , .
(remote query).
SELECT INTO. , .
. SELECT INTO , .
INSERT. . ,
, . . .
, ,

326

III.

. . . 11.1
.
11.1.

DTS

BULK
INSERT

ODBC

OLE DB

*
*

*
*

ODBC

OLE DB

*
*
*

*
*

Transact SQL

SELECT
INTO/
INSERT

*
*

DTS .
bcp.exe, BULK INSERT SELECT INTO/INSERT

SQLServerAgent. , DTS SQLServerAgent.


.
OLE DB.
ODBC-.
OLE DB .
OLE DB Microsoft , DB-Library, -

11.

327

API . Microsoft
ODBC, , OLE DB,
:
ISAM/VSAM ;
;
, ;
- .
Universal Access , Universal Server,
,
. , . . ,
. ,
. Universal Access , .
.
,
. SQL Server OLE DB ,
. OLE DB ""
.
SQL Server 2000 OLE DB 2.0, API . OLE DB
,
. OLE DB
, . . .
SQL Server 2000 OLE DB,
.
OLE DB
.

SQL Server 2000 OLE DB. SQL Server 2000 ODBC. ODBC , , MS Excel MS Access.
ODBC SQL Server 2000
OLE DB OLE DB Provider for ODBC. OLE DB ODBC,
.

328

III.


SQL Server 2000 .
Oracle, MS Access,
dBase . , "" , . , -
, , -
, . . ,
.
.
, .
, . , SQL Server 2000, . , ,
, , .
SQL Server 2000 ,
Unicode.

, .
SQL Server 2000
:
D bcp.exe (Bulk Copy Program);

Transact-SQL BULK

INSERT;

DTS.
.

Data Transformation Service



.
, .

. ,
.
,
. , ,
-

11.

329

. , .
, ANSI SQL-92,
. , . , ,
, .
Microsoft , Data Transformation Services
, DTS Transformation Engine.
, DTS. ,
"" ,
. , Oracle DTS- ANSI SQL,
Oracle. DTS Transformation Engine . , .
DTS ,
, Microsoft Excel. ,
OLE DB provider for ODBC , ODBC-, Sybase Informix. DTS
, OLE DB,
. Microsoft
,
.
Data Transformation Services
.
DTS , . DTS .
,
, ,
. Data Transformation Services . SQL Server 2000
, .
. DTS JavaScript.
VBScript PerlScript.
DTS , . SQL Server 2000,
. -

330

III.

,

- . DTS "" .
.
DTS
, . ,
SQL Server 2000,
: , , , . . ,
, .

DTS
, ,
, ,
, .

(package). DTS :

Connections objects. OLE DB,


. SQL Server 2000
. Connections objects :

File connections. .

, (ANSI
Unicode). ,
.

Data Source Connections.


, DTS . ,
. . SQL Server 2000,
Paradox, dBase, MS Access 2000, Oracle,
MS Excel, HTML, ODBC, . ., , OLE DB.

Microsoft Data link Connections.


, DTS,
OLE DB,
Microsoft Data Link Connections.
udl. , , .
Task Objects. DTS ,
. (tasks). , -

11.

331

. Task Objects :

. Data
Driven Query Task, Transform Data Task ParallelDataPump Task Objects.
. Microsoft ActiveX.

.
SQL Server Objects Task, Execute SQL Task Bulk Insert Task.
. , , , ,

, .

DTS.
ActiveX Script Task, Dynamic Properties Task, Execute Package Task, File
Transfer Protocol Task, Execute Process Task Send Mail Task.
, ,
.
, . , .
.

Step Objects. ,
. (precedence constraints),
. ,
,
. ,
.
, TaskA TaskB,
, TaskA
,
TaskB.

(Unconditional) . TaskB
, TaskA. ,
, .

(On Success) TaskB ,


TaskA .
, , TaskA
, TaskB . ,
, , . .
.

332

III.

(On Failure) , TaskB


TaskA. , ,
.
DTS DTS Import
and Export Wizard DTS Designer. DTS Wizard, SQL , . DTS Query
Builder .
, , , . , , .
.
, DTS,
DTS Designer .
, ActiveX. ,
. Task-objects . DTS Designer ,
. .
, DTS , -.

.
SQL Server. , DTS- , ,
.
SQL Server
Msdb, Microsoft Repository - .
DTS Microsoft Repository
. MS Repository
, .
, .
, . , Open Information Model,
Microsoft Repository.

11.

333

SQL Server . DTS


SQLServerAgent, Enterprise Manager dtsrun.exe. Data Transformation
Services ,

. ,
, , .
, . , ,
Task-objects. DTS
ActiveX ( VBScript, JavaScript PerlScript),
, SQL ,
,
. , . , . DTS -, .

Data Driven Query Task. .
, ,
.
ActiveX . Data Driven Query Task , . -
,
.
,
.
, . , , .
Data Driven Query Task Data Transformation Lookups,
. ID ,
, Data Transformation Lookups ActiveX
ID -.
- .

334

III.


, DTS Connection-objects.
OLE DB,
, , . OLE DB
. DTS Designer MS Access,
FoxPro, MS Excel, SQL Server, Oracle, Paradox, dBase .
, Microsoft Data Link Other Connections, .
.

, DTS- Step-objects.
,
,
DTS- .
, TaskB
, TaskA .
, TaskB
TaskA. ,
. , .
. ,
.
,
. , Oracle Paradox.
DTS Data Pump,
OLE DB Service Provider, , . DTS Data Pump -, ,
OLE DB. DTS Data Pump OLE DB . . Data Pump ActiveX, , .
ActiveX OLE . , DTS . Data Pump, OLE DB . , .

. DTS Data Pump ,
.

11.

335

SQL Server 2000 ActiveX Data Objects 2.0 (ADO),


OLE Automation OLE DB (Visual Basic, Visual J,
C++) (VBScript, JavaScript, PerlScript).
ADO.
DTS DTS Objects Transfer,
.

SQL Server 2000. . DTS- DTS
Objects Transfer
Transact-SQL -.
- SQL-DMO ODBC, OLE DB.
SQL-DMO.
, ,
, , , , ,
, ,
. , .
,
. DTS , . , , , .
DTS Wizard,
DTS Designer. DTS Wizard Transfer SQL Server
Objects, , .
. ,
.
, , DTS Wizard DTS Designer .
DTS.

DTS Export Import Wizard


, ,
, .
DTS .
, . DTS Import Wizard DTS Export
Wizard, . ,
12 . 1207

336

III.


. ,
. , , ( ).
, ,
. ,
DTS, ,
. , . MS Excel,
. ,
.



:
Run a Wizard Enterprise Manager.
Select Wizard (. 11.1), . DTS Data
Transformation Services.
. Select Wizard ,
Tools Wizards.
, Programs (),
Microsoft SQL Server Import and Export Data.
dtswiz Run ( ) (. 11.2), Run () .

DTS Import Export Wizard dtswiz.exe,


\Program Files\Microsoft SQL Server\80\Tools\BINN. , . .
PATH, , . Run ( )
dtswiz, .
, ( ),
(. 11.3), .
DTS Import/Export Wizard ,
.

11.

337

. 11.2. Run

. 11.1. Select Wizard

. 11.3. DTS Import/Export Wizard

, , DTS Import/Export
Wizard, ,

III.

338

. .

Enterprise Manager,
Enterprise Manager (task bar)
. ,
d t s w i z ,
. Enterprise Manager
.



. (. 11.4)
Next. Choose a Data Source,
.

. 11.4. Choose a Data Source DTS Import/Export Wizard

Source, OLE DB
. , ,
, .
.
. 11.4 Microsoft
OLE DB Provider for SQL Server.

11.

339

DTS Designei.
,
SQL
Server 2000:
dBase - V, III IV;
(txt);
MS Excel (csv);
MS Access ( mdb);
dBase ( dbf);
MS Excel ( xls) 35, 972000;
Paradox ( db) 3.x, 4.x 5.x;
Visual FoxPro;
Oracle;
SQL Server;
;
OLAP Services 8.0;
ODBC.
SQL Server (. . Microsoft OLE
DB Provider for SQL Server),
:
Server.
SQL Server, .
, . , .

SQL Server 2000 Windows 98 Server , . .


.
Use Windows NT authentication. , SQL Server
Server, , . DTS , , ,
Windows NT, Windows NT SQL
Server .
Use SQL Server authentication. SQL Server. :

III.

340

Username , Server .
;

Password ,
.

Database. , . Server,
,
Database , . ( ),
.
<default>.
,
, .
Database . .
Refresh, .
Advanced.
Advanced Connection Properties (. 11.5),
.
,
.
.

. 11.5. Advanced Connection Properties

11.

341

,
Source OLE DB.
SQL Server.


, , (. 11.6). Choose a destination, .
, .

. 11.6. Choose a destination DTS Import/Export Wizard



,
. ,
, . SQL Server 2000 (. . Microsoft OLE DB Provider
for SQL Server) , Database
<new>, SQL
Server , .
Database <new> Create
Database (. 11.7),
.

III.

342

, , ,
, .
.

. 11.7. Create Database


Name ,
.
. , Name,
, .
, Default data directory (
mdf ndf) Default log directory ( ldf)
Database Settings . Database Settings . " Database Settings" 8.
Create Database () . ( Data file
size), ( Log file size). Model ,
10% .
,
.
.


, ,
.
(. 11.8) ,
.
Specify Table Copy or Query, "
".

11.

343

. 11.8. Specify Table Copy or Query DTS Import/Export Wizard

,
:
Copy table(s) and view(s) from the source database. ,
.
, .
,
ActiveX. ,
, .
.
Use a query to specify the data to transfer.
. ,
Query Builder. , .
.
,
.
Copy objects and data between SQL Server databases.
,
. ,
.

, , SQL Server. . 11.8.

344

III.
, . SQL Server,
.

, , ,
.
, .



Copy table(s)
and view(s) from the source database,
. Next,
, , . 11.9.

. 11.9. Select Source Tables and Views


DTS Import/Export Wizard

Select Source Tables and Views,


".
, , . Source

11.

345

, ,
.
, .
,
.
Destination ,

, . Destination , .
,
, . , ,
.
Column Mappings,
Transformations, and Constraints (. 11.10), Transform ^ 1 .
. .

. 11.10. Column Mappings, Transformations, and Constraints


Column Mappings, Transformations, and Constraints , . ,

346

III.

. , . Source
( ), Destination , .
.

Column Mappings, Transformations, and Constraints.

Column Mappings
Column Mappings (. . 11.10)
.
. , :
Create destination table.
,
. ,
. . ,
, .
,
. , Drop and recreate destination table, .
, ,
, . , .
Delete rows in destination table. - (, , , . .),
,
, - .
, , . ,
, . . DTS
. , ,
, -

11.

347

, .
Append rows to destination table. , , ,
.
, . .
. ,
DTS ,
. ,
.
. , , . .
, , . ,
. , .

, , , ,
.
Enable
identity insert,
-. - , IDENTITY.
,
. . - .
, -, . , .
() , -
IDENTITY, () , .

. , , , . ,

. .

348

III.

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

, .
, . ,
. .
Enable
identity insert, , .
,
IDENTITY.

(~

^)

. . -
,
IDENTITY SET IDENTITY_INSERT.

Column Mappings Mappings, .


. "-", . .
. :
D Source. , .
, .
, <ignore>. ,
(
Destination) NULL, ( ) .
. ,
NULL, TO
Source <ignore>
.

11.

349

Source column, . , NULL.


.
Destination. , .
Source, Destination (
,
Source), .
.
Source, Destination
<ignore>. ,
, , .
. ,
. ,
, . ,
. . , . ,
,
. , s m a i l i n t i n t smalimoney money.
Nullable ,
NULL
.
Size. . ,
(char, varchar, nchar nvarchar), Size
, . , .
( t i n y i n t , smailint, i n t b i g i n t ) ,
(smalldatetime datetime), (smalimoney money)
.
Precision. (numeric,
decimal, f l o a t r e a l )
, .
Precision (

350

III.

),
.
Scale. . , . Scale
Precision . ,
, Precision Scale.

, 26.
Mappings,
. ,
. , . ,
Mappings. , Create destination table Drop and
recreate destination table, , , Mappings.

Mappings Transact-SQL, .
Constraints.
Mappings
. Source .
. , , .

Transformations

Transformations (. 11.11).

,
:
Copy the source columns directly to the destination columns.

11.

351

- . , .
Transform information as it is copied to the destination. , .
.

. 1 1 . 1 1 . Column Mappings, Transformations,


and Constraints, Transformations

.
.
,
.

ActiveX VBScript (Visual Basic scripting language) JavaScript (Java scripting
language). ,
, Language
.
. .

VBScript JavaScript SQL


Server 2000. PerlScript.

III.

352

,
, Mappings
Column Mappings.
, . ,
. Browse.


ActiveX, . . , .

Constraints
Constraints (. 11.12), , . , .
, Column Mappings Create destination table.
Drop and recreate destination table.

. 11.12. Column Mappings, Transformations,


and Constraints, Constraints

11.

353

:
Create Primary Key. , ,
. Create Table
Statement Alter Table Statement.
Create Foreign Keys. , , .

, ,
. :
At Create Time. , ( )
. .
, , .
After data transformation.
, . , , . ,
( At
Create Time). ,
. , . .
, FOREIGN KEY ( ). ,
,
.
. ,
.
ALTER TABLE, .
, :
Create Table Statement. CREATE TABLE, .
Create Primary Key Create Foreign Keys At Create Time , ,
. CREATE TABLE,

III.

354

, , Mappings Column Mappings.


. ,
. Create
Table Statement ,
Auto Generate, .
Alter Table Statement. ALTER
TABLE, .
,
(Create Primary Key Create Foreign Keys), a
After data
transformation ( ).
, ,
.
,
(, UNIQUE,
) .

CREATE
21.

TABLE ALTER

TABLE

. 1 1 . 1 3 . View Data

Constraints Column Mappings,


Transformations, and Constraints . ,
. (Save, schedule, and replicate package) DTS,
.

11.

355

, . Save, schedule, and replicate package . " " . Select


Source Tables and Views (. . 11.9) Preview, View Data (. 11.13). , .
,
.




.
, . , . , , .
Use a query to specify the data to transfer. ,
(. . 11.8).
, Next,
, , . 11.14.

. 11.14. Type SQL Statement DTS Import/Export Wizard


Query statement, ,
. -

356

III.

, .

(~

,
, . ,
.
, Query Builder
. Browse, .
Parse . ,
,
, . , , , .
Parse.

SELECT,
, 29.
, ,
Query
Builder, , .
Query Builder ,
DTS Import/Export Wizard. Query Builder, . Query Builder.


Query Builder (. . 15) Select Columns, " ". , , .
.

SELECT.

Source tables , . , . ,'


, -

11.

357

> .
Selected columns, . ,
. , . -
Selected columns , <. .
Selected columns ,
.

. 11.15. Query Builder

,
Selected columns, .


(. 11.I6) Specify Sort Order,
" ".
,
.
, , . Selected columns,
, .
,
Selected columns Sorting order.

III.

358

. 11.16. Query Builder

ORDER
SELECT, .
Sorting order , . Sorting order .
, , .
, , . . ,
Sorting order,
.
Sorting order Move Up Move Down, , ,
.
, Sorting order
, ,
.

, Sorting order .
, ,
.

11.

359


, (. 11.17) Specify Query
Criteria, " ".
, ,
. .

. 11.17. Query Builder

, ,
. All rows ,
, .
, ,
Only Rows meeting criteria.

, . .
Column , .
, Selected
column . ,
, (<, >, =, , <=, >=), . , Value/Column,
,

III.

360

Column. Value/Column
, ,
.
, , , Column.
Select a Value
(. 11.18), _i,
.
,
.
. Value/Column.
,
. , . 11.18. Select a Value
, . :
AND.
, ,
.
OR.
.
. . .
, Query statement .

,
, Column, ,
Value/Column. , Query statement ,
, .
Parse.
, . Next DTS Import/Export Wizard.

11.

361

Query statement . Parse.


, , , . ,
, ,
.


, , , , . (. 11.19),
Select Source Tables and Views.

. 11.19. Select Source Tables and Views


DTS Import/Export Wizard
Select Source Tables and Views
, (. . 11.9). ,
Select Source Tables and Views,
. " " .
,

Select Source Tables and Views Query, , ,
.

362

III.

(Save, schedule, and replicate)


DTS,
. ,
. Save,
schedule, and replicate package . "
" .
,
, .


, . ( ) .
.

.
,
, -
SQL Server . Copy objects and data between
SQL Server databases.

(~

"^

, SQL Server. SQL Server, . SQL Server 7.0 SQL Server 2000
SQL Server 2000.
, ,
Specify Table Copy or Query (. . 11.8). . " " .
, Next, , ,
. 11.20.

Select Objects to Copy, " ". , , SQL
Server SQL Server-. ,
. , ,
, .

11.

363

. 11.20. Select Objects to Copy DTS Import/Export Wizard

Copy SQL Server


Objects Task. , ,
, DTS Designer
, Copy SQL Server
Objects Task, .
,
.


Create destination objects (tables, views,
stored procedures, constraints, etc.), , : ,
, , , ,
. . , .
, , . , , , Create destination objects
(tables, views, stored procedures, constraints, etc.) .
:
Drop destination objects first. ,
,
, DTS , ,

364

III.

.
, ,
. , ,
,
.
, (
) - .
Include all dependent objects. , ,
. , . , , . . .
. ,
( ) . Include all depends objects, ,
.
. , , . , , Select Objects (. ! 1.21),

. Select Objects , . . Copy all objects. ,
. , Select Objects .
Select Objects ,
Objects . :
Show all tables ;
Show all views ;
Show all stored procedures ;
Show all defaults ;
Show all rules ;
Show all user-defined data types .
, Show all tables Show all
stored procedures, . Objects , ,
. ,
, .

365

1-1.

. 11.21. Select
Objects
Objects.
. Object ,
.

.
. Object Name.
,
.
Select All,
Objects. Check Uncheck , , .
Select All .
<Ctrl> .
, , Select
Objects , .


, , . , .
Copy data (. . 11.20),
, Select Objects.
Copy data , . , .
Copy data , -
, .

366

///.

Copy data , , .
:
Replace existing data. ,

. ,
, .
Append data.
. .
.


, ,
. , Select Object to Copy
DTS Import/Export Wizard , ,
, , ,
.
. Transact-SQL, , .
-. ,
. ,
, ,
,
.
DTS Import/Export Wizard , . , Select Objects,
, ,
.
\Program Files\Microsoft SQL Server\80\Tools.
, Script file directory
Browse for Folder, , .

SQL Server.

sql, , . -

367

11.

,
( log), , . , . . .

,
.
Advanced Copy Options (. 11.22),
Options. ,
. . . Use default options. - ,
Advanced Copy Options.

. 11.22 . Use default options


.

. 11.22. Advanced
Copy Options

Security options ,

:
Copy databases users and databases roles. , .
, ,
. , 1 3 * 1307

III.

,
( ).
,
. , .

dbo.

, DTS
. , , . ,
. -
, . , DTS.
Copy SQL Server logins (Windows NT and SQL Server).
( SQL Server, Windows NT), -.
, (. . )
, . sp_grantdbaccess, 9.
,
. , .

SQL Server, , .
sp_addlogin, SQL Server, Spasswd NULL.
SQL Server,
.
s p a d d l o g i n 9.
Copy object-level permissions. -,
, .
.
()

11.

369

GRANT DENY, , , .
(

. REVOKE . , Copy object-level permissions ,


.

. , .
, ,
(GRANT), (DENY).
. , .
- Transact-SQL, , , . . Query Analyzer.
Advanced Copy Options Table
options,
, .
:
Copy indexes. , Select Objects.
Copy triggers. .
Copy full text indexes.
.
Copy PRIMARY and FOREIGN keys.
.
Generate Scripts in Unicode. Unicode, .
, .
Use quoted identifiers when copying
objects,
. ,
(, ).
, . . ,
.
13*

370

III.

,
SQL
Server, . Select Object to Copy, . Save, schedule, and replicate package
DTS, .

.



, Specify Table Copy or Query. . , ,
Save, schedule, and replicate package (. 11.23),
, .

. 11.23. Save, schedule, and replicate package



, .
When,
:
Run immediately.
. -

371

11.

, ,
.
Use replication to publish destination data.
, .
DTS Import/Export Wizard
Create Publication Wizard, .
, . ,
. , Create Publication
Wizard, 14.
D Schedule DTS package for later execution. , Run immediately
, .
.
(, ) .

. ,
SQLServerAgent, .
, Schedule DTS
package for later execution.
(Occurs every I day(s), at 0:00:00). .
Edit Recurring Job Schedule (. 11.24),

I. . " ".

. 11.24. Edit
Recurring Job Schedule

372

III.

Save, schedule, and replicate package (. . 11.23) . ,


, . , Schedule DTS package for
later execution, Save DTS Package,
.
Schedule DTS package for later execution.
.
,
Save. :
SQL Server. sysdtspackages Msdb.
SQL Server Meta Data Services.
SQL Server, , , , , .
Structured Storage File. ;
Visual Basic File. Visual Basic.
. .


, Edit Recurring Job Schedule (. . 11.24) .
.
Occurs . , , , ,
. Occurs
:
Daily .
Daily , . , ,
. .
Weekly . Weekly , , .
, ,
, . .

11.

373

Monthly .
Monthly.
, .
, . . Daily frequency.
:
Occurs once at.
, .
(0:00:00). , .
Occurs every. ,
. ,
, , . . , Starting at , . ,
, Ending at. ,
. ,
.
, Duration
, .
.
:
Start date. ,
.
,
. ,
, Start date. , ,
2001 , Occurs Monthly, 25 . , 25
. Start date
.
End date. ,
. , .
.
No end date. .

374

III.

,
, Management\SQL Server Agent\Jobs
Enterprise Manager , , , , .
. , , . .


Save, schedule, and replicate package (. . 11.23)
Save DTS Package, ,
(. 11.25) Save DTS Package, "
DTS".
.

*i

. 11.25. Save DTS Package


,
:
Name. , .
, .
Description.
.

11.

375

Owner password. . , , .
,
.
User password. , , .
, .
Location. .
Server name. SQL
Server, .
Use Windows NT authentication. Server name Windows NT.
Use SQL Server authentication. SQL Server. (Username),
, (Password) .
Save DTS Package (. . 11.25), , SQL Server
SQL Server. Visual Basic Save DTS Package . , , ,
, .



. (. 11.26)
, .
Finish , ,
.
Finish, Save, schedule, and replicate package
Run immediately. Execution
Package (. 11.27). , .
Execution Package.
DTS Import/Export Wizard
.
DTS Designer, DTS
.

III.

376

. 11.26. DTS Import/Export Wizard

. 11.27. Execution
Package

DTS Designer
DTS Import/Export Wizard. , SQL Server.
. , -

11.

377


SQLServerAgent.
.
DTS, . , . , . .
.
,
. DTS ,
. ,
: DTS Import/Export Wizard . DTS,
DTS Designer.
.
DTS Designer Enterprise Manager
Data Transformation Services
New Package. DTS Package: <New Package >
(. 11.28).

. 11.28. DTS Package: <New Package> Enterprise Manager

378

III.

. 11.28 , , . , , .
,
. Task
(task), SQL Server 2000.
Data (datasource),
DTS Designer.
, .



, , .
, .

,
. , ,
" ", " ".
, DTS Connection objects. DTS Designer
, . , Microsoft Data Link Other Connections.
DTS, DTS Designer, Data.
. , ,
, .


.
, DTS OLE DB,
. -

11.

379

, Data, OLE DB. , OLE DB , .

, , . , , .

Data :
Microsoft OLE DB Provider for SQL Server
Microsoft SQL Server;
Microsoft Access Access;
Microsoft Excel 97-2000
Microsoft Excel 972000;
dBase 5 dBase 5;
HTML File (Source)
() HTML;
! Paradox 5.x Paradox 5.x;
Text File (Source) ,
();
Text File (Destination) ,
();
Microsoft ODBC Driver for Oracle Oracle;
Microsoft Data Link , UDL,
, OLE DB
. , Microsoft Data Link;
Other Connections ,
ODBC.
, DTS Designer
, (, ).
, .

, DTS ,
, . , -

380

III.

DTS Designer, Task.


:
File Transfer Protocol Task
Web;
ActiveX Script Task
ActiveX;
Transform Data Task
, ;
Execute Process Task , ;
Execute SQL Task Transact-SQL;
Data Driven Query Task ;
Copy SQL Server Objects Task
SQL Server 2000 SQL Server 7.0.
, , ;
Send Mail Task . ()
( ) ;
Bulk Insert Task
. bcp.exe;
Execute Package Task DTS;
Message Queue Task DTS;
Transfer Error Messages Task
, ,
SQL Server 2000;
Transfer Database Task
SQL Server;
Transfer Master Stored Procedures Task ,
. SQL
Server 2000. ;
Transfer Jobs Task , , ;

11.

357

Transfer Logins Task SQL Server;


Dynamic Properties Task
.
SQL Server 7.0, , , ,
SQL Server 2000 . SQL Server.

Task. , , . .


,
.
, .
, ,
.
.

File Transfer Protocol Task


File Transfer Protocol Task ,
. 11.29. FTP Site FTP Transformation.
, ,
.
(. 11.29) :
Description. , . .
Source. , . ,
, . :

Internet Site .
, . 11.28.
;

Directory .
. Source

Directory path,
.

382

III.

. 11.29.
File Transfer Protocol Task

FTP Site. , . , .
Username. ,
, .
anonymous, . . .
Password. , . anonymous .
Number of retries. ,
.
, .
Directory path. , , ( Source
Internet Site) ( Source Directory)
, .
FTP Site ,
FTP Transformation (. 11.30). , ( ). FTP Transformation
. (,

383

11.

), .

. 11.30.
Properties File Transfer
Protocol Task,
FTP Transformation

FTP Transformation . , .
Source, , ( ). .
. , FTP Site ( Directory Path), . , Directory Path
C:\Windows\System32,
, C:\Windows\System32
. C:\Windows ( . :\) Source .

FTP Transformation , Source .

Destination ,
. .
Source Destination ,

384

III.

.
Destination, , , .

. Refresh.
Destination Overwrite,
, , .
,
. , , Directory Path Destination FTP Site, , .
. Overwrite.
,
Destination, File Transfer Protocol Task
. , DTS
.

ActiveX Script Task


ActiveX Script Task ActiveX. VBScript JavaScript. :
, ;
, ;
, ;
ADO (ActiveX Data Objects), , , .

(~

, SQL Server 2000, , PerlScript.


ActiveX Script Task ,
. 11.31. , .
DTS.

11.

385

. 1 1 . 3 1 . ActiveX Script Task

Description, ,
, . , .
,
. , ,
.

ActiveX
. , .
VBScript JavaScript , , MSDN (Microsoft Developer Network).

, , ,
. , , Language.
VB Script Language JavaScript
Language. Language
. , .
, Language -

386

III.

, . .
, . . 11.31 , VBScript. Auto Gen.
Functions, , , Language.

.
.
Entry function ,
. , Entry function. Main. ,
, Main. , .
, Language, Functions Entry function Language. ,
Browser, , .
Browser . ] 1.32.

. 11.32. ActiveX Script Task

11.

387

, ,
, . Browse. ,
. Save.
Parse,
. , .
. Undo.
, . OK, Cancel Help ,
.
, , , . , ,
, . , . ,
.

Transform Data Task



. , . , ,
Data, .
, , , (. 11.33).
Task
Transform Data Task, , (source), ,
(destination). , , Transform Data Task Task.
,
, , <Ctrl>, . Transform Data Task . Task, Transform Data Task
, .
Transform Data Task ,
. 11.34. , .

III.

388

. 11.33. Transform Data Task

. 11.34.
Transform Data Task

11.

389


Source , . ,
Description, , . , .
Connection , Transform Data
Task. , .
, ,
.
Table/View

. ,
, .
Preview, View Data (. 11.35) , , . .
. ,
200 .

. 11.35. View Data


,
SQL query. , , . , Build Query, Browse
Parse Query. , -
, Parameters.

390

III.

:
, ;
, Browse;
Query Builder.
.
SELECT, , 29.
Query Builder.

Query Builder
Query Builder Build Query. Data Transformation Services Query Designer (. 11.36).

. 11.36. Data Transformation Services Query Designer


(pane),
:
Table/View Pane.
, , ,
Transform Data

11.

391

Task. Diagram Pane.


Diagram Pane. , , , ,
. ,
, ,
. ,
, .
( SELECT).
. Sort
Ascending, . Sort Descending
. ORDER BY . ,
.
, ,
, . JOIN. , Diagram Pane, Grid Pane SQL Pane.
Grid Pane. , Diagram Pane. Grid Pane
, , .
,
Diagram Pane.
Diagram Pane
, Grid Pane
Column.
, , Diagram Pane.
,
. , ,

, . Alias
, . , . Table , .
Column , Column

3Q2

III.

, Table.
Output , .
Diagram Pane. ,
SELECT . Sort Type
,
. Ascending Descending. , , . Sort Order. , ,
Criteria. ,
. , .
. , Or.
, , , OR. , , . , AND,
AND.
SQL Pane. ,
.
, SQL Pane. , ORDER BY,
WHERE. ,
. SQL Pane.

SELECT 29.
d Results Pane. , . , , ,
, . , Results Pane,
Transform Data Task.
Data Transformation Services Query Designer,
. -

11.

393

. Table/View Pane, Diagram Pane SQL Pane.


. ,
,
. .
Table/View Pane, Diagram Pane . .


.
, .
Properties (. 11.37),

( Table/View Pane), Properties.

. 11.37. Properties,
Query
Properties , , Query,
. 11.37. :
Query name. .
,
. ,
Transform Data Task, . ,
Query name.
Transform Data Task .

394

III.

Output all columns. SELECT *, , Diagram Pane.


DISTINCT values. ,
SELECT DISTINCT,
,
.
.
GROUP BY extension. , . GROUP BY
extension ,
:
WITH CUBE GROUP BY WITH CUBE, .
, , ;
WITH ROLLUP GROUP BY WITH ROLLUP,
;

ALL
, ,
WHERE . ,
, ,
, NULL.

, , 29
SELECT. ,
PERCENT WITH T I E S .

. ,
. ,
, ,
.

REPCENT ,
,
. ,
0 100;

WITH TIES
, ,
ORDER BY, .
WITH T I E S .

395

11.

SQL Comment. , , . ,
, , .
SQL Comment Source Transform Data Task
Properties (. . 11.34) .
Query Properties
. Parameters
(. 11.38) .



, , , DTS. , , , . ,
. . , .
.

. 11.38. Properties,
Parameters
Parameters , , .
, :

396

III.

Prefix characters. , . .
% @.
Suffix characters. , . , , .
Escape character. , , , . . . ,
, , .

(Escape-). ,
DTS . \.
Parameters.
% ( ,
). [ ]
{ }.

Transform Data Task , , . , ,


.
.
, , Data Transformation Services
Query Designer . ,
SQL Pane, Source Transform Data Task
Properties (. . 11.34). ,
, SQL Comment
Properties Query (. . 11.37).

Source , Parse Query.


, Transform Data Task
.
DTS,
.
? , . WHERE, . .

397

11.

. ,
Source :
SELECT *
FROM
authors
WHERE (state = ?)

, , . . Transform Data Task , , 1. ?,


. , .
Parameter Mapping (. 11.39),
Parameters Source. ,
, .

. 11.39. Parameter
Mapping
, , . , ( ), ,
Parameters, ,
, Input Global Variables, , , .
, Global Variables (. 11.40),

398

III.

Create Global Variables,


Parameter Mapping.

. 11.40. Global
Variables
Global Variables , . ,
. .
, ,
ActiveX Script Task Dynamic Properties Task.
Global Variables
Name , . , . ,
Transact-SQL. Value
,
. . ,
Value.
, Parameter
Mapping Input Global Variables
. , ,
.

11.

399

Source
Transform Data Task.
.


Transform Data Task Destination
(. 11.41) , , .

. 1 1 . 4 1 . Transform
Data Task Properties,
Destination

Connection ,

. , Source, Destination .
Table name, ,
.
,
, , Table
name. , ,
NULL, ( ). ,
, Source, , . , ,
. ,
14 3KIJ07

III.

400

smaiidatetime, , datetime. ,
, , i n t
char ().
, , , Transform Data Task . ,
, .
, , , Table name.
, .
Create Table name. Create Destination Table (. 11.42) CREATE
TABLE, .

Create Destination Table


. ,
, Cancel.
.

. 11.42. Create
Destination Table
, , ,
,
Source. , , , ,

. ,
, .

, CREATE TABLE 22.

401

11.

Destination,
, , .
.


Transform Data Task,
. , Transformations
(. 11.43) ,
. ,

. , ActiveX,
.

. 11.43. Transform
Data Task Properties,
Transformations
Name, , . SQL
Server 7.0 .
SQL Server 2000 Transform Data Task
. ,

, ,
, SQL Server 7.0.
14*

402

III.

Source, ,
,
Source. Destination ,
Destination .
- .

, . . , . .

(~

, Source Destination
. , Source Destination,
. . ,
.
, Source Destination Transformations.

DTSTransformationN, N .

.
. ,
,
. , .
,
. ,
, , ,
. .
Delete <Delete>.
, , , .
, , .
New. Source Destination , , .
New Create New Transformation (. 11.44),
. ,
DTS. Transfer Data Task
ActiveX Script Copy Column. Only show valid transformations

11.

403

. ,
.
Transformation
Options, . ,
. General
(. 11.45)
.
. 11.44. Create New Transformation

. 11.45. Transformation Options, General

Name , .
DTSTransformationN. ,

404

III.

, .
,
Create New Transformation. . ,
.
Sequence , . , ,
. Sequence
. , . ,

Sequence.
General . Source Columns (. 11.46) , .

. 11.46. Transformation Options, Source Columns

11.

40S

Source Columns :
Available columns. , ,
Source Transform Data Task Properties (. . 11.34).
Selected columns. ,
. , Source
Transformations (. . 11.43) New.

Selected columns. ,
, .
Transformation Options Destination Columns
(. 11.47) ,
.

. 11.47. Transformation Options, Destination Columns

406

III.

, Destination Columns
Source Columns. , Source Columns,
Destination Columns Available columns Selected columns.
,
Destination Transform Data
Task Properties (. . 11.41). Selected columns , .
Column, Selected columns
Source Columns Destination Columns Transformation Options
, . ActiveX Script
.
, , .
.

Properties
General Transformation Options
(. . 11.45). . 11.48 Column Order,
Copy Column.
Column Order
Columns,

. 11.48. Column Order

. Source
, Selected columns Source
Columns. Source ,
, Selected columns
Source Columns. . ,
.
, <ignore>.
, (
Destination) NULL, (
) .
. NULL, TO Source <ignore> .

11.

407

Destination ,
. Destination ,
, Selected columns
Destination Columns. Source,
Destination <ignore>. , Source, , .

. , Copy Column
. ActiveX Script. Properties
General Transformation Options (. . 11.45)
ActiveX Script Transformation Properties (. 11.49),
ActiveX,
.

. 11.49. ActiveX Script Transformation Properties

408

III.

, ActiveX Script Task


(. . 11.31), . ActiveX Script Transformation Properties, . .

ActiveX Script Task. ,
Browser (. 11.50) (Source Columns,
Destination Columns Lookups),
, , , (lookups).
Lookups
Transform Data Task,
.

. 11.50. ActiveX Script Transformation Properties, Browser


ActiveX Script Task ActiveX Script Transformation
Test, .
Testing Transformation (. 11.51),

11.

409

.
, .
.

. 11.51. Testing Transformation


, , . View Results Testing Transformation.
View Data (. 11.52), .

. 11.52. VieW Data

III.

, , . , ,
.

Transformations (. . 11.43), Test.
ActiveX Script, Copy Column.

. , Transform Data Task, Lookups* Options. ,
, .
. ,

.
Lookups Options.



Transform Data Task. ,
. , ActiveX Script , Source Destination.
, (lookup queries). , SELECT, UPDATE,

INSERT

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

ActiveX.
. ActiveX.
, ,
, ,
, . -

411

11.

Lookups (. 11.53)
Transform Data Task.

. 11.53. Transform
Data Task Properties,
Lookups
Lookups, . .
Add
. Name ,
. Connection , .
. ,
, Transform Data
Task, .

, ActiveX, ,
Source. , ,
Destination.
Cache ,
. .
0, , .

412

///.

, jgj, Query
, . 11.36. . " Query Builder" ,
. ,
SQL Pane, Diagram Pane Grid Pane.
,
. . " '
. , ?.
, ,
ActiveX
ActiveX Script. Browser ActiveX Script Transformation
Properties (. . 11.50) Lookups
, Lookups Transform Data
Task (. . 11.53).
ActiveX, f name
GenNewName, NumAuth:
DTSDestination("au_fname ") =
DTSLookups("GenNewName ").Execute(NumAuth)

ActiveX
Script Transformation Properties. , .
, , , , ,
DTSSource (). .
, , .
. , - DTS, .
, ActiveX
, ActiveX Script Task
DTS ,
.
, , Books Online MSDN.


,
Transform Data Task Properties, Options (. 11.54). -

413

11.

,
.

. 11.54. Transform
Data Task Properties,
Options
Exception file
, , . :
Name. , . Browse,
j, Name.
.
File type. . :

7.0 format SQL Server 7.0.


(parsers) , .
File type
.

Error text ,
, . , , -

414

III.

. , ,
.
Source error rows , , . .
, , .
,
Name, Source.
Dest error rows , , . ,
,
Dest, , . Copy Column Source Dest . ,
ActiveX Script,
.

(~

Source Dest
.
File format. , .
, Source Dest.
.

Row delimiter ( ),
.
{CR}{LF}. . (Semicolon), (Comma), (Tab), (Vertical Bar)
. (<>).

Column delimiter ,
. , .
(Vertical Bar).

Text qualifier ,

11.

415_

. <>, .
Double Quote {"}
Single Quote {'}, , , . , , .
, Exception file , . Data movement
. :
Max error count. ,
.
, , .
, ,
. .
0. , Max error
count,
(Failed). 0, .
Fetch buffer size. ,
. 1, .
First row.
. . , , , . , .
Last row. , . 0,
, First row .
SQL Server ,
SQL Server. , SQL Server,
. , :
Use fast load. .
OLE
DB Provider for SQL Server. , .
Keep NULL values.
, NULL -

416

III.

,
NULL. , NULL.
. NULL
.
NULL, NULL.
NULL ,
(NULL) .
Check constraints. , . ,
. , Check constraints.
,
, , . , DBCC (DataBase
Console Commands DataBase Consistency Check).
Table lock. , ,
. ,
. . ,
. ,
, ,
, .
Enable identity insert. ( IDENTITY) - , . , -
, , . , .

Enable identity insert.
.
Always commit final batch. , DTS
,
. ,
, . , ,

11.

417

.
Always commit final batch .
- Insert batch size. , . 0, ,
. , . , .
. ,
. 1. , . . ( Insert batch size
0) , 1 .
Options .
.
, .
Transform
Data Task.

Execute Process Task



Windows, , , MS Word MS Access. Execute Process Task , . . ,
, ,

. .
. ,
,
. , , - .
Execute Process Task ,
Transform Data Task.
(. 11.55) :
Description. ,
. .
Win32 process. , .

418

III.

(com, exe, bat),


. ,
Select File,
.

. 11.55. Execute
Process Task Properties
Parameters.
, .
Return code.
,
. , ,
, Execute
Process Task. 0 . , . ,
,
. ,
, , Execute Process Task .
Timeout. ,
. , ,
Execute Process Task .
( ) .
.
Terminate process after timeout.
Timeout . ,

11.

419

. , .
,
, . , SQL Server 2000.
,
.
, . , . .
.
Execute Process Task
.

Execute SQL Task


Execute SQL Task Transact-SQL,
, ,
, , , . . ,
.
, SELECT.
Execute SQL Task
(. 11.56) :
Description. , .
Existing connection.
, .

.
Command time-out. .
, ,
. , ,
. 0 ( )
. , .
SQL statement. , . ,
Query Builder.
, Browse , -

420

III.

. ,
. Query Builder,
, Build Query. , . 11.36. . " Query
Builder" . , SQL
statement. Parse Query.

. 11.56. Execute SQL


Task Properties
Execute SQL Task , .
. "
" . , :
EXEC GetListAuthors ?

, Parameter Mapping (. 11.57),


Parameters . ,
Input Parameters Output Parameters. , , , , .

421

11.

. 11.57. Parameter
Mapping
Input Parameters (. . 11.57)
. " " .
Output Parameters (. 11.58).

. 11.58. Parameter
Mapping, Output
Parameters

422

III.

, Output Parameters, . Output Parameter


, :
None.
. ,
,
.
.
Row Value.
, , .
Row Value Parameter Mapping, .
.
Parameters, ,
. , , Output Global Variables.
,
, .
, . <>.
.
Create Global Variables,
Global Variables, . 11.40.
.
Rowset. ,
. , , .
ADO (disconnected ADO recordset).
, , ADO. , ActiveX Script,
.
Transform Data Task.
Execute SQL Task
.
, .
DTS,
ActiveX.
.

11.

423

Data Driven Query Task


Transform
Data Task,
. . ,
Copy Column ActiveX Script.
, , .
DTS Data
Driven Query Task, . , Transform Data Task. , ,
,
.

Data Driven Query Task


. , .
, Transform Data Task.
Data Driven Query Task . ,
Transform Data Task
. Data Driven Query Task
Transform Data Task.
Queries .
Data Driven Query Task Source
(. 11.59). Source
Transfer Data Task (. . 11.34). , . Source Data Driven Query Task Properties
Transfer Data Task . " Transfer
Data Task" . , Bindings, Transformations,
Lookups Options Data Driven Query Task , , Destination, Transformations, Lookups
Options Transfer Data Task.
. " Transfer Data Task".
, , . ,
Transformations
:
ActiveX Script
VBScript JavaScript, -

424

III.

, PerlScript.
Transform Data Task .

. 11.59.
Data Driven
Query Task

G Copy Column .
Transform Data Task.
Date Time String
. : , , , , , .
Lowercase String
.
Middle of String
. , , .
CJ Read File .
Trim String , ,
, , ,
, (. . 0x09OxOd, 0x20).
Unicode .
Uppercase String .

11.

425


, . . .
Transformations Data
Driven Query Task Transform Data Task, , Options . . 11.60
Options Data Driven Query Task. ,
SQL Server, SQL Server.
Options Transform Data Task.

. 11.60. Data Driven


Query Task Properties,
Options

,
Data Driven Query Task. Queries (. 11.61),
.
Queries ,
.
, . ,
,
.

426

III.

. 1 1 . 6 1 . Data Driven
Query Task Properties,
Queries

Query
type, , . :
Insert ;
Update ;
Delete ;
Select .
, Query type,
. ,
.
Query Builder.
Build.
. " Query
Builder" . , .
. " " .
.
Destination to parameter mapping,

. ,

11.

427

Destination to parameter mapping .


Parameters ( ). Destination
, . ,
, . , , .
Parse/Show Parameters,

, Destination to parameter mapping.
Data Driven Query Task
.

Copy SQL Server Objects Task



, . .
. ,
, , . . " ". ,
, , ,
, . , , , , . .
, ,
Copy SQL Server Objects Task,
. SQL Server 2000 SQL
Server 7.0. , Copy SQL Server Objects Task SQL Server
7.0 2000. SQL Server
(6.5 6.0) Upgrade Wizard.
SQL Server . ,
(, SQL Server 4.1) SQL
Server 6.x, Upgrade Wizard . 6.
Copy SQL Server Objects Task . 11.62.
, . Source
,
. , ,
Destination. ,
Source Destination,
, , .

428

. 11.62. Copy SQL Server Objects Task Properties

. 11.63. Copy SQL Server Objects task Properties,


Copy

III.

11.

429

(. 11.63) , Select Object to Copy


DTS Import/Export Wizard (. . 11.20). ,
. " " . , DTS Import/Export Wizard
DTS, Copy SQL Server Objects Task.
, Copy SQL Server Objects Task
.

Send Mail Task


Send Mail Task .
, ,
SQLServerAgent ,
.
SQLServerAgent . " General" . " SQLServerAgent" 8. Send Mail Task . 11.64.

. 11.64. Send Mail Task Properties

Send Mail Task



. , ,
:

430

_ _ ^ _ _ _ _ _ _

III.

Description. , ,
, Send Mail Task .
Profile name. , MSSQLServer.
, ,
.
Password.
, .
. ,
(, ). ,
,
i, , .
. , (, ). , ,
.
Subject. . , . ,
. , .
Message. . Attachments. ,
. , .
,
, Bulk Insert Task.
Send Mail Task
. 11.64.

Bulk Insert Task



.
. , . .
,
, .
Bulk Insert Task, -

11.

431

, .
Unicode. . 11.65 Bulk Insert Task.

. 11.65. Bulk Insert


Task Properties
, . , General,
, . .
Description. ,
. .
Existing connection. , .
, .
Destination table. , , .
, ,
Refresh, . , .
, .
Source data file. ,
. , Browse For
Existing File, ,
15

1207

432

III.

. , Bulk Insert Task , .


Use format file.
, , . .
. Bulk Insert Task .
(format file). Use format file , . , ,
Generate. ,
.
Specify format. .
, .
:

Row delimiter
( ),
.
{LF}, {CR}.
{CR}{LF}.
(Semicolon),
(Comma), (Tab), (Vertical Bar)
.
(<>).

Column delimiter ,
. , .

(Tab).


.
28.
General . ,
, . . ,
Options , . , -

11.

433

, Options (. 11.66). ,
.

. 11.66. Bulk Insert


Task Properties, Options

Options :
Check constraints. , . ,
. , Check constraints.
,
, , . ,

DBCC.
Keep Nulls.
, NULL , NULL. , NULL.
. NULL
.
NULL, NULL.
15*

434

III.

NULL ,
(NULL) .
Enable identity insert. ( IDENTITY) - , . , - , , . ,
.
- Enable identity insert.
.
Table Lock. ,
,
. , .
.
. ,
, ,
, .
Sorted data. , , , .
, .
, .
Code page. ,
. ,
Unicode ( t e x t , varchar char),
, .
, 32
127.
. char,
varchar t e x t 32
127. :

OEM , ;

1252 (ANSI/Microsoft Windows ISO 1252);

RAW ""
(raw) . . . .

11.

435

Data file type. Bulk Insert Task


. Data file type
:

char .
,

;

native , (native).
,
SQL Server 2000.
. . .
. SQL Server;

widechar ,
Unicode.
\ t ,
\. widechar , .
, , SQL Server 6.x, . .
Unicode;

widenative native widechar.


, Unicode,
, SQL Server 2000.
.
SQL
Server 2000 SQL Server 7.0.
Insert commit size. , . , .
Bulk Insert Task . ,
,
. ,
.

(batch). .
.

436

III.

.
. Insert commit size
. . 0, .
Only copy selected rows. , , - .
, . , .
, .
. , ,
, :

First row
. . , .
,
;

Last row ,
. 0
, First row .

Bulk Insert Task .


bcp.exe (bulk copy program).
, . , bcp.exe , . , Bulk Insert Task Transact-SQL BULK INSERT,
.
bcp.exe, BULK INSERT
. " " 28.

Execute Package Task



, , .
.
. SQL Server 7.0 , . . . SQL Server 2000 Execute
Package Task, .

11.

437

Execute Package Task


, . , . ,
.
Execute Package Task .
General (. 11.67)
:
Description. , . .

. 11.67. Execute Package Task Properties,


General

Location. ,
. ,
, ,
. . 11.67 ,
SQL Server. SQL Server Meta Data Services. :

SQL Server
, .
sysdtspackages Msdb;

III.

438

SQL Server Meta Data Services


, SQL Server. , , , ,
;

Structured Storage File ( -) , .


Structured Storage File, Package name, .

Package name. DTS,


. ,
Location , . ,
Select
Package (. 11.68), , . Select
Package ^ 1 ,
Package name.

. 11.68. Select Package


Password. DTS Import/Export Wizard,
,
, . ,
, ,
Password. , , , Execute Package Task, .
Package ID. ,
,
Package name.

11.

439

Version. , . .
( ).
Server.
SQL Server,
.
Use Windows NT Authentication. , SQL Server Server, , .
DTS , , ,
Windows NT, Windows NT SQL
Server .
Use SQL Server Authentication. SQL Server. :

Username ,
Server .
;

Password , .

General .
Options (. 11.69),
.
Options
. Variables,
:
Name. ,
,
.
. . , . .
Value. ;
.
New. . ,
Delete.

440

III.

. , , a DTS Designer .

. 11.69. Execute Package Task Properties, Options

Execute Package Task .

Message Queue Task


Message Queue Task DTS , .
Message Queuing. . , ,
Message Queuing. , . , , ,
, .
Message Queue Task . 11.70.

441

11.

. 11.70. Message
Queue Task Properties

Message Queue Task Message Queuing Services. Windows NT 4.0


Microsoft Windows NT 4.0 Option Pack. Windows 2000
. ,
.

:

Description. ,
(),
. .
Message. Message Queue Task , , .
, .
, (Send
messages) (Receive messages). ,
, , . . 11.70 ,
Send messages. ,
Message to be sent.
Queue. ,
()
.

442

III.

_\_.
. . ,
Message Queue
Services, . , , .
,
, . ,
, .
, ,
Message to be sent (. . 11.70),
. Number ,
Message Type. Edit.
Delete. Message Queue Message Properties (. 11.71),
Add.

. 11.71. Message
Queue Message Properties
, . Message type, :
Data File Message .
File name,
. , , , .

443

11.

Global Variables Message .


Message Queue Message Properties , . 11.72. Global variables. .
Global variables .
New .
Name
, . Value
, , . (, ) Global Variables
(. . 11.40), Create Global
Variables. . " " .
String Message .
Message Queue Message Properties ,
. 11.71. , String
message, .

. 11.72. Message
Queue Message Properties

. .
Message Queue Task , Message
Queue Task Properties (. . 11.70) Message
Receive messages. Message Queue Task
Properties , . 11.73.

444

III.

. 11.73. Message
Queue Task Properties
, Message Queue Task : , . , . . Message type , . , , .
(Data File Message)
:
Save file as. , *
. , .
Overwrite. , ,
.
. , Save file as , .
.
Only receive message from a specific package or version.
. , , , . ,
,
. :

11.

445

No filter .
, , (
Queue);

From package Identifier, ,


. (CF94A366-13024 3 6 6 - A 0 3 7 - A 5 9 F A F F 6 D 4 0 0 } .
, .
^, Identifier.
. , ;

From version . - - . ,
. ,
, .
Message Queue Task (, ) . ,
, Identifier.
.

Identifier.
Only receive message from a specific package or version From
package From version. , Identifier
,
.
Remove from message queue.
Message Queue Services.
.
, , . . - .
Message Queue Task .
Time out after. Message Queue Task . ,
,
. , , -

446

III.

, . ,
.
1 9999 .
, .

("

. .

Message Queue Task .

Transfer Error Messages Task



(user-defined error messages).

, .
, , . , , .
SQL Server 7.0
- .
DTS SQL Server 2000
. Transfer Error Messages Task.
Transfer Error Messages Task .
Source (. 11.74) ,
.
, Source
Source server ,
. , .
, Transfer Error Messages Task
SQL Server 2000, SQL Server 7.0.
Destination ,
SQL Server,
Source. ,
Destination, Source.

11.

447

. 11.74. Transfer Error Messages, General

Error Messages (. 11.75),


, Error Message Copy Option,
:
All error messages detected at package runtime. , .
Selected error messages. (user-definer error messages). SQL Server 2000,
, , . . , , .
User-defined error messages,

Selected error messages. , ,
Source. Error . , , Destination.
( ) Select . , Clear All.

50 000.
s p a d d m e s s a g e .

III.

448

, , sysmessages
Master.

. 11.75. Transfer Error Messages, Error Messages


Severity (severity)
. Message.
LanguagelD , .
,
. Status
.

19 ,
, (system
administrator), 19 25, .
Transfer Error Messages Task .

Transfer Databases Task


Copy SQL
Server Objects Task,
SQL Server.
:
,
;

11.

449

- , , , ;
.
, Copy SQL Server Objects Task , -.
.
DTS Transfer Databases Task, , ,
Copy SQL Server Objects Task.
Copy SQL Server Objects Task .
Source Destination , , .
,
, Databases (. 11.76).

. 11.76. Transfer Databases, Databases

, Databases,

-. ( ),
-, .
Source:ServerName ,
Destination:ServerName .
. - ,
,
Databases Destination:ServerName Already exists,

450

III.

Move . System database, Move . , .


Copy SQL Server Objects Task , .
-.
, Move
,
. . Refresh, -.
, Copy SQL Server Objects Task .
- , , (attach)
, Copy SQL Server Objects Task
. File locations (. 11.77)
.
,
.
Files . :
Data files ( mdf ndf);
Log files - ( ldf).

. 11.77. Transfer Databases, File locations

11.

451

Destinations drives , . , Default data directory


( mdf ndf) Default log directory ( ldf)
Database Settings . Database
Settings . " Database Settings" 8,
Size ,
. , Destinations drives, Size,
Status . ,
.
, , , .
Refresh.

. Database
files (. 11.78), Modify.

. 11.78. Database files


Database files . ,
-

452

III.

, ,
.
Drive, , , Available Space Required
Space. Refresh.
, ,
.
, .
- .
Database ,
. , - , Source Files.
, -, . , , Destination. , ,
. , CDW (. 11.79), ,
Destination.

. 11.79. CDW
Size. Status
. , ,

11.

453

,
Source Files.
Database files .
File locations Transfer Database Task
Properties (. . 11.77). , Status File
locations , . .

Transfer Master Stored Procedures Task


(master server) .
Transfer Error Messages
Task. Transfer Master Stored Procedures Task (. 11.80)
. Source Destination
. Stored Procedures, .
,
Transfer Error Messages Task.

. 11.80. Transfer Master Stored Procedures

Transfer Jobs Task


Transfer Jobs Task SQLSen'eiAgent
SQL Server. , Transfer Jobs Task ,
. -

454

III.

Jobs (. 11.81), . .
.

. 1 1 . 8 1 . Transfer Jobs Task

Jobs Copy Option , :


All jobs detected at package runtime. , .
Selected jobs. .
, .
.
, -, .
Source, .
, , Transfer Jobs Task .

Transfer Logins Task


, , , , . , , - .
,

, .

11.

455

Transfer Database
Task ,
. ,
. (SID, security ID) . Transfer Database Task
. ,
, , . .
.
. ,
. .
Transfer
Logins Task. SQL Server 7.0
, .
Transfer Logins Task : Source, Destination Logins.
, Logins (. 11.82).

. 11.82. Transfer Logins Task

Logins
.
, ( Logins Copy Option server
logins detected at package runtime). , ,
Logins for selected
databases. .
,
-, . . , Source.

456

III.

, .
Select All Clear All , ,
.
, ,
Transfer Logins Task .

Dynamic Properties Task


, DTS , . , , , .
DTS Designer ,
. , . SQL Server 7.0
. SQL Server 2000

Dynamic Properties Task. . ,
,
.

. 11.83. Dynamic Properties Task

11.

457

, (. 11.83) . Description
, . .
Change list, ,
.
. (. .
), Add.
Dynamic Properties Task:Package Properties (. 11.84).

. 11.84. Dynamic Properties Task:Package Properties


Dynamic Properties Task:Package Properties ,
. ,
, , , . ,
.
. . :
Connections. , . Connections . , , .

III.

458
Tasks .

Steps , .
Global Variables ,
.

Dynamic Properties Task:Package Properties


, .
,
.
,
. , Property Name Default Value. ,
, . .
,
.

Set ( ). Add/Edit Assignment (. 11.85). , .

. 11.85. Add/Edit Assignment


INI-

459

11.

Source , .
, ,
Source information. :
INI File INI-
(. . 11.85). , INI- ( File), .
, (
Section) ( Key), . .
Preview , .
.
Refresh Preview.

. 11.86. Add/Edit

Assignment

Query. ,
. 11.86. Transact-SQL. Connection
, . .
Query. , , Browse. , Query
Builder . Parse,

460

III.

. , . .
.
, .
Preview , . .
Refresh , .
Global Variable. . Add/Edit Assignment , . 11.87.
- Variable, . Preview ,
.
.

. 11.87. Add/Edit
Assignment
Global Variable
Environment Variable. ,
, . , ,

( Win32) DTS. Execute Process Task, .
, DTS - .

461

11.

Source Environment Variable Add/Edit Assignment


, . 11.88.
Variable , . Preview .

, ,
SET, .
.

. 1 1 . 8 8 . Add/Edit
Assignment

Environment Variable

Constant. ,
, . Add/Edit Assignment
, . 11.89. Constant , .
,
Select Enumeration Value (. 11.90).
Select.
Data File. , . , . Add/Edit Assignment
, . 11.91. File
, .

462

III.

Preview.
, Refresh.

. 11.89. Add/Edit
Assignment
Constant

. 11.90. Select
Enumeration Value
Dynamic
Properties Task:Package Properties (. . 11.84). ,
, ,
Dynamic Properties Task . , . . ,
.

463

11.

. 11.91. Add/Edit
Assignment


, DTS. , ,
, . .
, DTS
. ,
, 13 . , , , . , Data Driven Query Task ,
,
. ,
. , :
1. Execute Process Task,
(bat).
.
2. Dynamic Properties Task, .
3. Data Driven Query Task, , .
16

*. 1207

464

III.

, . ,
.
. ,
TaskA TaskB ,
TaskA ,
TaskB. :
(Unconditional)
. TaskB , TaskA. , , .
(On Success).
TaskB ,
TaskA . , , TaskA ,
TaskB . , , , . .
.
(On Failure). ,
TaskB
TaskA. , , .
.
, . , , Workflow .
, Workflow.

, , ,
.
.
.
. On Completion
, On Success , On Failure .

465

11.

. , , (. 11.92).

. 11.92. Workflow
Properties


,
, . Save Package.
Save DTS Package (. .93),
. , Save DTS Package
, , . , (,
), Save as Package.
,
:
Package name. ,
. , .
16*

466

III.

. 11.93. Save
DTS Package

Owner password. . ,
, .
, .
User password. .
, . , .
Location. , . ,
Location,
. , SQL Server. ,
SQL Server Meta Data Services
. ^ :

SQL Server sysdtspackages Msdb;

SQL Server Meta Data Services SQL Server,


,, , , ,
;

Structured Storage File


-;

Visual Basic File Visual Basic.

11.

467

Server. SQL Server,


.
Use Windows NT authentication. Server Windows NT.
Use SQL Server Authentication. SQL Server.
(Username), , (Password)
.
Save DTS Package (. 11.93), ,
SQL Server SQL Server. -
Visual Basic Save DTS Package
. , , ,
, .

12

SQL Server 2000



(, Total Cost of Ownership).
, . , 1015%
. ,
.

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

. SQL Server 2000 , -.
, SQL Server 2000 ,
,
. ,
"" , SQL Server 2000,
, , SQL Server 2000 .

12. SQL Server 2000

469


Microsoft .
: MS Windows 2000,
Exchange Server 2000 . SQL
Server 2000.
, .
SQL Server 2000 . ,
, . SQL Server 2000 ,
,
.
SQL
Server 2000,
. SQL Server 6.x, , SQL Server 7.0, .
,
, . , SQL Server 2000,
,
.
SQL Server 2000
SQLServerAgent. SQL
Server 2000, . , SQLServerAgent
.
. ,
, .
SQL Server 2000 :
Jobs ;
Alerts ;
Operators .

, , Msdb,

470

III.

SQLServerAgent.
Msdb , .
? Enterprise Manager. ,
Management, SQLServerAgent.
[] ,
Alerts, Operators Jobs.
Enterprise Manager .

SQL Server 2000.

SQL Server 2000


, .
(jobs) ,
.
(steps).
, . SQL
Server 2000 ,
. .
Transact-SQL Scripts (TSQL).
Transact-SQL, . . .
SQLServerAgent MSSQLServer
.
Operating System Command (CmdExec).
Windows. cmd.exe Windows NT command.com, SQL Server 2000
Windows 95/98.
Replication. , . :

Replication Snapshot ,
;

Queue Reader ;
Replication Transaction-Log Reader ;
Replication Distributor ;
Replication Merge .

14.

12. SQL Server 2000

471_

ActiveX Script. ,
. SQL Server 2000 VBScript JavaScript. , , PerlScript.
SQL Server 2000 .
, ,
. SQL Server 2000
.
,
. SQL Server 2000
. ,
.
, .
,
? SQL Server 2000 (schedules), . ,
, SQLServerAgent
. ,
(manual start) .

SQL Server 2000 ,


,
. .

. . ,
. . ,

,
. ,
(deadlocks) .
SQL Server 2000, .
.
. , , , -

472

III.

, . ( , ) .
, SQL Server 2000, . .

, . ,
, . .
SQL Server 2000 "" , . (alerts).

, , , .

, (event).
, . SQL Server 2000 . , ,
, .
, ,
, .

10%. ,
,
.

SQL
Server 2000, . . , . SQL Server 2000 ,
SQL Server 2000. , Transact-SQL .

,
,
.
SQLServerAgent (application log).

12. SQL Server 2000

(~~

473

.
, . Event Viewer, Windows NT . ,
Start (), Programs () Administrative Tools ( ).

,
, SQL Server 2000
. :
SQL Server 2000. ,
.
SQL Server 2000. (severity level)
, .
Performance Monitor.
SQL Server 2000,
Performance Monitor.
, . SQL
Server 2000 - .
.
, - . . - ,
. .
, . :
000 Information;
001 Miscellaneous System Information;
002006 Reserved;
007 Notification: System Information;
008 Notification: User Intervention Required;
009 - User Defined;
010 Information;
011 Specified Database Object Not Fount;

012 - Unused;

013 User Transaction Syntax Error;


014 Insufficient Permission;
015 - Syntax Error In SQL Statements;
016 Miscellaneous User Error;

474

III.

017 Insufficient Resources;


018 NonFatal Internal Error Detected;
019 Fatal Error In Resource;
020 Fatal Error In Current Process;
021 Fatal Error In Database Process;
022 Fatal Error: Table Integrity Suspect;
023 Fatal Error: Database Integrity Suspect;
024 Fatal Error: Hardware Error;
025 - Fatal Error.

019 ,
, (system administrator), 019 025,
.
- ,
, s y s a l e r t s Msdb
. SQLServerAgent
s y s a l e r t s , .
,
.
SQL Server 2000 .
:
(Execute job).
.
Gob), .
, .
SQL Server 2000, . , , , . (truncation)
SQL Server 2000,
( ).
(Operators notify).
,
(operator) . ,
, .
:

12. SQL Server 2000

475

e-mail .
SQL Server;
pager ;
net send
NET SEND .

.
, .
. (Message forwarding).
SQL Server 2000.
, ,
SQL Server 2000 ,
.
. (application log) . ,
.
, SQL Server 2000 , . . .

.
. (operator) , . .

SQL Server 2000, , , .
. ,
.
. ,
. ,

III.

476

,
.
,
.

. SQL
Server 2000 ,
. Windows NT SQL Server 2000,
. , ,
. SQL Server 2000 , . , ,
, , .


SQL Server 2000
, .
.
Wizards (). , ,
. , . . , . SQL Server 2000 :
Create Alert Wizard ;

Create Job Wizard ;

Make Master Server Wizard


;

Make Target Server Wizard


.

, . , . ,
, .
Enterprise Manager. -

12. SQL Server 2000

477

: , ,
. Enterprise Manager , . Management, Enterprise Manager.
Transact-SQL. , Msdb.
, ,
. . SQL Server 2000
, .
(

Microsoft . , SQL Server 2000. Microsoft , ,


. , SQL Server 2000, .

.
. , .


SQL Server 2000.
Create
Job Wizard. ,
, . SQL Server 2000 Enterprise Manager. , . ,
s p a d d j o b , .

Create Job Wizard


Create Job Wizard.
. . . ,

478

III.

(schedule) .

Enterprise Manager.
Enterprise
Manager Run a wizard
Management Create Job Wizard.
.

.
(. 12.1) .

. 12.1. Create Job Wizard


:
Transact-SQL command Transact-SQL.
Operating-system shell command (for example, run a batch script or invoke an application) .
Active script (for example, VBScript or JavaScript) ,
(VBScript, JavaScript PerlScript).

, .

12. SQL Server 2000

479

, .
, , , . . 12.2
Transact-SQL command.

. 12.2. Create Job Wizard

Database name , SQLServerAgent .


()
.
.
Transact-SQL statement Transact-SQL,
. ,
Open. Parse
.
, .
(. 12.3) . :
Now. . .
One time. . (
On date) ( At time), . .

480

III.

Automatically when the SQL Server Agent starts.


SQLServerAgent.
When the computer is idle.
. ,
, , .
On a recurring basis.
.
. Schedule. Edit Recurring Job Schedule.

. 12.3. Create Job Wizard

(. 12.4) , .
:
Net send NET SEND;
E-mail .
.
Net send E-mail .
( ) .

12. SQL Server 2000

481

.
( Job name). ,
.

. 12.4. Create Job Wizard

Enterprise Manager
, Create
Job Wizard . . Enterprise Manager.
Enterprise Manager, Management, .
Management L+J SQLServer
Agent. : Jobs, Alerts Operator. Jobs, New Job.
New Job Properties, . 12.5.
.


General (. . 12.5), . , .

482

III.

Name , . .
Source , .
,
(local). Created .
, (Not yet created).
, Created
.

. 12.5. New Job Properties, General

General ,
:
Target local server ;
Target multiple servers .
, . Change.
General Category. . SQL Server 2000 :
Database Maintenance ;
Full-Text , ;
Jobs from MSX ;
REPL-Alert Response , ;

12. SQL Server 2000

483

REPL-Checkup , ;
REPL-Distribution , Distribution Agent;
REPL-Distribution Cleanup , ;
REPL-History Cleanup , ;
REPL-LogReader , LogReader Agent;
REPL-Merge , Merge Agent;
REPL-QueueReader , ;
REPL-Snapshot , Snapshot Agent;
REPL-Subscription Cleanup , ;
Web Assistant Web-;
[Uncategorized (Local)] , .

. ,
Jobs Enterprise Manager All Tasks, Manage Job
Categories. Job Categories, . 12.6.

. 12.6. Job Categories


, ,
. .
, , . ,
( , ,

484

III.

. Job Categories
( )
.
, :
Add. , .
Delete. .
Properties. , , . ,
. Show all jobs.
, .
. ,
Member.
, General (. . 12.5). Owner ,
(owner) . , .
Description .
.
Enabled,
. ,
. , . , .

Enabled .
, .
. , Enabled, .
General .


, Steps
(. 12.7), , .

12. SQL Server 2000

485

. 12.7. New Job Properties, Steps


. New, New
Job Step (. 12.8).

. 12.8. New Job Step, General


General Advanced.
. Step name ,
.
. . "-

III.

486

" . , General .
Transact-SQL Script (TSQL). Database
, . Command.
Transact-SQL, .
General Open, , .
Parse, .
,
.
, ,
Advanced (. 12.9).

. 12.9. New Job Step, Advanced


(advanced) . On success/failure flow
:
On success action. , .
,
:

Quit the job reporting success


;

Quit the job reporting failure ;

12. SQL Server 2000

487

Goto the next step , . ,


.
Retry attempts. , .
0,
.
Retry interval (minutes). Retry attempts
0, ,

.
On failure action. On success action
, .
On success action.
Transact-SQL Script (TSQL) command options , . :
Output file. , , Transact-SQL .
, .
,
, --|. Output file
, :

View ;
Overwrite ,
;

Append ,
, .
Append output to step history. ,
, . Msdb.
, , Msdb
.
Run as user. , ,
. (Self), . , .

488

III.

. Steps
New Job Properties (. . 12.7).
, , . :
ID .
1 .
Step Name . ,
.
. . ""
SQL Server 2000 .
On Success ,
.
On Failure ,
.
, :
Move step .
ID.
Start step , .
, ID 1,
. ,
, .
New .
Insert ,
( New),
.
Edit .
Delete , .
.


,
.
Schedules (. 12.10).
.
, New Schedule. New Job Schedule (. 12.11).

12. SQL Server 2000

489
|

. 12.10. New Job Properties, Schedules


New Job Schedule Name.
. .
Name Enabled, .
, , .
.

. 12.11. New Job Schedule


Schedule Type :
Start automatically when SQL Server Agent starts.
SQLServerAgent, , . -

490

III.

, .
Start whenever the CPU(s) become idle. .
, , . , , .
One time. .
, :
On date ;
On time .
Recurring.
. .
00:00.
Change. Edit Recurring Job Schedule
,
. , .

. 12.12. New Alert Properties, General

12. SQL Server 2000

491

. ,
.

. Schedule
New Job Properties (. . 12.10). , ,
.
. ,
, New Alert
Schedules. New Alert Properties (. 12.12).
.
Enterprise Manager .
. Schedules
New Job Properties.


New Job Properties Notifications
.
. 12.13.

. 12.13. New Job Properties, Notifications

, :

492

III.

E-mail operator. ,
. ^
. ,
, , :
When the job succeeds ;
When the job fails ;

Whenever the job completes , .

Page operator. ,
.
Net send operator. , NET SEND.
Write to Windows NT application event log. ,
.
Automatically delete job.
.

.
New Job Properties, , SQL Server 2000
.

Transact-SQL
Transact-SQL.
, . .
.
, SQL Server 2000 Msdb. , sysjobs. SELECT, UPDATE DELETE,

Enterprise Manager. . SELECT. , .


:
sp__configure

'allow

update',

{ 0 1 1 }

12. SQL Server 2000

493_

0 , 1 .
sys jobs
, .
. , , .
( Enterprise Manager)
,
. , ,
. :
sp_add_job ;
sp_update_job ;
sp_deiete_job ;
sp_add_jobscheduie ;
sp_add_jobstep ;
s p h e i p j o b ;
sp_heip_jobstep .
s p a d d j o b
:
sp_add_j ob [@ job_name =] 'j ob_name'
[,[Senabled =] enabled]
[,[@description =] 'description']
[,[@start_step_id =] step_id]
[,[@category_name =] 'category']
[,[@category_id =] category_id]
[,[@owner_login_name =] 'login']
[,[@notify_level_eventlog =] eventlog_leve1]
[,[@notify_level_email =] email_level]
[,[@notify_level_netsend =] netsend_level]
[,[@notify_level_page =] page_level]
[,[@notify_email_operator_name =] 'email_name']
[,[@notify_netsend_operator_name =] 'netsend_name']
[,[@notify_page_operator_name =] 'page_name']
[,[@delete_level =] delete_level]
[,[@job_id =] job id OUTPUT]


, , Books Online.

III.

494


,
, . SQL Server 2000 . , (script) , Transact-SQL, .
, .
,
. . .

DTS, Transfer Job Task. , , Transfer Job Task, .

, All Tasks,
Script Job. Generate SQL Script (. 12.14).

. 12.14. Generate
SQL Script
:
File name. , . , ^ J .
File format. ,
:

12. SQL Server 2000

495

MS-DOS Text (OEM) MS-DOS;

Windows Text (ANSI) Windows;

International Text (Unicode) Unicode.

Replace job if exists. , ,


.
, .
SQL Server 2000
.
.
(

.
, . , SQL Server 2000 .
Jobs All Tasks, Script All Jobs.


, SQL Server 2000.
,
Create Alert Wizard, Enterprise Manager .
. , Create Alert
Wizard , . , .
, ,
. .
.

Create Alert Wizard


Create Alert Wizard Enterprise Manager Run a Wizard Management Create Alert
Wizard. .
,
1 7 . 1207

496

III.

.
.
(. 12.15) ,
. :
Only if this error occurs. , .
Manage SQL
Server Messages, , _^|.
Error Description ,
.
For any error of severity.
.
, ,
.

. 12.15. Create Alert Wizard


,
:
d Database name. ,
, . , .
,
( Databases).

12. SQL Server 2000

497

Error message contains this text. ,


.
. .
,
. .
, (. 12.16), , . , , .
Job to execute
,
New Job. , No Job.

. 12.16. Create Alert Wizard

Create Alert Wizard (. 12.17) , .


, . . . , Alert
notification message to send to operator , .
E-mail, Page Net Send , .
. . Create Alert Wizard . .
17*

498

III.

. 12.17. Create Alert Wizard

Enterprise Manager
Enterprise Manager New
Alert Properties (. 12.18).
Alert New Alert.
Name , . :
SQL Server event alert. (application log) .
SQL Server performance condition alert. (counts) SQL Server.
Performance Monitor.
,
. .
Event alert definition
. :
Error number. , . ^ J ,
. ,
(user errors).

12. SQL Server 2000

499

. 12.18. New Alert


Properties, General
Severity. ,
(severity). .
Database name. , , . , ( All Databases).
Error message contains this text.
, ,
.
, .
, General
New Alert Properties SQL Server event alert.
. 12.18 SQL Server performance condition alert.
Performance condition alert definition SQL Server 2000, . :
Object. .
SQL Server 2000.

500

III.

Counter. , . .
Instance. ,
.
Value. , .
Alert if counter.
. . :

falls below ;

becomes equal to Value;

rises above Value.

. General New Alert Properties .


History,
:
Date last occurred.
.
Date last responded to. , .
Occurrence count.
.
Reset Count. (Occurrence count).
General . Response (. 12.19), , .
(Operators to notify), . New Operator.
(E-mail), (Pager) (Net Send).
. , , Additional
notification message to send. .

.

12. SQL Server 2000

501

. 12.19. New
Alert Properties,
Response

,
.
:
, NET SEND.
Include alert error text in. Delay between responses .
.

Transact-SQL
sysaierts Msdb.
Transact-SQL,
:
D s p a d d a i e r t ;
sp_update_aiert ;
sp_delete_aiert .
s p a d d a i e r t :
spi_add_alert [@name =] 'name'
[, [@message_id =] message_id]
t, [@severity =] severity]
[, [@enabled =] enabled]

502
[,
[,
[,
[,
[,
[,
[,
[,
[,

III.
[@delay_between_responses =] delay_between_responses]
[@notification_message =] 'notification_message']
[@include_event_description_in =] xnclude_event_description_in]
[@database_name =] 'database']
[@event_description_keyword =] 'event_description_keyword_pattern']
{ [@job_id =] job_id I [@job_name =] ' jobjiame ' } ]
[@raise_snmp_trap =] raise_snmp_trap]
[@performance_condition =] 'performance_condition' ]
[@category_name =] 'category']

,
, Books Online.


, , ,
. , . . " " .


, . SQL Server 2000 , Enterprise Manager Transact-SQL ( ).
. , Enterprise Manager Operators.
.
.
, .
, . , ,
.

Enterprise Manager
Enterprise Manager
New Operator Properties, ,
Operators Enterprise Manager New Operator. , . 12.20.

12. SQL Server 2000

503

. 12.20. New
Operator Properties,
General
,
. :
Name. , .
E-mail name. ,
. , - -. I.
. E-mail name.
Pager e-mail name. ,
, .
Net send address. ,
NET SEND.


Test.

( E-mail name) , . ,

504

III.

, , . .

, .

Pager on duty schedule.
.
8 6 .
,
, . SQL Server 2000 , .
General New Operator Properties
- Notifications (. 12.21).

. 12.21. New
Operator Properties,
Notifications
, . , .

, .

12. SQL Server 2000

505

Operator is available to receive notifications


. ,
. .
Send E-mail .

Transact-SQL
sysoperators
Msdb. ,
. , .
:
sp_add_operator ;
sp_deiete_operator ;
sp_update_operator
;
s p h e i p o p e r a t o r .
sp_add_operator:
sp_add_operator [gname =] 'name'
[, [@enabled =] enabled]
[, [@email_address =] 'email_address']
[, [@pager_address =] 'pager_address']
[, [@weekday_pager_start_time =] weekday_pager_start_time]
[, [@weekday_pager_end_time =] weekday_pager_end_time]
[, [@saturday_pager_start_time =] saturday_pager_start_time]
[, f@saturday__pager_end_time =] saturday_pager_end_time]
[, [@sunday_pager_start_time =] sunday_pager_start_time]
[, [@sunday_pager_end_time =] sunday_pager_end_time]
[, [@pager__days =] pager_days]
[, [@netsend_address =] 'netsend_address']
[, [@category_name =] 'category']

(v

sp_add_operator,
,
, Books Online.


SQL Server 2000 (fail-safe operator). -

506

III.

, ,
. , .
SQL Server 2000
, .
(, ), , (, ,
). ,
, Msdb ,
sysnotif i c a t i o n s , .
. Alert System SQL Server Agent Properties (. 12.22). SQLServerAgent Enterprise Manager Properties.

. 12.22. SQL Server


Agent Properties,
Alert System
Fail-safe operator, , Operator , .
No fail-safe operator, , .

12. SQL Server 2000

(~

507

SQL Server 2000 .


, ,
Operator No fail-safe operator.


,
.
. ,
, , ,
.
, : .
"" (script) Transact-SQL, . .
, .
Enterprise Manager. ,
. ,
Enterprise Manager Operators. , .
All Tasks, Script Operator.
Generate SQL Script,
, .
, Operators Enterprise Manager
All Tasks, Script All Operator.


.
, . ,
.
SQL Server 2000
. . ,

508

III.

, .
.
.
SQL Server 2000
(multiserver administration). , :
Master Server (MSX) ;
Target Server (TSX) ;
Multiserver Jobs ,
.

.


, .
(MSX,
Master SQL Executive Server). Windows NT. ,
, , . , , . ,
(domain controller). ,
, ,
.
, , , .

(multiserver jobs), , .
, SQL Server 2000 .
. SQL
Server 2000, (application log) Windows NT .


(forwarding events).
, SQL Server 2000
, -

12. SQL Server 2000

509

SQL Server 2000.


.
SQL Server 2000
Advanced SQL Server Agent Properties (. 12.23).
SQLServerAgem
Enterprise Manager Properties.

. 12.23. SQL
Server Agent Properties,
Advanced
SQL Server event forwarding. Forward events to a different
server . Server
,
. ,
, New Forwarding Server. Events , :
Unhandled events. , .
G All events. '
, , .
, If event has severity of or above
, ,

510

III.

.
, . , . . .

(MSXOperator).
. , .
.
Windows NT , . .
.
Make
Master Server Wizard ( Make MSX Wizard), , SQLServerAgent Enterprise
Manager Make This a Master,
Select Wizard, , Enterprise
Manager Run a Wizard.
,
. .
(. 12.24)
(MSXOperator).

. 12.24. Make MSX Wizard

12. SQL Server 2000

511

(E-mail address),
(Pager address) (Net
send address). , .
.
, .
,
. ____J
. Test,
. , (. 12.25).
, . (TSX, Target SQL Server Executive). , SQL Server 2000,
. ,
Register Server. Register
SQL Server Properties.
Properties.

. 12.25. Make MSX Wizard

512

III.


,
. ,
,
(TSX, Target SQL Server Executive).
.
, . . . , SQL Server 2000, Windows NT. , SQL
Server 2000 .
, , .

, , SQL Server 2000 ,


.
.
.
SQL Server 2000 Make Target Server Wizard ( Make TSX Wizard).
Select Wizard, .
Run a Wizard Enterprise
Manager. SQLServerAgent,
Make this a Target.

. (. 12.26) .
:
Master server (MSX). ,
. _j
Select Server,
.
Physical location of. .
.
. .
,
.

12. SQL Server 2000

513

. 12.26. Make TSX Wizard



, , .
(multiserver jobs). ,
.
.
, ,
.
, Jobs
New Job. New Job Properties (. 12.27).
, , ,
Target multiple servers.
,
. Change.
.
.

sysdownioadiist Msdb
,
.

III.

514

sysdownioadiist.
, .

. 12.27. New Job Properties

, sysdownioadiist . , . , ,
, .
. SQL
Server 2000 .
,
. ,
.
, .
, ,
.
,
.

(MSXOperator).
, .
. ,
SQL Server 2000,
Windows NT. , SQL Server 2000.

12. SQL Server 2000

515

Database Maintenance Plan Wizard


SQL Server 2000
,
. ,
SQL Server 2000, .
.
, , . , , .
(jobs) . ,
SQL Server 2000,
, Database Maintenance Plan Wizard.
Database Maintenance Plan Wizard
,
.
Enterprise Manager Management , Database Maintenance Plans. , Enterprise Manager , .
Database Maintenance Plan Wizard
Select Wizard, Run a Wizard Enterprise Manager, Database Maintenance Plans New Maintenance Plan.
.
(. 12.28) , .
,
. :
All databases , , .
All system databases (master, model, and msdb) .
All user databases (all databases other than master, model, and msdb)
.
These databases ,
, . -

516

III.

, .
, ,
.

. 12.28. Database Maintenance Plan Wizard

. 1 2 . 2 9 . Database Maintenance Plan Wizard

12. SQL Server 2000

517

,
(. 12.29).
. (fill factor) ,

. , , . . ,
. .
,
Reorganize
data and index pages. , :
Reorganize pages with the original amount of free space.
, (
).
Change free space per page percentage to.
, . 10%, . . 10 . (split page)
.

(statistics). (query optimizer) .
, .
Update
statistics used by query optimizer. ( )
, .

(7

Update statistics used by query optimizer , .



s p _ d b o p t i o n , a u t o c r e a t e s t a t i s t i c s .

. ,
. , SQL Server 2000
. ,
, .
.
.

518

III.

. . (shrink)
.
.
,
Remove unused space from database files Database Maintenance Plan
Wizard. :
When it grows beyond. , .
, , .
Amount of free space to remain after shrink.
,
. .
, Schedule,
.
(Occurs every
1 week(s) on Sunday, at 1:00:00).
Change.
. Database Maintenance Plan Wizard . (. 12.30) .

. 12.30. Database Maintenance Plan Wizard

12. SQL Server 2000

519


Check database integrity.
, :
Include indexes.
. .
Attempt to repair any minor problems. , . .
Exclude indexes. .
Perform these tests before doing backups.
, .
, .
,
.
, ,
.
Change. .
, (. 12.31),
.

. 1 2 . 3 1 . Database Maintenance Plan Wizard

520

_____

III.

,
,
. Back up the database as part of the
maintenance, plan. :
Verify the integrity of the backup on completion of the backup.
.
Location to store the backup file.
. :

. , ;

Disk . , .
Schedule,
. Change.
(. 12.32) ,
. Location to store the
backup file Disk, . , , .
Directory in which to store the backup file , :
Use the default backup directory.
\Mssql7\Backup.
Use this directory.
,
. .
. Create a subdirectory for each
database. ,
- . , , Remove
files older than. .
, , . (Minute(s)), (Hour(s)), (Day(s)),

12. SQL Server 2000

521

(Week(s)) (Month(s)). 4
.

. 12.32. Database Maintenance Plan Wizard


Backup file extension , . bak.

"pubs_tlog_
199803120206.bak", 199803120206 " " (time stamp),
.
.
(. 12.33)
.
Back up the transaction log as part of the
maintenance plan.
.
.
.
tm. , (. 12.34) -

522

III.

. 12.33. Database Maintenance Plan Wizard

. 12.34. Database Maintenance Plan Wizard

12. SQL Server 2000

523

.
Write report to a text file in directory . , .
, ,
.
Delete text report files older than , .
,
.
Send e-mail report to operator.
, .
, , .

. 12.35. Database Maintenance Plan Wizard


sysdbmaintplan_history Msdb.
(. 12.35)
Write history to the msdb.dbo.sysdbmaintplanjiistory table on this server. ,
Msdb .
, SQL Server 2000 . Limit rows in the
table to ,

524

III.

. 1000 .
,
, sysdbmaintpian_history . Write history to the
server. , . ,
Limit rows in the table to.
s y s d b m a i n t p l a n h i s t o r y 10 000 .
.
.
.

13


,
. . .
, . ,
,
. , , . , , , , . .
,
.
,
, .
, .
,
, -
. .
.
, , , , .
,
,
. ,
.
SQL Server 2000
:
;
;

526

III.

d ;
RAID.
. , RAID (Redundant Array of Independent Disks)

, . ,
, .

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

,
, RAID, . " RAID" 16.
.


(back up)
. RAID

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

13.

527

. ,
, . ,
.

("

SQL
Server 2000. - , . .
,
SQL Server 2000,
, Unicode,
. SQL Server 2000
.
,
.
, , , . SQL Server 2000
. ,
. - , .
SQL Server 2000 , . :
;
;
;
.
.

, SQL Server 2000 . , , , ARJ, RAR ZIP.


SQL Server 2000 10 .


(database backup) .
18

*. 1207

528

III.

, .
,
, , ZIP-.

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

.

, . ,
. .
,
, .
, . , , , , .
,
, SQL Server 2000 ,
.
, SQL Server 2000
.
-

13.

529

.
.

(~

SQL Server 2000


(truncate) . , .
BACKUP LOG
TRUNCATE_ONLY, .
Truncate log on
checkpoint. Enterprise Manager,
, sp_dfc>option.
, . :
;
;
, ;
(shrinking) .
, , .
, ,
.


, (differential database
backup) , . , . :
;
.
, . . ,
, . . 1 , , .
. 1

ARJ, RAR ZIP. .


18

530

III.

SQL Server 2000.


,
. ,

,
, . .
,
.

, SQL Server 2000


.

. ( )
, (
) .
- , . .


.
,
, . .
,
. .
, ,
. 8
,
. ,
, , . . . , . .
(transaction log backup). , -

13.

531

. , .
, , . SQL Server 2000 , .
,
, , .
, ,
. . ,

, .

. , 10 , 8 ,
. , ,
, .
, , . .
,
,
, , . t r u n c . log on
chkpt (Truncate transaction log on checkpoint). SQL
Server 2000
() .
(truncate). ,
, , .

. , .
.
SQL Server 2000 .

532

III.

. , , SQL Server 2000


. .
. ,
.

.

. ,
,
,
, . , SQL Server
.
, .
SQL Server 2000
,
. 99%
, .
.
.
, . ,
8
4 . , 2 ,
. .
. "" , , 2
. , .



SQL Server 2000.
,
.

13.

533

. , , ,
image, t e x t ntext. .
SQL Server 2000 .
.
. . , ,
. , image, text ntext, .
, . ,
,
. , , . ,
.

^)


(read only).
. , ,
.
. , . ,
, , . ,
. ,
, . , ,
, . ,
.
.
. .
.

534

III.

, . . . - .
"" ,
. .
.
. , SQL Server 2000 .
. ,
, ,
.
,
.
.
,
,
.
.



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

.
,
12 , .
:

13.

535

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

,
.
.



, .
, . .
, .

536

III.

, , .
.

:
. . , . , . .
.
, (3,5" 5,25") .
, .
,
. . SQL Server 2000 ,
. ,
SQL Server 2000, ,
. SQL Server 2000
, Windows NT Backup. ,
SQL Server 2000
Windows NT . SQL
Server 2000 .
, , .
.
(

SQL Server Upgrade Wizard


, Backup , , SQL Server 2000.
.
, , . .
. , , ZIP-, . DVD. . SQL
Server 2000 , , : , , , . .
, , , NTFS, ,
. ,

13.

537

SQL Server 2000, , . .


. .
, SQL Server 2000. ;
, ,
,
-
. , , , SQL
Server 2000,
, NTFS.

-uie
SQL Server 2000 ,
SQL Server 2000 (
). , .
. , . , SQL Server 2000 . (named pipes) ""
,
SQL Server 2000.
. SQL Server 2000
"" , . , ,
.
, . ,
. .
, . . SQL Server 2000

\Program
Files\Microsoft
SQL
Server\Mssql\Backup, \Program Files\Microsoft SQL Server\Mssql\Data. ,
, .
,
, .
, .

538

III.

, . , , , , .
(,
, ZIP-, DVD- . .),
, .
,
, , ,
,
. , , ,
.
.
,
, . ,
, , . , , .
. ,
.
.



, , , . ,
SQL Server 2000 .
Master Msdb. SQL Server 2000.
, .
(

,
( ),
, ( ).
,
Master, ,
SQL Server 2000, .
, ,
. . .
Master .

13.

539

Master
: ,
, SQL Server 2000 . .
Msdb
SQL Server 2000, SQLServerAgent. , .
Msdb , Master, , .
SQLServerAgent , Msdb
. Msdb , .

Master . . Msdb
, .
.
Model Tempdb.
. .
, . , . . Tempdb ,
SQL Server 2000. Tempdb.
,
.
.


,
, . Master , .
, Master SQL
Server 2000. ,
SQL Server 2000
, . .
, MSSQLServer , SQL Server 2000 -

540

III.

. ,
SQL Server 2000, . ,
.
Master , SQL Server 2000. SQL Server 2000 (singleuser mode), " . , , ,
MSSQLServer, .
. , SQL Server 2000
,
.

SQL Server 2000 s q l s e r v r . e x e -. ,


.
, Master. , .
, , , , .
.
Master SQL
Server 2000. ,
. . Master
.
: rebuildm.exe Master
.
rebuildm.exe Master,
SQL Server 2000 . Master
.
, . Master , SQL Server 2000. . rebuildm.exe ,
, -

13.

541

SQL Server 2000. , , , .


Master
. .
, .

Windows NT Backup. MSSQLServer.
, , .

.


Master , . ,
, .
SQL Server 2000 .
(attach)
sysdatabases Master . , , (primary file) .
, , . ,
.
,
Master , . , (detach) .
sysdatabases Master
, SQL Server 2000
. - , "" .

SQL
Server 2000, ,
, , .

SQL

542

III.

Server 2000. ,
, .

s p a t t a c h d b :
sp_attach_db [dbname =] 'dbname',
[Sfilenamel =] ' f i l e n a m e j i ' [,...16]

.
[gdbname =] 'dbname'
, .
,
, .

[Sfilenamel

=]

'filename_n'

[,...16]

. ,
, , (
mdf).
, ,
. . , 16 .

. ,
. SQL
Server 2000 . dbnamejog.ldf.

:
sp_detach_db [Sdbname =] 'dbname'
[, [Sskipchecks =] 'skipchecks']

sp_detach_db,

' dbname' , . 'skipchecks 1 ,


. NULL. TRUE, TO UPDATE STATISTICS . FALSE, TO
UPDATE STATISTICS .


Microsoft
, , ,
.

13.

543

, .
,
, . .
. , ,
, . ,
, . . , .
Microsoft
,
,
:
;
;
;
, .
, ,
.
.
,
, .


Transact-SQL
SQL Server 2000 ,
, :
Enterprise Manager
Backup Wizard
Transact-SQL

.
Database Maintenance Plan
Wizard. . " Database Maintenance Plan Wizard" 12.
Transact-SQL
BACKUP. -

544

III.

,
. , Enterprise Manager . , Transact-SQL.



.
. BACKUP,
:
BACKUP DATABASE {database_name I @database_name_var}
TO <backup_device> [ , . . . n ]
[WITH [BLOCKSIZE = { b l o c k s i z e I @ b l o c k s i z e _ v a r i a b l e } ]
[ [ , ] DESCRIPTION = { t e x t | @ t e x t _ v a r i a b l e } ]
[[,]
DIFFERENTIAL]
[ [ , ] EXPIREDATE = ( d a t e | 0date_var}
I RETAINDAYS = {days I @days_var}]
[ [ , ] FORMAT I NOFORMAT]
[ [ , ] {INIT | NOINIT}]
[ [ , ] MEDIADESCRIPTION = {text I @ t e x t _ v a r i a b l e } ]
[ [ , ] MEDIANAME = {media_name I @media_name_variable}]
[ [ , ] [NAME = {backup_set_name I @backup_set_name_var}]
[ [ , ] {NOSKIP I SKIP}]
[ [ , ] {NOUNLOAD | UNLOAD)]
[ [ , ] [RESTART]
[ [ , ] STATS [= p e r c e n t a g e ] ]
]

.
database_name I @database_name_var

, .
(databasename)
(@database_name_var).
, ntext t e x t .

<backup_device>

[,...n]

,
. :
<backup_device> : : =
{

{backup_device_name
I

|
,

@backup__device__name_var}
"

13.

545

{DISK I TAPE I PIPE) =


{'temp_backup_device'

I @temp_backup_device_var}

backup_device_name I @backup_device_name_var
, SQL Server 2000 sp_addumpdevice. , .
(, ZIP ), . ,
(temporary backup device).

.

,
,
. , .
, . . D I S K I TAPE I P I P E
.

'tempj3ackup_device'

@temp_backup_device_var. , , .

WITH FORMAT, , ,
, Microsoft Tape Format (MTF). . ,
Microsoft Tape Format, .

, SQL Server 2000


. (), .
. , , .

546

III.

d BLOCKSIZE = {blocksize I @blocksize_variable}


,
.
,
FORMAT. - , 2048 .
, .
65 536 . ,
BLOCKSIZE, .
DESCRIPTION = ( t e x t I @text_variable}
.
255 ,
. , ,
. .

DIFFERENTIAL

. ,
. ,

. DIFFERENTIAL ,
.
EXPIREDATE = {date | @date_var}
.
.
. (date), ,
(@date_var), smalldatetime datetime.
EXPIREDATE , .
RETAINDAYS = {days I @days_var}


, , . SQL Server 2000 . RETAINDAYS
INIT SKIP.

EXPIREDATE, RETAINDAYS, TO

, . -

13.

547

s p _ c o n f i g u r e
media r e t e n t i o n .
FORMAT

. .
.
. , .

NOFORMAT

, .
I N I T NOFORMAT .

INIT
, SQL Server 2000
. . , ,
EXPIREDATE RETAINDAYS.

, BACKUP SKIP.
NOINIT

, I N I T . TO .
MEDIADESCRIPTION = ( t e x t | @text_variable)

.
DESCRIPTION, -

, .
255

, t e x t ntext.
MEDIANAME = {media_name

@media_name_variable}

,
. , , .
128 .
NAME = {backup_set_name I @backup_set_name_var}
. 128 . , .

III.

548

SKIP

.-,..

, BACKUP. SKIP , .
NOSKIP

,
.

UNLOAD

.
UNLOAD, TO ,
. .

NOUNLOAD

.
RESTART
SQL Server 2000 . BACKUP , ,
RESTART. ,
.
STATS [= percentage]
( )
.
10% .

pubs.
pubs.bak:
BACKUP DATABASE pubs TO DISK = 'c:\pubs.bak'
:
Processed 176 pages for database ' p u b s ' , f i l e 'pubs' on f i l e 1.
1
Processed 1 pages for database ' p u b s ' , f i l e 'pubs_log' on f i l e 1.
BACKUP DATABASE s u c c e s s f u l l y processed 177 pages in 0.549 seconds (2.629
MB/sec).
, , ,
.

13.

549

.

. , , . sp_addumpdevice. :
sp_addumpdevice [@devtype =] 'device_type',
['Ologicalname =] ' logical_name',
[Sphysicalname =] 'physical_name'
[, { [@cntrltype =] controller_type
| [Sdevstatus =] 'device_status'
}}

,
:
EXEC sp_addurapdevice 'DISK',
'pubs_dev', 'C:\SQLBack\pubs_bak.dat'

pubsdev,
pubs_bak.dat, SQLBack :.

. :
BACKUP DATABASE pubs TO pubs_dev


,
BACKUP. :
BACKUP DATABASE {database_name I @database_name_var}
<file_or_filegroup> [,...n] TO <backup_device> [,...n]
[WITH [BLOCKSIZE = {blocksize I @blocksize_variable}]
[[,] DESCRIPTION = {text I @text_variable}]
[[,] EXPIREDATE = {date I @date_var)
I RETAINDAYS = {days I @days_var}]
[[,] FORMAT I NOFORMAT]
[[,] {INIT I NOINIT}]
[[,] MEDIADESCRIPTION = {text I @text_variable}]
[[,] MEDIANAME = {media_name I @media_name_variable}]
[[,] [NAME = {backup_set_name | @backup_set_name_var}]
[[,] {NOSKIP I SKIP}]
[[,] {NOUNLOAD | UNLOAD}]
[[,] [RESTART]
[[,] STATS [percentage]]
]

550 '

III.

,
.
< f i l e _ o r _ f i l e g r o u p > ,
, .
:
<file_or_filegroup> ::=
{

FILE = {logical_file_name | @logical_file_name_var}


I FILEGROUP = {logical_filegroup_name I @logical_filegroup_name_varj
}

.
FILE = {logical_file_name | 91ogical_file_name_var}

.
,
Transact-SQL, ,
. ,
.
d FILEGROUP = {logical_filegroup_name I @logical_filegroup_name_var}

,
, FILEG'ROUP .
, . SQL Server 2000 , . ,
. , ,
.



BACKUP :
BACKUP LOG {database_name I @database_name_var}
{[WITH
{NO_LOG | TRUNCATE_ONLY}]} | {TO <backup_device> [ , . . . n ]
[WITH [BLOCKSIZE = { b l o c k s i z e I @ b l o c k s i z e _ v a r i a b l e } ]
[ [ , ] DESCRIPTION = { t e x t I @text_va"r i a b l e } ]
[ [ , ] EXPIREDATE = { d a t e | @date_var}
I RETAINDAYS = {days I @days_var}]
[ [ , ] FORMAT I NOFORMAT]
[ [ , ] {INIT I NOINIT}]

. 13.

551

[ [ , ] MEDIADESCRIPTION = { t e x t I @ t e x t _ v a r i a b l e } ]
[ [ , ] MEDIANAME = {media_name I 8 m e d i a _ n a m e _ v a r i a b l e } ]
[ [ , ] [NAME = {backup_set_name I @backup_set_name_var} ]
[ [ , ] NO_TRUNCATE]
[ [ , ] (NOSKIP ] SKIP}]
[ [ , ] (NOUNLOAD I UNLOAD}]
[ [ , ] [RESTART]
[ [ , ] STATS [= p e r c e n t a g e ] ] ] }

, .
NO_LOG I TRUNCATE_ONLY

, .
. , . .
NO_TRUNCATE


NOTRUNCATE SQL Server 2000 .
, ,
(suspect) .
(has not been recovered) .


Enterprise Manager
Transact-SQL.
BACKUP
BACKUP. He
BACKUP. (
) * Enterprise Manager.
BACKUP,
Enterprise Manager .
Enterprise Manager
SQL Server Backup (. 13.1),
. ,
Enterprise Manager All Tasks, Backup Database. ,
Database .

552

III.

. 13.1. SQL Server


Backup pubs
, SQL Server Backup .
General
. Options . ,
General.
Database.
, .
, .
, SQL Server Backup.
Name. ,.
. . . .
Description. .
.
Backup.
, :

13.

Database - complete ;

Database - differential ;

553

Transaction log ;
File and filegroup
.
,
. Specify Filegroups and Files,
, . Specify Filegroups
Files ,
. Backup,

.

Backup to. ,
:


,
(), ZIP,
. , SQL Server 2000, , Backup to Disk;

Disk
.

, ,
, Backup
to. , . ,
Database.
SQL Server 2000 .
Select Backup Destination (. 13.2),
Add. File name .
BACKUP DISK =
'file_name'. To .
, .
Backup device, . (
sp_addumpdevice.)
.

III.

554

, , <New Backup Device>. Backup Device


Properties - New Device, .

. 13.2. Select Backup


Destination

View Contents, , .
Overwrite. ,
:
Append to media . , , ;

Overwrite existing media


. , . , , .

, Schedule. ,
SQL Server Backup (. .
), .
SQLServerAgent, .
, , , .

. ,
Schedule. .

13.

555

Edit Schedule (. 13.3), ^ J , Schedule.

. 13.3. Edit Schedule

Schedule type :
Start automatically when SQL Server Agent starts.
SQLServerAgent, , . , .
Start whenever the CPU(s) become idle. .
, , .
, ,
.
One time. .
, :
On date ;
At time .
Recurring.
. .
0:00:00.
Change. Edit Recurring Job Schedule

III.

556

,
. , .
,
, . , . Options
(. 13.4), . . , ,
. , , .

. 13.4. SQL Server


Backup, Options
:
Verify backup upon completion.
.
Eject tape after backup. ,
. .
.
Remove inactive entries from transactional log.
.
Check media set name and backup set expiration. ,
, -

13,

557

, . ,
. . , .
Media set name. ,
.
. .
Backup sell will expire. ,
.
:
After ,
;

On , .

, . , , . , . .
. , .
Initialize and label media. .

MTF (Microsoft Tape Format). ,
, . .
:

Media set name ,


MTF;

Media set description


, .

Options . . ,
, ,
.
Enterprise Manager , , & Backup,
Management .

558

III.



Enterprise Manager
. ,
, .

,

,
Create
Database Backup Wizard.
Select Wizard (. 13.5),

Run a wizard, Enterprise Manager. Select Wizard
Management Backup Wizard.
,
.

. 13.5. Select Wizard

,
.
.
Next.

Select Database to Backup,


" ".
Database,
, .
.
Database ,
. , .
Type Name and Description for Backup (. 13.6),
" ". :
Name. , .
Description.
.

13.

559

. 13.6. Type Name and Description for Backup

Create Database Backup Wteard

,
. Name , , databasename
backup. , ,
.
Select Type of Backup (. 13.7) ,
, .
, :
Database backup - backup the entire database
;
Differential database - backup only new and changed data ;
G Transactional log - backup the record of all the changes made to the database
.

, Master Msdb . , Master , Msdb


.

560

111.

. 13.7. Select Type of Backup Create Database Backup Wizard

. 13.8. Select Backup Destination and Action


Create Database Backup Wizard

. Select Backup Destination and Action (. 13.8),


" ".

13.

5?1

, ,
. , .
, , ,
. Select backup device , , :
. .
, , .

, .
File.
.
, .
Backup device. .
sp_addumpdevice
Backup Device Properties - New Device.

. ,
Backup Device Properties - New Device.
Properties, , :
Append to the backup media. .
, , .
Overwrite the backup media.
. , . ,
, .
Eject tape after backup.
, . . .
Read and verify the integrity of the backup after backup. .
Backup Verification and Scheduling
(. 13.9) , *
,
.
Check media set name and backup set expiration date,
,
19*

562

III.

.
,
. . , , Media set
name. .

. 13.9. Backup Verification and Scheduling


Create Database Backup Wizard

, , .

-
, . .
. , Backup set will expire .
, After ( ), On ( ).
, Schedule,
.
. , -

13.

563

, . " Database Maintenance Plan Wizard" 12.



, .
,
. .
, - , , Back.


Transact-SQL
SQL Server 2000 :
Enterprise Manager;
Transact-SQL.

, SQL Server 2000, Windows NT Backup .


.
Transact-SQL RESTORE. .


RESTORE :
RESTORE DATABASE {database_name I @database_name_var}
[FROM <backup_device> [ , . . . n ] ]
[WITH [DBO_ONLY]
[ [ , ] FILE = file_number]
[ [ , ] MEDIANAME = {media_name I @media_name_variable}]
[ [ , ] MOVE ' l o g i c a l _ f i l e _ n a m e ' TO l o p e r a t i n g _ s y s t e m _ f i l e _ n a m e 1 ]
[,...n]
[ [ , ] {NORECOVERY I RECOVERY I STANDBY = undo_file_narae}]
[ [ , ] {NOUNLOAD I UNLOAD}]
[ [ , ] REPLACE]
[ [ , ] RESTART]
[ [ , ] STATS [= p e r c e n t a g e ] ]
]

III.

564

DATABASE {database_name |

@database_name_var}

DATABASE , ,
.
DATABASE . (database name)
( @ d a t a b a s e _ n a m e _ v a r ) .

FROM

<backup_device>

[,...n]

FROM , .
backupdevice,
. " " . . FROM , (recovery) . NORECOVERY, RECOVERY STANDBY.

DBO_ONLY

(DBO, database owner).



sp_dboption dbo use only.
FILE = file_number

(backup set) . .
MEDIANAME = tmedia_name i @media__name_variable)

, .
d MOVE 'logical_file_name' 'operating_system_file__name'

, , .
, .

NORECOVERY


. , . NORECOVERY ,
RECOVERY NORECOVERY.
RECOVERY

RESTORE RECOVERY, TO
. ,
.

13.

STANDBY = u n d o _ f i l e _ n a m e

565
;

(undo file), ,
. STANDBY,
. STANDBY
(standby server), , . ,
SQL Server 2000 . ,
. .

RECOVERY, NORECOVERY STANDBY, TO


RECOVERY.

UNLOAD

NOUNLOAD

, .

REPLACE

. ,
,
, , .

RESTART

, , , . .
STATS [= percentage]

( ) . 10% .



RESTORE :

566

III.

RESTORE DATABASE {database_name I Gdatabase_name_var}


<file_or_filegroup> [,...n]
[FROM <backup_device> [ , . . . n ] ]
[WITH
[DBO_ONLY]
[ [ , ] FILE = f i l e _ n u m b e r ]
[ [ , ] MEDIANAME = {media_name I @media_name_variable)]
[ [ , ] NORECOVERY]
[ [ , ] {NOUNLOAD I UNLOAD}]
[ [ , ] REPLACE]
[ [ , ] RESTART]
[ [ , ] STATS [= p e r c e n t a g e ] ]
]

, RESTORE ,
<file_or_filegroup>
[, .. . ] . ,
.
. "
" .



RESTORE :
RESTORE LOG (database_name I @database_name_var)
[FROM <backup_device> [ , . . . n ] ]
[WITH
[DBO_ONLY]
[ [ , ] FILE = f i l e _ n u m b e r ]
[ [ , ] MEDIANAME = {media_name I @media_name_variable}]
[ [ , ] {NORECOVERY I RECOVERY | STANDBY = undo_file_name} ]
[ [ , ] {NOUNLOAD | UNLOAD}]
[ [ , ] RESTART]
[[,] STATS [= percentage]]
[[,] STOPAT = {date_time I @date_time_var}]
]

RESTORE
.
.
DATABASE LOG,
, .
STOPAT = ( d a t e t i m e | S d a t e t i m e v a r }
, .
, datetime. smaiidatetime.
,
datetime smaiidatetime.

13,

567


, , . SQL Server 2000
, .
, ,
.


Enterprise Manager
, Transact-SQL . RESTORE. ,
Transact-SQL . , , , .
, Transact-SQL,
Enterprise Manager.
,
, , .
Enterprise Manager
Restore database (. 13.10). Tools Restore Database,
- All Tasks, Restore Database.
, Restore database .
General
. Options . ,
General (. 13.10):
Restore as database.
,
. ,
.
, . .

,
, ,

III.

568

. ,
, ,
. , ,
, .

. 13.10. Restore database


Restore. . ,
, Parameters.
(. . 13.10)
Database.
:

Database ,
;

Filegroups or files
;

From device ,
.
Show backups of database. .

13.

569

, Parameters,
. , , , , .
First backup to restore.
, .
, . ,

.
, .
Point in time restore. , . ,
,
. ,
.
,
, , Show backups of
database, , First
backup to restore. :
Restore. , ,
. .
, .
1. , ,
. ,
.
, ( ).
Backup Set Date.
.
Size. , .
Restore From. , . , .
.
Backup Set Name. ,
, .
Properties ,
, , Restore From.

570

III.

, ,
, , .
, General
Restore database, Restore
Database. ,
Parameters
.
Options (. 13.11), .
:
Eject tapes (if any) after restoring each backup. .
Prompt before restoring each backup. .
Force restore over existing database.
.
Restore database files as.
. :

Original File Name , ;


Restore As , . , .
.

Recovery completion state. , . :

Leave database operational. No additional transaction logs can be restored



.
;

Leave database nonoperational but able to restore additional transactional


logs ,
. ;

Leave database read-only and able to restore additional transactional logs


, . , . , " ". Undo file

13.

571

. , .
Options,
Enterprise Manager, .

. 1 3 . 1 1 . Restore database, Options

14



. , , , .
. .

, .
SQL Server 2000,
. ,
.
, .
.
, . , , ,
.
, ,
,
.

,
.
.
.

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

14.

573

.
. .
.
,
.
:
. .
, ,
. , , - .
.
.
,
, .
.
SQL Server 2000 ,
.

DTS . ,
, : , .
SQL Server 2000
(replication). SQL
Server 2000
ODBC OLE DB. ( ), , SQL Server 2000
, .
SQL Server 2000 Replication Distribution Interface.
SQL Server 2000, SQL Server 7.0 SQL Server 6.x,
, Microsoft Access, Oracle, dBase,
Paradox MS Excel.

.

574

III.

,
DTS. , .
SQL Server 2000.


SQL Server 2000,
, , . ,
. -
.
SQL
Server 2000 .
SQL
Server 7.0. , .
,
.
2 , .
,
, .
SQL Server 2000 . , (queue updating).

.
SQL Server 2000 , . ,
, .
, LAN, WAN .

SQL Server 6.0. ^ "
" Publish and Subscribe, SQL Server 6.0. Publisher,
Distributor Subscription.

14.

(~

575

, ,
SQL Server 2000. . , , .

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

.


SQL Server 2000 ( ), . , SQL Server 2000.

,
:
(Publication). .
. , .
,
.
(Article). , .
- . , , :
Using a vertical filter ( ), ;
Using a horizontal filter ( ),
, ,
WHERE.

, SQL Server 6.x . SQL Server 2000 ,


, SQL

576

III.
Server 6.x SQL Server 2000 , . , SQL Server 7.0,
SQL Server 2000 .
, . Microsoft ,
.

(publisher) SQL Server 2000 , ()


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

- , , , , .

, , , ,
, , .
, .
, , . (Snapshot Replication). .
. ,
.

(subscriber) , .
.
. ,

577

14.

,
.

SQL Server 2000 , Microsoft Jet Database, ODBC


OLE DB.
, , . SQL Server 7.0
SQL Server 2000.
, . , .
, , .
.
,
. ,
, , , .
. SQL Server 2000 - , . .
. SQL Server 2000
:
(Merge Replication). . .

. ,
,
.
D (Immediate Updating Subscribers).
. , . ,
. ,
.
(Queue Updating). ,
,
. , .
,
.

578

III.

, , .
,
. , . SQL Server 2000. ,
? SQL Server 2000 :
(Push Subscription). . ,
. ,
. ,
.
, . . ,
.
(Pull subscription). , -, .
, , .
, .

, .

. ,
-. ,
,
. . , ,
.

, SQL Server 2000


, . ,
,
.

14.

579

(distributor) ,
.
, .

.
, , .
, . .

, .
,
. , ,
, , .
(distribution
database), .
D i s t r i b u t i o n . ,
. ,
, , , . , .
.

, . , .
, .

. , , .
.
, . SQL Server 2000
, . -

580

III.

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

, ,
.
, .


, SQL Server 2000 ,
SQL Server 2000.
SQL
Server 2000. , , , , . .
. .
SQL Server 2000:

Snapshot Agent

Log Reader Agent


Queue Reader Agent
Distribution Agent
Merge Agent
. SQL Server 2000
. ,
. \Program Files\Microsoft SQL
Server\80\COM. , , , .

14.

56?

,
, "" . ,
. ,
D i s t r i b u t i o n , .
, , . :
Agent History Clean Up: Distribution 10 . ,
48 .
Distribution Clean Up: Distribution 10
,
.
Expired Subscription Clean Up , .
Reinitialize Subscriptions Having Data Validation Failures ,
. ,
.
Replication Agents Checkup ,
. 10 .
, ,
,
"" . .
. SQLServerAgent
, .


SQL Server 2000. , SQL Server 2000 . , . SQL Server 2000 ,
. D i s t r i b u t i o n , Enterprise Manager
Replication Monitor.
.

582

III.

Snapshot Agent
Snapshot Agent
(snapshot file). , ,
. .
. , . Snapshot Agent . , (),
,
. . Snapshot Agent
(script file), .
. Snapshot Agent
. Snapshot
Agent .
.

SQL Server 2000 Snapshot Agent.

Snapshot Agent snapshot.exe,


:
snapshot -Publisher <..>
-PublisherDB <..>
-Publication <..>
[-ReplicationType <1|2>]
[-Distributor <..>]
[-DistributorSecurityMode <0|l>]
[-DistributorLogin <..>]
[-DistributorPassword <..>]
[-PublisherSecurityMode <0|l>]
[-PublisherLogin <..>]
[-PublisherPassword <..>]
[-MaxBcpThreads <..>]
[-BcpBatchSize <..>]
[-HistoryVerboseLevel <0|l|2|3>]
[-RowDelimiter <..>]
[-FieldDelimiter <..>]
[-70Subscribers]
[-ProfileName]
[-DynamicFilterLogin <..>]
[-DynamicFilterHostName <..>]
[-DynamicSnapshotLocation <..>]
[-Continuous]

14.

583

[-Output <..>]
[-OutputVerboseLevel <0|l|2>]
[-LoginTimeout <..>]
[-QueryTimeout <..>]
[-DefinitionFile <..>]


snapshot.exe, . . . . " " . , Snapshot Agent
. , snapshot.exe, . ,
SQLServerAgent,
. SQL Server, , ,
. . -
Schedules , .

Log Reader Agent


Log Reader Agent (Transactional
Replication), .
, . Distribution. Dist r i b u t i o n .

Snapshot Agent, Log Reader Agent.


Log Reader Agent logread.exe,
:
logread - P u b l i s h e r <..>
-PublisherDB <..>
[-KeepAliveMessagelnterval <..>]
[-PublisherSecurityMode < 0 | l > ]
[-PublisherLogin <..>]
[-PublisherPassword <..>]
[ - D i s t r i b u t o r <..>]
[-DistributorSecurityMode < 0 | l > ]
[-DistributorLogin <..>]
[-DistributorPassword <..>]
[-Buffers <..>]
[-SyncLogging]

584

III.

[-HistoryVerboseLevel <0|l|2>]
[-PacketSize <..>]
[-ReadBatchSize <..>]
[-ReadBatchThreshold <..>]
[-Pollinglnterval <>]
[-Messagelnterval <.->]
[-Continuous]
[-Output <..>]
[-OutputVerboseLevel <0|l|2>]
[-LoginTimeout <. . > ]
[-QueryTimeout <. . > ]
[-DefinitionFile <..>]

Queue Reader Agent


, SQL
Server 2000 ,
(Queue Updating).

(queue).
- ,
.

. , . Queue Reader Agent.
Queue Reader Agent .
.
, . ,
,
.
Queue Reader Agent qrdrsvc.exe, :
Qrdrsvc
[-Distributor <local-machine-name>]
[-DistributionDB <distribution_database>]
[-DistributorLogin <distributor_login>]
[-DistributorPassword <distributor_password>]
[-DistributorSecurityMode <0-l>]
[-ResolverState <l-3>]
[-HistoryVerboseLevel <0-3>]
[-Pollinglnterval <0-240 seconds>]
[-Continuous]
[-Output <..>]
[-OutputVerboseLevel <0|l|2>]

14.

585

[-LoginTimeout <..>]
[-QueryTimeout <..>]
[-DefinitionFile <..>]

Distribution Agent
Distribution Agent ,
Snapshot Agent Log Reader Agent. Distribution Agent

D i s t r i b u t i o n .

, Distribution Agent. Distribution Agent.
Distribution Agent .
(pull replication) .
(push replication),
.
Distribution Agent distrib.exe, :
distrib -Publisher <..> -PublisherDB <..>
[-Publication <..>]
[-SubscriptionType <0-2>]
[-SubscriberDB <-..>]
[-SubscnberSecurityMode <0 I 1>]
[-SubscriberLogin <..>}
[-SubscriberPassword <-.>]
[-SubscriberType <0-2>l
[-SubscriberDatabasePath <.. >j
[-Distributor <. . >]
[-DistributorSecurityMode <0I 1>]
[-DistributorLogin <..>]
[-DistributorPassword <..>]
[-DistributorNetwork <..>]
[-DistributorAddress <..>)
[-FileTransferType <0|l>]
[-FtpAddress <..>J
[-FtpPort <..>]
[-FtpOserName <..>]
[-FtpPassword <..>]
[-TransactionsPerHistory <..>]
[-CommitBatchSize <..>]
[-CommitBatchThreshold <..>.]
[-MaxDeliveredTransactions <..>]
[-BcpBatchSize <..>]
[-SubscriptionTableName <..>]
[-ErrorFile <..>]
[-MaxBcpThreads <..>]

-Subscriber <..>

586

III.

[-UselnprocLoader]
[-NoTextInitOnSync]
[-Buffers]
[-Quotedldentifier <..>]
[-HistoryVerboseLevel
<O|1|2I3>]
[-ProfileName <..>]
[-KeepAliveMessagelnterval <..>]
-AltSnapshotFolder <..>]
-SkipErrors]
L
[-Hostname]
[-OseDTS]
[-PacketSize <..>]
[-Pollinglnterval <..>]
[-Messagelnterval <..>]
[-Continuous]
[-Output <..>]
[-OutputVerboseLevel
<0ll|2>]
[-LoginTimeout <..>]
[-QueryTimeout <..>]
[-DefinitionFile <..>]

Merge Agent
Merge Agent (merge replication). ,
SQL Server 7.0. .
, .
, . , .

.
Merge Agent ,
. , ,
.
Merge Agent.
. ,
.
, Merge Agent ,
. D i s t r i b u t i o n .

( ), . , "
", .

14.

587

. , ,
, .

,
,
, .
, , Merge Agent. , Merge Agent ,
.
Merge Agent , .
,

.
Merge Agent replmerg.exe, :
replmerg -PublisherDB <..> -Subscriber <..>
-SubscriberDB <..> -Publication <..>
[-Hostname <..>]
[-Pollinglnterval <in seconds>]
[-Validatelnterval <in minutes>]
[-SubscriptionType <0|l|2>]
[-SubscriberConflictClean <0|l>]
[-PublisherSecurityMode <0|l>]
[-PublisherLogin <..>]
[-PublisherPassword <..>]
[-SubscriberSecurityMode <0|l>]
[-SubscriberLogin <..>]
[(-SubscriberPassword I -SubscriberEncryptedPassword) <..>]
[-SubscriberType <01112 I 31 4 I 5 I 61718>]
[-Validate <0|l|2|3>]
[-FastRowCount <0|l>]
[-HistoryVerboseLevel <0|l|2|3>]
[-ProfileName <..>]
[-MaxBcpThreads <..>]
[-UselnprocLoader]
[-interactiveResolution <0|l>]
[-KeepAliveMessagelnterval <..>]
[-SrcThreads <..>]
[-DestThreads <..>]
[-ForceConvergenceLevel <0|l>]
[-InputMessageFile <..>J
[-InputMessageFromPublisher <0|1>]
[-OutputMessageFile <..>]
[(-Distributor <..>)
I (-DistributorNetwork <..> -DistributorAddress <..>])
[-DistributorSecurityMode <0|l>]
[-DistributorLogin <..>]

588

III.

[(-DistributorPassword I -DistributorEncryptedPassword) <..>]


[-MaxDownloadChanges <..>]
[-MaxUploadChanges <..>]
[-UploadGenerationsPerBatch <..>]
[-DownloadGenerationsPerBatch <..>]
[-UploadReadChangesPerBatch <..>]
[-DownloadReadChangesPerBatch <..>]
[-UploadWriteChangesPerBatch <..>]
[-DownloadWriteChangesPerBatch <..>]
[-SubscriberDBAddOption 0|l1213]
[-SubscriberDatabasePath <..>]
[-FileTransferType <0|l>]
[-FtpAddress <..>]
[-FtpPort <..>]
[-FtpUserName <..>]
[-FtpPassword <..>]
[-ExchangeType <1|2|3>]
[-AltSnapshotFolder <..>]
[-SyncToAlternate <0|l>]
[-DynamicSnapshotLocation <..>]
[-Continuous]
[-Output <..>]
[-OutputVerboseLevel <0|l|2>]
[-LoginTimeout <..>]
[-QueryTimeout <..>]
[-DefinitionFile <..>]


SQLServerAgent.
, ,
, SQLServerAgent. , SQLServerAgent , MSSQLServer.
, SQLServerAgent .
. , Windows NT. SQL Server, , SQLServerAgent.
Management\SQL Server Agent\Jobs
(. 14.1) , , , , REPL.
.
, .
. 14.2 STORAGE-pubs-1, Log Reader Agent.

14.

589

**^****^-*?

. 1 4 . 1 . Management's SQL Server AgentXJobs

. 14.2. General

Genera] ,
REPL-LogReader. ,

14.

591

Agent.
. , ,
.

. 14.4. , General
Advanced (. 14.5), , . ,
.

. 14.5. , Advanced
20

592

III.

(. 14.6). Replication Transaction-Log Reader. , logread.exe,


Log Reader Agent. , Command,
,
, .
logread.exe
Log Reader Agent.

. 1 4 . 6 . , G e n e r a l

Advanced (. 14.7) ,
logread.exe ( On success action)
( Quit the job reporting success).
( On failure action) ( Goto the next
step). 10 ( Retry attempts)
( Retry interval (minutes)).
(. 14.8), ,
, 10;
logread.exe. ,
Transact-SQL Script (TSQL) sp_MSdetect_nonlogged_shutdown, Log Reader Agent.
Advanced (. 14.9) ,
.

14.

593

. 14.7. , Advanced

. 14.8. , General
, Log Reader
Agent, . ,
.
. , ,
.
20*

594

III.

. 14.9. , Advanced

. 1 4 . 1 0 . S c h e d u l e s

Log Reader Agent.


Schedules (. 14.10). , . Description . ,
SQLServerAgent (Start automatically when SQL Server Agent Starts).
, logread.exe, . ,

14.

595

, . (Task Manager) Processes (. 14.11),


, logread.exe .
, .

. 14.11. Processes

<Ctrl>+<Shift>+
+<Esc>, Task Manager.
<Ctrl>+<Alt>+<Del> Task Manager.
, Windows NT 4.0 Windows 2000.

. 14.11 , Distributor Agent (distrib.exe) Queue Reader Agent (qrdrsvc.exe). Merge


Agent (replmerg.exe) , . . . Snapshot Agent ,
. 23:33.
, Log Reader Agent,
. Notifications

596

III,

. , - ,
.
Log Reader Agent
. , .


.
. SQL Server 2000 ^
.
SQL Server 2000 :
Snapshot Replication ;
Transactional Replication ;
Merge Replication .
.
,
, .
""
. , . :
Immediately-Update Subscribers ;
Queue Updating .

, SQL
Server 2000 SQL Server 7.0.

, ,
, . , -;
. ,
.
.

14.

597


(Snapshot Replication). , . (snapshot).
.
.
. (snapshot
file), .
. ,
, . .
. ,
.
, . .
,
. . .
. , , , .
. ,
. . ,
, ,
,
.
" "
(DSS, Decision Support Systems). , . ,
, " ". .

598

III.

,
, .
, ,
.

,
. ,
, .
, .
, . . 14.12
.

. 14.12.

, Snapshot Agent Distribution Agent. . ,


.
Snapshot Agent , . ,
.

14.

599

(snapshot files). , :
1. Snapshot Agent . . , ,
(share-lock). ,
. . ,
. .
. , . . , , . . , . .
, .
Snapshot Agent .
2. SCH
.
, ( , ). ,
, ,
IDX. SCH IDX , D i s t r i b u t i o n .
3. Snapshot Agent
. ,
.
. bcp.exe
(native) . , SCH IDX,
D i s t r i b u t i o n .
, . .
, SCH , .

,
SQL Server 2000. SQL Server 6.x
. .

600

III.

4. (SCH, IDX,
), .
Snapshot Agent
D i s t r i b u t i o n , ,
, . ". Msrepl_commands
Msrepi_transactions. , , . . Msrepl_transactions

.
5. .
(log history file) .
( ), .
Snapshot Agent . , D i s t r i b u t i o n . .

~^)

( ), Snapshot
Agent, . .
(SCH) (IDX).
, Snapshot Agent, Distribution Agent.
. ,
. :
1. , Distribution Agent
. , .
(pull replication), . (push replication),
.
(_


, . . Distribution Agent
.
. ,
, . , .

14.

2. D i s t r i b u t i o n .
Msrepl_commands Msrepl_transactions.
, , (
), (SCH) (IDX).
3. Distribution Agent . ,
. ,
, SCH.

( ).
( bcp.exe BULK INSERT) . , , IDX.
, . , . SCH, IDX,
. , D i s t r i b u t i o n
. ,
.

(Transactional Replication).
. .
, , , .
, INSERT, DELETE UPDATE. -

D i s t r i b u t i o n .
. , D i s t r i b u t i o n . , .
, , . . ,
, . , ( ).

III.

602

, . . ,
. , .
.

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

.
. 14.13.

, :
Snapshot Agent;

14.

603

Log Reader Agent;

Distribution Agent.

.
-, . , .
. Snapshot Agent
, (SCH), (IDX) ( ). . Snapshot Agent
.
,
. Log Reader Agent. ,
, . INSERT, UPDATE DELETE, -

, .

(~

, 500 Unicode.

, , .
,
.
,
Log Reader Agent.

SQL Server 2000 ,


. . , , , s p _ r e p l c m d s .
, s p _ r e p i d o n e .

MSrepltransactions Distribution.

. , Snapshot Agent, , .

604

III.

, . .
, , . ,
, .
Distribution Agent.
,
. ,
,
.
, .
, .
,
. ,
, SQL Server 2000 , .

. . , SQL Server 2000 . . 100 . .

.
, SQL Server 2000 , .
(

, . ,
, .

Distribution
Agent. . ,
, .
Distribution Agent
MSrepi t r a n s a c t i o n s . , ,
, .
. Distribution Agent .

14.

605

,
,
.


INSERT, UPDATE DELETE. , -, . .

, , .
SQL Server 2000

. . , 15% ,
UPDATE,
. .
.
SQL Server 2000
(stored procedure replication).
,
, . , -
UPDATE. . , .
.
.
, . , . ,
,
( ), (SCH) (IDX), .
. ,

606

III.

,
, .
.
, , . ,
,
.

, .

( ) .
SQL Server 2000
:
Procedure Execution ( ).
. . , ,
. , , -
.
,
.
.
,
, .

^)

.
, .
, ,
.
, .

Serializable Procedure Execution ( ). ,


. , (DML, Data Manipulation Language). , ,
. ,
(serializable transaction).

14.

607


"" "".
. , . , . .
. .
,
, . . Snapshot Agent
, . .
, SQL Server 2000 . , , ,
. .
correct_price, ,
, .
goods. , c o r r e c t p r i c e
p r i c e _ i i s t , .
, , ,
goods. , p r i c e _ i i s t
. , . correct_price.

, , .
,
. , , ,
.
, SQL Server 2000 .
.
.

608

III.

, , . , , .

, ,
(
, ). .


, , (Immediate Updating Subscribers). , ,
. .
, .
,
, , .
SQL Server 7.0 (merge replication),
. ,
. , .

, . , ,
. , .
, SQL Server 2000 .
. 14.14 .

SQL Server 2000 :


Snapshot Agent
, .
, ,
Merge Agent , , ,
.

14.

609

. 14.14.
SQL
Server 2000. , , . ,
. ,
.
, , .
:
SQL Server 2000 , ,
. , (GUID, Global Unique Identifier). GUID uniqueidentifier,
. GUID
.
( ).
SQL Server 2000 , ,
uniqueidentif i e r ROWGurDCOL.
, . ROWGUID,
. ^. .

610

III.

timestamp ,
. .
. u n i q u e i d e n t i f i e r .
, . , ,
(triggers), INSERT, UPDATE, DELETE
.
, .

(~


, SQL Server 2000 . SQL Server
(, ).
SQL Server 2000 .
, ,
- . , , , .

, Msmerge_contents Msmerge_tombstone INSERT,


UPDATE DELETE.
ROWGUID, .
. ,
.
, , . (
), (SCH) (IDX) Snapshot
Agent, .

(~~

|* .

14.

611

Merge Agent .
,
.

Merge Agent , (push replication), , (pull replication).


.
, . , .
CD-ROM DVD ,
, .

, , u m q u e i d e n t i f i e r ROWGUIDCOL. ,
.
, . ,
, .
.
.

. Msmergecontents.
ROWGUID, . , , TABLENICK. GENERATION
, . , Msmergecontents
, .
Msmergecontents. Msmerge_contents .
, ,
,

612

III.

(merge) . , Merge Agent D i s t r i b u t i o n .


, . (
), Merge Agent ,
,
. .
. Merge Agent
, ""
. , . , 100- .
, , .
.

,
( GENERATION) (
LINEAGE COLVI). .

,
.
"", Merge Agent
. , , .

SQL Server 2000 , ,


,
. , .
, SQL Server 7.0. SQL Server 2000
. ,
, . ,
, Microsoft SQL Server 2000.
:
,-.

14.

613

Microsoft SQL Server Additive Conflict Resolver


. , , ;
Microsoft SQL Server Averaging Conflict Resolver .
;
Microsoft SQL Server DATETIME (Earlier Wins) Conflict Resolver (datetime smalldatetime). , ;
Microsoft SQL Server DATETIME (Later Wins) Conflict Resolver
(datetime smalldatetime). , ;
Microsoft SQL Server Maximum Conflict Resolver
. ,
;
Microsoft SQL Server Merge Text Conflict Resolver . ,
;
Microsoft SQL Server Minimum Conflict Resolver
. , ;
Microsoft SQL Server Subscriber Always Wins Conflict Resolver ,
. , , .
, .
,
. .
,
.

,
, .
, .

, , :
Subscription cleanup at the Publisher;
History cleanup at the Distributor.

614

III.


SQL Server 7.0
. , . . - , . .,
( ).
.
. SQL
Server 7.0. SQL Server ,
:
(Merge Replication);
(Immediately-Updating Subscribers).
-
.
. , , .
, , . ,
. ,
, ( ) , .
,
. , ,
. .

.
SQL Server 7.0 ,
, . ,
, . -,
, .

. , -

14.

615

, . ,
.
, .

,
. ,
( )
.
SQL Server 2000 . SQL Server 2000
. (Queue Updating),

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

. , , , .

, , .
ROWGUIDCOL.
. " " .


, , .

616

III.

,
.
, , , . , .
.
,

(immediate updating subscribers). ,
SQL Server 7.0 , ,
.


. ,
. ,
.

SQL Server 2000 SQL Server 7.0.


(2, two-phase commit protocol),
,
. 2 (MSDTC, Microsoft Distributed Transactional Coordinator)
(distributed transactions).
,
. , ,
,
, . , , . .
, SQL
Server 2000 .
,
. ,
.
. .

14.

617

, ,
. . .
, ,
.
, , .
. , ,
, .
.
. . 14.15 , .

. 14.15.
, , SQL Server 2000 . tiniestamp. ,
, . timestamp .

618

III.

timestamp " ".


, timestamp, .
.
timestamp, . . , .
, (triggers), , INSERT,
UPDATE DELETE. ,
, .
(MSDTC), 2.

,
,
. .
.
, , .
, timestamp ,
. ,
timestamp
.
, .
.
timestamp,
. ,
, . , , , , .

(constraints) (rules). , .
, . . timestamp
. .

14.

619

. timestamp , . ,
,
.
,
. ,
.
(MSDTC), .
. . , , .
, . .
(2). , , .
, Log Reader Agent D i s t r i b u t i o n ,
. , , , ,
. .

, , ,
. .


SQL Server 2000 , ,
:
,
, timestamp.
,
. ,
( ), , timestamp .

620

____

III.

INSERT . , .
, . .
.
SQL Server 2000 . , SQL Server 2000
time stamp.
, . .
. ,
,
,
.

timestamp. , IDENTITY.
.
t e x t image, .
.


, SQL Server 2000 ,
.
, . , , . ,
, .

. ,
.

^
.
SQL Server 7.0. SQL Server 2000

14.

621

(Queue Updating), ,
,
.
. 14.16 .

. 14.16.

, . . ,
.
, ,
, .
; , .
(queue). -

622

III.

, . .
, .
-
, .

, ,
.
.
. . . , , . ,

.
. ,
. , . ,
,
.

,
. ,
.
, . SQL Server 2000 , . ,

:
Microsoft Message Queue. , . . ,
, , , , . , Microsoft SQL Server 2000 queue, Microsoft Message Queuing
2.. , . .
SQL Server 2000,
. -

14.

623

SQL Server. To
SQL Server 2000, .
Microsoft Message Queue
Message Queue , , Queue Reader Agent.
SQL Server. -
SQL Server 2000 MSRepiication_queue,
. , . . , SQL Server 2000 Windows 98/NT/2000.
MSReplicationqueue Queue Reader Agent,
. sp_sqlqmon. ,
.
. SQL Server
,
, .
, , ,
. . , , , .
DELETE, INSERT
UPDATE.
. . .
(

,
NOT FOR REPLICATION, . ,
, .
,
. ,
01

9 11

624

III.

,
. ,
. , , UPDATE, DELETE INSERT. ,
.
, . , .
Microsoft , Queue Reader Agent.

, . ,
. , , .
,
. -,
, . ROWGUIDCOL,
. ROWGUIDCOL u n i q u e i d e n t i f i e r .

NEW (). ,
(GUID, Global Unique Identifier). , ROWGUIDCOL ,
. GUID, .

Queue Reader Agent, ,
GUID. , , , . .
. , , . .
;
Queue Reader Agent .
,
, . , GU1D ,
? , -

14.

625

GUID, .
GUID .
Queue Reader Agent
,
. .
, . , (winner)
(loser). ( ) , . :
Reinitialize Subscriber. .
,
.
, . ,
,
. ,
Distributor Agent.
Publisher wins.
. , , . , Queue Reader Agent , ,
,
.
Subscriber wins. . ,
. .
.
, , .

.


, . ,
SQL Server 2000
. -

626

III.

.
.
, . :
"--". ,
. ,
.
"--" . , .
, , .
"--". .
(DSS, Decision
Support Systems). , , , . , . .
.
"--".
, . "--"
,
. , .
.
SQL Server 2000
. , , .
,
.
. .

, ,
.


, , , , . SQL Server 2000 :

14.

327

....,,,.

Enterprise Manager;
.
,
. ,

, SQL Server 2000. ,
.
Enterprise Manager
, . , . ,
.
. .

,
Enterprise Manager
.
,
Enterprise Manager. , . Enterprise Manager,
, Enterprise Manager. To
. , ,
.

>


. Enterprise Manager.
.

-.-.-

,:,

. '.f-nV


. , . ~
, . , ,, .;>

628

III.


, , . , . . , .
.
, . , . .
,
, .
, . , , . SQL Server 2000
.
, ,
Configure Publishing and Distribution Wizard.
, , . .

Enterprise
Manager .

Select Wizard (. 14.17) Replication Configure Publishing and Distribution Wizard.

Select Wizard
Run a wizard,
Enterprise Manager.

. 14.17. Select Wizard


,

. ,
( )
.

14.

629

Configure Publishing and Distribution Wizard , , ,


, . .
Select Distributor (. 14.18) ,
, SQL Server 2000,
.

. 14.18. Select Distributor


Configure Publishing and Distribution Wizard
,
:
Make 'ServerName' its own Distributor; SQL Server will create a distribution database and log1.
, SQL
Server 2000, . ,
. , . ;
Use the following server, which has already been configured as a Distributor.
, ,
1

'ServerName' . .

III.

. . , ,
. , .
SQL Server 2000,
Enterprise Manager. , .
. Add Server,
.
. " " 10.
. . .
.
Customize the Configuration (. 14. i 9)
, :
Yes, let me set the distribution database properties, enable Publishers, or set the
publishing settings. ,
, . ,

. , . , ,
. , (
) .
/'No; use the following default settings. ' ' , , .

D i s t r i b u t i o n , ,
(, , .
, , ,
. .
, ^ , . .
.

14.

631

. 14.19. Customize the Configuration


Configure Publishing and Distribution Wizard

Provide Distribution Database Information (. 14.20), "


". , :
Distribution database name. ,
. ,
d i s t r i b u t i o n . . ,
.
Folder for the distribution database file. i ,
, (mdf ndf)
. , , Browse for Folder,
^ J ,
;
.
Folder for the distribution database log file.
.
;
>

,
()
.
.

. ;

.,-. '.-.

632

III.

. 14.20. Provide Distribution Database Information


Configure Publishing and Distribution Wizard

. 1 4 . 2 1 . Enable Publishers
Configure Publishing and Distribution Wizard

, ,
, Enable Pub-

633

14.

Ushers (. 14.21), , .
Registered servers, . Publishers .
, . Distribution DB
, . ,
. ,
.
...!, Publisher "Properties
(. 14.22).

. 14.22. Publisher
Properties
STORAGE

, :
Name. -.
.
Distribution database. ,
. -

634

III.

, . .
Snapshot folder. ,
, Snapshot Agent.
\Program Files\Microsoft SQL
Server\MSSQL\ReplData. , .
.
,
, ,
, :
Impersonate the SQL Server Agent account on 'ServerName' (trusted connection).
Windows NT. To
, SQLServerAgent. ,
,
SQLServerAgent, . Windows NT.

""")

, ,
SQLServerAgent
( ).
.
Use SQL Server Authentication.

SQL Server. , :
_.. Login , ...... . , ,
;

Password , ;

* Confirm password .
.
;, Enable Publishers (. . 14.21).
:
Enable All",
- 6- 1 ;

635

14.
Enable None ;

New .
.
Enable Publishers . Enable Publication Databases (. 14.23).
( . . ), .

. 14.23. Enable Publication Databases


Configure Publishing and Distribution Wizard

: '

, . ,
. Databases, , . :
Trans
, ;
Merge .

Transactional Merge,
( Enable All),
( Enable None), , Trans Merge:

636

III.

, , . , , , .
Enable Subscribers (. 14.24), ,
. , , . .
^ 1 ,
SubscribersTrroperties (. 14.25).

. 14.24. Enable Subscribers


Configure Publishing and Distribution Wizard

, . General
Description, , . . (
Impersonate the SQL Server Agent account on 'ServerName' (trusted connection))
Windows NT,
SQLServerAgent. SQL Server ( Use SQL
Server Authentication). ( Login name)
( Password Confirm password) .

637

14.

. 14.25. Subscriber
Properties, General

Schedules (. 14.26),
. .
Distribution Agent,
Merge, Agent.
( Continuously),
( At the following scheduled times).
. Edit
Recurring Job Schedule.
,
, , .
. Finish .
, ,
Enterprise Manager - Replication Monitor
Group,
, , ,
. , , ,
Publications, , . , ,
Enterprise Manager ,
.

III.

638

. 14.26. Subscriber
Properties, Schedules



.
. , , . , ,
.

, . , , .
, . ,
Configure Publishing and Distribution Wizard. Publisher and
Distributor Properties (. 14.27).
Replication Monitor Group. Distributor Properties.

III.

640

, .
Databases Properties. Distribution Database Properties (. 14.28).

. 14.28. Distribution
Database Properties
Name, . ,
.
, .

,
. , Enterprise Manager - Management\SQL Server AgentUobs .
Transaction retention,
.
. At least .
.

14.

641

, .
,
. , .
.
But not more than . , , . ,
,
. .
72 .
,
. 10
,
.
48 .
.
, , . , ,
.

, .
.
, Distributor (. . 14.27).
Agent Profiles, Agent
Profiles (. 14.29). . , ,
.
Distribution, , , Distribution Agent.

.
,
. (Profile) . .

642

III.

. System. User. , . .

. 14.29. Agent Profiles


, . View Details (
Modify, ),
. Replication Agent Profile Details.
,
. , . . . .
. Description (. . 14.29).
(. . 14.27).
Distributor Publishers (. 14.30).
Publishers Enable
Publishers Configure Publishing and Distribution Wizard (. . 14.21).
, Publishers -

643

14.


. Servers.
, ,
, .
,
.

. 14.30. Publisher
and Distributor Properties,
Publishers
, . Publisher Properties,
^ | .
(. . 14.22).
Publishers .
Publication Databases (. 14.31) .
, .
Trails Merge, ( )
. . ,
Enable Publication Databases
Configure Publishing and Distribution Wizard (. . 14,23);

III.

644

. 14.31. Publisher
and Distributor Properties,
Publication Databases
, Subscribers (. 14.32).
, ,
Enable Subscribers (. . 14.24). ,
, .
Subscribers , , .

, .
, Subscribers
.
.
Subscriber Properties,
jgj, .

(. . 14.25).

.

645

14.

. 14.32. Publisher
and Distributor Properties,
Subscribers


,
. , ,
.
.
, , . ,
, . , , ,
.
Disable
Publishing and Distribution Wizard. , , Select Wizard (. . 14.17).
.
, . ,
, ,
. , Next.

646

III.

(. 14.33)
.
.
, . ,
. , . , Finish. , , ,
, - Finish.

. 14.33. Disable Publishing and Distribution Wizard

,
.
,
. , (, ) , u n i q u e i d e n t i f i e r timestamp.


, , . -

14.

647

. , . .
. , .
, ,
.


, .
, , , . :
;
;
.

:
;
.

, , . .
Create Publication
Wizard. , .
Select Wizard (. . 14.17)
, , (. 14.34). , ,
,
, . Databases and publications , , Create Publication.
Create Publication Wizard.
Create Publication Wizard ,
Show advanced options in this wizard, ,
(advanced) . -

648

III.

, .

. 14.34.
, Choose Publication Database, ,
.
Northwind.
,
, Select Publication Type (. 14.35).
,
. , :
Snapshot publication ;
Transactional publication ;
G Merge publication .

, . ,
,
.
, Select Publication Type
, Next.
, Specify Subscriber Types (. 14.36),
.
,
:

14.

649

Servers running SQL Server 2000 SQL Server 2000;


Servers running SQL Server version 7.0 SQL Server 7.0;
L"J Heterogeneous data sources, such as Oracle or Microsoft Access, or devices running SQL Server for Windows ,
SQL Server 2000 SQL Server 7.0. Oracle,
SQL Server 6.x.

. 14.35. Select Publication Type Create Publication Wizard

. 14.36. Specify Subscriber Types Create Publication Wizard

650

III.

,
SQL Server 2000. SQL Server 7.0
,
. , SQL
Server 2000. .

, Specify Articles
(. 14.37). , .
,
.

. 14.37. Specify Articles Create Publication Wizard

SQL Server 7.0, ,


(Tables),
(Stored procedures), (Views) (User-defined functions). . ,
Server running SQL Server version 7.0
.

14.

651

,
. . . , Shove
. Publish All
.

Show unpublished objects .


, , .
. ,
\%1, .
.
,
. Article Defaults
.
, .
, ,
Article Issues (. 14.S8).
. ,
.
, . ,
, .
. ,
.

, , .
Article Issues
, Select Publication Name and Description
(. 14.39). ,
, . Publication name.
, ,

652

III.

. Publication
description. ,
, -, .
.

. 14.38. Article Issues Create Publication Wizard

. 14.39. Select Publication Name and Description Create Publication Wizard

14.

653

, List this
publication in the Active Directory, .
, Active Directory. ,
-, .
Customize the Properties of the Publication (. 14.40).
( , . .). ,
:
Yes, I will define data filters, enable anonymous subscriptios, or customize other
properties. , .
, .

. 14.40. Customize the Properties of the Publication


Create Publication Wizard

No, create the publication as specified. .


,
, ,
.
,

III.

654

. ,
, Snapshot Agent
23:30. .
. .
.


. ,
.
, , Filter Data
(. 14.41),
( ) . , :
D Vertically, by filtering the columns of published data.

, . .
, ;

. 14.41. Filter Data Create Publication Wizard

14.

___^_

655

Horizontally, by filtering the rows of published data.


,
. , .
.

, ( , )
, . , , .
,
. , ,
.
, Filter Data
, Filter Table Columns (. 14.42).
, .
, . , , . ,
.
. , . , - (, ), ' .
.
, , Enable Dynamic Filters (. 14.43).
( Yes, enable dynamic filters) (No, use
static filters) .

, , . , ,
.


.
, , 2 2 . 1207

656

III.

. , .

(dynamic snapshot).

. 14.42. Filter Table Columns Create Publication Wizard

. 14.43. Enable Dynamic Filters Create Publication Wizard

14.

657

,
Create Dynamic Snapshot Work . .

SQL
Server 2000, , .
, Generate Filters Automatically
(. 14.44), (extend filter),
. Table to filter ,
.
None do not extend filter, . ,
. SELECT, . WHERE. ,

, .

. 14.44. Generate Filters Automatically


Create Publication Wizard
22*

III.

658

SELECT, WHERE, 29. ,


, .
OR AND.
, .
, Generate Filters Automatically ,
Filter Table Rows (. 14.45),
. ,
. ,
.
( Table) ( Owner) ,
( Article). , Filter Clause ,
SELECT, WHERE. ,
<11 rows published>
, .

. 14.45. Filter Table Rows Create Publication Wizard



Specify Filter (. 14.46), ,, |,
.

14.

659

. 14.46. Specify Filter


Table to filter Specify Filter ,
. Article name
, . . ,
SELECT,
. ,
WHERE. , , ,
.
. ,
,
.
SOSERSNAME () HOST_NAME (), , ,
.
, SELECT
, .
.
, , .

HOST_NAME ( ) , , , SUSER_SNAME ?

III.

660

, . , . , Windows NT, SQL Server.


, Employees :
SELECT <published__columns> FROM [dbo] . [Employees]
WHERE T i t l e O f C o u r t e s y = ' M r . '

<published_coiumns> ,
Filter Table Columns (. . 14.42). WHERE TitieOfCourtesy = 'Mr.',
,
TitleOfCourtesy ..
Filter Table Rows (. . 14.45).
,
. . .
FOREIGN KEY.

JOIN SELECT. 29.


, , .
:
Filtered Table ,
. PRIMARY KEY ( );
Table to Filter ,
FOREIGN KEY ( );
JOIN Filter Clause ,
. table2.fk.ey = tablel.pr.key,
,
, AND OR.
Specify JOIN,
Specify Filter (. . 14.46).

Specify JOIN
.
,
Validate
formation (. 14.47).
,

,
Subscriber In
-

14.

661

. Yes, validate Subscriber information .


, . ,
, . .

. 14.47. Validate Subscriber Information Create Publication Wizard


, No, do not validate Subscriber information. ,
.
Optimize Synchronization. , ( Yes, minimize the amount of data), (No, do not minimize the amount of data) .
(Allow Anonymous Subscriptions), .
,
:
Yes, allow anonymous subscriptions. , .

662

III.

No, allow only named subscriptions. ,


.
, Set Snapshot Agent Schedule, Snapshot Agent,
.
23:30 , . Change
Edit Recurring Job Schedule,
Snapshot Agent, .


, Create the first snapshot immediately.
. . . ,
Finish. . , .
Finish
. . , Publication Properties.
.



,
, , ,
. , ,
. ,
, ,
. ,
, . Snapshot Agent
,
Merge Agent.
,

, , -

14.

663

. ,
, . , , , .
,
, . .
,
"" .
SQL Server 2000 .
(dynamic snapshot), , . , , ,
. ,
.

.
.
, .
Create Dynamic Snapshot Wizard, , ,
.
. ,

.
,
.
Create Dynamic Snapshot Wizard
Publications , ,

Create Dynamic Snapshot Job (. 14.48), Create Dynamic Snapshot Wizard.

~^

Create Dynamic Snapshot Wizard/


,
. , ,
, Snapshot Agent.
, ,
. , , -

III.

664

, . ,
, Jobs, ManagemenftSQL Server Agent, REPL-Snapshot. Status Last Run Status , ,
( ) .

. 14.48. Publications
Create Dynamic Snapshot Wizard . ,
.
, .
, Specify Filter Values (. 14.49), ,
HOST_NAME () SOSER_SNAME (). , . ,
WHERE RowOwner=HosT_NAME (),
STORAGE, TO
:
SELECT--< > FROM. < > WHERE RowOwner = 'STORAGE'

665

14.

. 14.49. Specify Filter Values Create Dynamic Snapshot Wizard

STORAGE. . , ,

.
.

, , .
,
.

,
(. 14.50). , Specify Snapshot
File Location, ,
.
, , (
). Merge Agent
.

. , -

666

III.
. ,
, .

. 14.50. Specify Snapshot File Location


Create Dynamic Snapshot Wizard

. 14.51. Set Job Schedule Create Dynamic Snapshot Wizard

14.

667

, Set Job Schedule


(. 14.51) Snapshot
Agent
. , Create Dynamic Snapshot Wizard
SQLServerAgent, Snapshot
Agent , . ,
, , .
, , , :
Run the job on the following schedule. . ,
Snapshot Agent 23:49. Change
Edit Recurring Job Schedule, . ,
, , .
Run the job on demand only.
. Managem e n t SQL Server Agent\Jobs .
, ,
.
Create the first snapshot immediately, Snapshot Agent
.
, ,
Specify Job Name, ,
.
Management SQL Server Agent\Jobs
. ,
, '_Dynamic\ ,

.
. .

. ,
Finish ,
( ), .

III.

668

,
33 200 . . 14.52
DynSnap5,
. .

, Wstorage\snapshot$\Dynsnap5, Specify Snapshot File Location (. . 14.50),


C:\Tmp\Dynsnap5. \\storage\snapshot$ C:\Tmp.

. 14.52.

, ,
ReplData. , . , -

14,

669

This is a snapshot for a dynamically filtered subscription.


.


.
,
, .
,
.


Publication
Properties (. 14.53). , ,
.
General . ,
:
Name. , .
,
.
Database. , , .
, .
Description. .
, .
( , ).
List this publication in the Active Directory. Active Directory, , -, .
Subscription expiration.
, :

Subscriptions expire and are dropped if not synchronized in the following


number of days
, , . ,
.

670

III.

, .
.
.
Subscriptions never expire ,
, .
, Articles.

. 1 4 . 5 3 . G e n e r a l


Articles (. 14.54) , . .
,
. , ,

. Show,
,

.

14.

671

. 14.54. Articles
. Publish All. , .
Show unpublished objects,
,
. , .


-. , , ,
.
. .
, , ,
. ,
. Article Defaults
Articles. Default Article Type (. 14.55), -

672

III.

. . , . 14.56 Default View Article Properties .


.

. 14.55. Default Article Type

. 14.56. Default View


Article Properties


,
. ,
. ,
. Show unpublished objects
Articles (. . 14.54), -

673

14.

pa . ,
Orders. , orders, . , .
Table Article Properties (, j4.57) ,
, . ..
. , General Snapshot,
, , . ;>
, ;
.

. 14.57. Table Article


Properties, Genera!

, General (. 14.57):
Name - .
, .
Description . ( , ).
Source table owner. , ,
, .

674

III.

Source table name. ,


.

.
Destination table owner. , , ,
. ,
.
,
. , dbo , . .
.


Destination table name,
, .
.

When merging changes from different sources. , , :


Treat changes to the same row as a conflict

. ,
. , . .
, .
Treat changes to the same column as a conflict (changes to different columns in
the same row will be merged)
, . . Merge Agent
, .
, Snapshot.
Snapshot (. 14.58), ,
. .
,
,
. :

14.

675

Keep the existing table unchanged. .


DROP the existing table and re-create it.
,
, . , , , .
Delete data in the existing table that matches the row filter statement. , . ,
, .
, .
Delete all data in the existing table. .

. 14.58. Table Article


Properties, Snapshot
. , , , , . , ,
,

III.

, ,
. .
,
, , :
Include declared referential integrity. , FOREIGN KEY
( ). ,
, .
Clustered indexes.
, , .
Nonclustered indexes. .
User triggers. ,
.
Extended properties.
, . , ,
.
Collation. , .'

. ,
, , .
,
Convert aser-defmed to base data types. Snapshot Agent , ,
(LJDDT, user-defined data types),
.
,
,
.
Snapshot ,
Resolver (. 14.59),
. ,
. ,
:

14.

677

Use the default resolver.


,
.
SQL Server 7.0.
Use this custom resolver (registred at the Distributor).

. ,
. SQL
Server 2000
. " " . , , .
.
Microsoft SQL Server Stored Procedure Resolver Enter information
needed by the resolver .

. 14.59. Table Article


Properties, Resolver


, ( ) . ,
,
.

III.

678

, . .
Identity Range (. 14.60), - (
IDENTITY) . . -,
, ,
- . ,
.
. - -
( SQL
Server 2000), .

. 14.60. Table Article


Properties, Identity
Range

- 21.


, ,
. . - ,
. Identity Range -

14.

679

,
-.

(~

, Identity Range
, -.
(. . 14.60) ,
-. ,
.

:
Maximum identity value.
-. ,
.

-
t i n y i n t ( 0 255), s m a l l i n t (
-32 768 32 767), int ( -2 147 483 648 2 147 483 647) b i g i n t
( -9 223 372 036 854 775 808 9 223 372 036 854 775 807).
Next range starting value. ,
.
.
Identity increment -. 1 .
Range size at Publisher , .
Range size at Subscribers , .
Assign a new range when this percentage of values is used. ,
, .
Identity Range . ,

-.
.

Merging Changes (. 14.61).
Check permissions,

III.

680

Merge Agent .
, . ,
,
.
. , , .
:
INSERT ;
UPDATE ;
DELETE .

. 14.61. Table Article


Properties, Merging
Changes
,
,
.
,
.
UPDATE, .
,
.
.

14.

681


, Articles
. , . Filter Columns
Filter Columns (. 14.62) ,
, . , . ,
. , ,
. , . ,
. .

. 14.62. Filter Columns


,
, . ,
, ,
ROWGUIDCOL.
Add Column to Table Drop
Selected Column, , , -

682

III.

.
( ),
.
Add Column to Table Add Column to Replicated Table (. 14.63),
. Table, , .
Column name,
Column definition (excliding the column name). ( <data_type>), .
. 21.

. 14.63. Add
Column to Replicated Table

Include this column in the following publications, , .


,
, , ,
. , , .

14.

683

Filter Rows
(. 14.64). ,
. Filter
Clause. Specify Filter
(. . 14.46), ,
Filter Rows , . " " . .

. 14.64. Filter Rows


, , Subscriptions
(. 14.65), ,
.
,
.
Push New,
Push Subscription Wizard,
.

684

III.

. 14.65. Subscriptions

,
:
Properties , ;
Delete ;
Reinitialize , ;
Reinitialize ;
View Conflicts .

.
Subscriptions,
. , :
Subscription Name ;
: (Push) (Pull);
Priority .

14.

685


, Subscription Options (. 14.66) .

. 14.66. Subscription Options


, :
Allow pull subscriptions. . :
Allow anonymous subscriptions .
Allow new subscriptions to be created by attaching a copy of a subscription database. (attaching)
.

.
Centralize conflicting reporting at the Publisher
.

686

III.

Allow partitioning through dynamic filters. ,


. , .
Before merging, validate Subscribers with this expression.
WHERE,
. , , .
, .
Minimize network traffic by increasing the storage requirements at the Publisher.
, . .


, , Snapshot
(. 14.67). , Merge Agent
.

. 14.67. Snapshot

14.

687

, Snapshot
format, ,
:
Native SQL Server format all Subscribers must be servers running SQL Server.
(native) , .
SQL Server 2000 SQL Server 7.0.
Character mode format supports heterogeneous Subscribers and data transformations using DTS.
, (Oracle, SQL Server 6.x, SQL Server 2000 . .).
, , Transact-SQL,
( )
( ) .


Snapshot Location (. 14.68) ,
.

. 14.68. Snapshot Location


23

.1207

88

III.

SQL Server , . SQL


Server 2000 . , , FTP.
, Snapshot Location:
Generate snapshots in the normal snapshot folder. , Program Files\Micsoroft SQL
Server\MSSQL\ReplData. , . , .

, . .
Generate snapshots in the following location.
, ,
. :

Folder , . , ;

Compress the snapshot files in this location ,


.
;
Subscribers can access this folder using FTP (File Transfer Protocol) ,
FTP.

, FTP:
FTP server name FTP, .
, , Folder,
FTP.
Port , FTP;
Client path to this folder from the FTP root
FTP, .
;

14.

689

Login ,
;
Password , ;
Confirm Password .
, Snapshot Location.
.


Publication Access List (. 14.69).
.

. 14.69. Publication Access List


, , . , ,
, ,
, .
Add,
SQL Server Enterprise Manager,
23*

690

III.

, .
.


Sync Partners (. 14.70)
. , .
.
. ,
,
.
SQL Server 2000
, , .
Sync Partners.

. 14.70. Sync Partners

.
,
. . -

14.

691

. , .


, , Status
(. 14.71). Snapshot Agent
SQLServerAgent.

. 14.71. Status
Last run Next run
Snapshot Agent. Snapshot Agent , Run Agent Now. Agent Profiles ,
Agent Profiles. Explore Snapshot
(. 14.72).
, Explore The Last Snapshot Folder.

, , . , -

III.

692

,
.

. 14.72.
, . SQLServerAgent, .
Status , , .

Start Service, .
Refresh Status
.


, , .
, . , , -

14.

693

Publications
.. Delete. .
, .
, .
,
. , .
.


,
.
,
.
.
. ,
,
. ,
, , , .
, .
, .
,
Create Publication Wizard.
(Push Subscription), (Pull Subscription).


, , . . ,
.
, .
. ,
Merge Agent
,
, ,
, .

III.

694

Push
Subscription Wizard, .
Select Wizard,
Run a wizard, Enterprise Manager. .
Subscriptions (. . 14.84),
Push New.
, Push New Subscriptions. Action Enterprise Manager
.
, Select Wizard Create and Manage Publications (. 14.73).
,
, .
Push New Subscription.

, Create and Manage Publications


Properties, . Create and Manage Publications Tools, Replication, Create and
Manage Publications.

. 14.73. Create and Manage Publications


, , ( ).
, . , -

14.

695

. , , .
, , , Choose Subscribers (. 14.74).
-

. 14.74. Choose Subscribers Push Subscription Wizard

,
.
, , <Ctrl> <Shift>, . .
, , , Choose Destination Database (. 14.75).
,
. ,
.
. , Browse Databases
(. 14.76), . Browse or Create.

,
Browse or Create . ,
. .

696

III.
,
Choose Destination Database, , .

. 14.75. Choose Destination Database


Push Subscription Wizard

. 14.76. Browse
Databases
, Browse Databases Database Properties (. 14.77), Create
New.
, 20.

14.

697

. 14.77. Database Properties


Choose Destination Database (. . 14.75).
,
, .
,
Push Subscription Wizard .
, .
Northwind, , , .
Set Merge Agent Location (. 14.78) Merge Agent.
Merge Agent
, SQL Server 2000
, .
, :
Run the agent at the Distributor , SQL Server 7.0.
Run the agent at the Subscribers (administration will still be performed at the Publisher and Distributor).

698

III.

.
,
, .
Merge Agent . .
: Network computer name of
Subscriber NetBIOS . SQL Server 2000.

. 14.78. Set Merge Agent Location Push Subscription Wizard


Merge Agent , .
.

Merge Agent, Set Merge Agent Schedule (. 14.79) . ,
,
:
Continuously provides minimal latency between when an action occurs at the
Publisher and is propagated to the Subscriber. . ,

699

14.

. , Merge Agent.
Using the following schedule.
. ,
. . .
. , Edit Recurring Job
Schedule, Change.

. 14.79. Set Merge Agent Schedule Push Subscription Wizard

(~

, SQLServerAgent. , , Merge
Agent. ,
, .
12.
Merge Agent,
Initialize Subscription (. 14.80),

700

III.

, :
Yes, initialize the schema and data.
, . , , :
Start the Merge Agent to initialize the subscription immediately
,
.
Merge Agent.
No, the Subscriber already has the schema and data. , , . . ( -
).

. 14.80. Initialize Subscription Push Subscription Wizard


.
, , . . ,
.
,
( ) .

14.

701

Northwind ,
(, ), ,
, .
, Set Subscription
Priority (. 14.81), . . ( Use the priority setting of the Publisher to resolve the conflict),
( Use the following priority, between
zero (lost) and 99.99 (highest), to resolve the conflict). ,
. 75, 0 99.

0 100, 100 .

. 1 4 . 8 1 . Set Subscription Priority Push Subscription Wizard

, . , , .

702

III.

, .
.
Start Required Services (. 14.82) SQLServerAgent, , , . ,
SQLServerAgent ( )
Finish .
Status.

Initialize Subscription
,
SQLServerAgent .

. 14.82. Start Required Services Push Subscription Wizard

. . . Finish
.
, .

14.

703


, , . , , . ,
, .
,
,
.
Pull
Subscription Wizard,
. ,

.
.

Pull Subscription Wizard ,


.
Look for Publications (. 14.83)
, ,
:
Look at publications from registered servers.
.
Look at publications in the Active Directory or specify publication information, this
option is for Publisher running SQL Server 2000 or later. Active
Directory. ,
, Active
Directory. , Active Directory
SQL Server 2000, Windows 2000 Active Directory.
, .
Choose Publication , . 14.84.
,
.
, , , . , .
,
Register Server.

704

III.

. 14.83. Look for Publications Pull Subscription Wizard

. 14.84. Choose Publication Pull Subscription Wizard


,
, Specify Synchronization Agent Login
(. 14.85). ,

14.

70S

Merge Agent . , SQLServerAgent


( Impersonated the SQL Server Agent account),
SQL Server,
( Use SQL Server Authentication).
( Login) ( Password Confirm
password) .

. 14.85. Specify Synchronization Agent Login


Pull Subscription Wizard

Choose Destination Database , . , Northwind,


, chair. ,
, . New.
Allow Anonymous Subscription (. 14.86) ,

. , , .
,
.
No, this a named subscription.

706

III.

. 14.86. Allow Anonymous Subscription Pull Subscription Wizard

. 14.87. Initialize Subscription Pull Subscription Wizard

'

Initialize Subscription (. 14.87) ,


. ,
, , .

14.

707

Yes, initialize the schema and data.


, ,
Merge Agent.
, Snapshot Delivery (. 14.88).
, . , :
Use snapshot files from the default snapshot folder for this publication.
ReplData, .
Use snapshot files from the following folder.
, . , .
Snapshot Agent , .
, This snapshot is for a dynamically filtered subscription.

. 14.88. Snapshot Delivery Pull Subscription Wizard


, . "

708

III.

" . ,
C:\Tmp\DynSnap5.
Set Merge Agent Schedule (. 14.89), Merge Agent,
.
:
Continuously provides minimal latency between when an action occurs at the
Publisher and is propagated to the Subscriber. Merge Agent . .
Using the following schedule. .
On demand only -- you can synchronize this subscription using SQL Server Enterprise Manager or the Windows Synchronization Manager.
. , .
Merge Agent , .

. 14.89. Set Merge Agent Schedule Pull Subscription Wizard


,
,

14.

709

. Set Subscription Priority


(. 14.90). (.
. 14.81). , , 75.

. 1 4 . 9 0 . S e t S u b s c r i p t i o n P r i o r i t y Pull Subscription Wizard

. 14.91. Start Required Services Pull Subscription Wizard

710

III.

Start Required Services (. 14.91) SQLServerAgent. , SQLServerAgent Finish


. Status .
SQLServerAgent
, Configure SQL Server Agent (. 14.92).
SQLServerAgent
. . SQLServerAgent , .

. 14.92. Configure SQL Server Agent Pull Subscription Wizard

.
. Finish
.


.
. , .

14.

711

. Subscriptions (. 14.93) .
.
, ,
. .

. 14.93. Subscriptions
, , . , . , Subscriptions Properties. .
(Pull).
.
,
. .
(. 14.94).
. General

.

712

III.

. 14.94.
,
General

. 14.95.
,
Synchronization

14.

713

Synchronization (. 14.95). ,
,
Merge Agen :
At the Distributor ;
At the Subscriber . , SQL
Server 2000-. Verify Agent
.
. ,
, .
- Replications\Subscriptions (. 14.96) ( Pull ).

. 14.96. Replications\Subscriptions
Pull Subscription Properties (. 14.97)
Properties
. .

714

III.

. 14.97.
,
General
General
, . , Synchronization (. 14.98).
Synchronization , Merge Agent. Agent Properties View Conflicts. Merge Agent.
, SQLServerAgent, Merge Agent.
. " "
.
View Conflicts Microsoft Replication Conflict Viewer.
.
.
, Synchronization. Enable synchronization using Windows Synchronization Manager. ,
,
Enterprise Manager. .

14.

715

. 14.98.
,
Synchronization


Programs (), Accessories Syncronize.
On-demand synchronization, :
Resolve conflicts automatically.
.
Resolve conflicts interactively (articles must support interactive resolution).

Microsoft Replication Conflict Viewer.

, . , ,
.
Synchronization Merge Agent Location,
Merge Agent:
Run the agent at the Subscriber ;

716

III.

Run the agent at the Distributor .


Network machine name of Distributor
-.
Synchronization Security (. 14.99).
, . ,
, Merge
Agent .

. 14.99.
,
Security
, Distributor login Publisher login, , ,
. ,
:
Impersonate the SQL Server Agent account on 'ServerName' (trusted connection).
Windows NT.
Merge Agent , , SQLServerAgent.
, SQLServerAgent
.

717

14.

Use SQL Server Authentication. SQL Server.


.
, . ,
Use the same login as for the Distributor. , .
Snapshot File Location (. 14.100).
.

. 14.100.
,
Snapshot File Location
, ,
:
Get the snapshot from the Publisher's normal snapshot folder. ReplData, .
Get the snapshot from the following folder. , . Folder. ,
. -

718

III.

, This is a snapshot for a dynamically


filtered subscription.
Download the snapshot using FTP (File Transfer Protocol). FTP.
, Snapshot Agent .
FTP, . ,
Snapshot Location
(. . 14.68).
Folder. , . ,
, . . .



,
.
. . ,
Enterprise Manager Delete.
.

, .

. , ,
. -

15


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

. . . , . , .
. .
,
. , -.
,
. ,
. , .
SQL Server 2000 , .
, 24 3*1207

'

720

III.

. .
.
(bottlenecks)
. .
,
.
. , ,
.
,
, ,
, . .
, RAID SCSI, 130 ,
128 , . - ,
.
.
.
,
,
/.
, . ,
.
.
.
, . ,
, . . . ,
, "" .
, .



. ,
:

15.

721_

.
.
:

Performance Monitor;

Task Manager;

Event Viewer;

Simple Network Management Protocol, SNMP.

SQL Server 2000 .


.
SQL Server 2000 :

SQL Server Profiler;

Enterprise Manager;

Transact-SQL.

. , , . , ,
, 1205,
, (deadlocks).
. , . ,
, .


, , ,
. ,
, , .
. . ,
, .
, , .
Performance Monitor, ,
, , '
. | . ,
, , SQL Server Profiler.
24*

722

III.

Performance Monitor
Performance.
Windows 2000
, . ,
Performance .
.
. ,
. , .

(~

Performance Windows NT 4.0


Performance Monitor.
Performance Windows 2000 , Performance Monitor Windows NT 4.0. Performance Monitor.
Performance Monitor
(counters). , . ,
, , .
, .

.
Performance Monitor
(objects), . ,
, Microsoft SQL Server 2000,
. , . , , , . .,
, , , . .

. ,
.
(instances).
.
,
Performance Monitor .

15.

723

, . ,
Performance Monitor. ,
, .
.

, . Performance Monitor.
SQL Server 2000. , . , . .
64 , , . , SQL Server 2000, SQL Server 2000. . 15.1 , SQL Server 2000.
IS. 1. SQL Server 2000

. 15.1 , SQL
Server 2000. ,
SQL Server 2000.
, . . . , SQL Server: User Settable Object.
, .
SQL Server User Settable Object 10 , User Counter 1
User Counter 10.
, . sp_user_counteri
sp_user counter10.

- dipcc s e t i n s t a n c e . , :

15.

725

USE master
EXEC sp_helptext 'sp_user_counter7'
:
Text
c r e a t e proc sp_user_counter7 @newvalue i n t as
dbcc s e t i n s t a n c e ('SQLServer:User S e t t a b l e ' ,
1
'Query , 'User counter 7 ' , gnewvalue)
,
:
dbcc setinstance ('SQLServer:User Settable',
'Query', 'User counter T, 10)
1

v,

, dbcc setinstance
SQL Server: User Settable Object. , .
Performance Monitor. ,
Programs () Administrative Tools, . .
perfmon.exe.

Performance Monitor
Windows NT 4.0, Performance Windows 2000. ,
. ,
SQL Server 2000 Windows 2000.
Performance (. 15.1) .
, .
, .
, ,
.
System Monitor,
, ,
, .
. 15.1.

726

III.

. 1 5 . 1 . Performance, System Monitor

System Monitor, :
Counter Logs. . ,
, , System Monitor. . Performance
, .

. . System Monitor , . .
. , ,
, System Monitor
.
Counter Logs Performance .

727

15.

Trace Logs. ,
. , , .
Alerts. , . ,
.
Performance , System Monitor.
. 15.1, ,
.
.
.
Add ( ).
Add Counters (. 15.2),
.

. 15.2. Add Counters


, , ( Use local computer counters) ( Select counters
from computer). , , .
Performance object ,
.
, . 15.1. , ,

728

III.

, .
( Select
counters from list), (
All counters).
, , .
, . , All instances,
( Select instances from list).
. 15.2 Add Counters SQL
Server:Databases. (All counters) (All instances), .
. 15.3 Performance .

. 15.3. SQL Server:Databases

. , - . . , -

15.

729

, , , , . .
, Properties.
.
. , , , .
, .
<Delete>. New Counter Set.
Percent Log Used SQL Server: Databases
. . 15.4 Performance
.

. 15.4. SQL Server:Databases Percent Log Used


. .
.

730

III.

View Histogram.
, . 15.5.

. 15.5. SQL Server:Databases

. 15.6. SQL Server-Databases

15.

731

, .
View Report. , . 15.6.
, HTML-.
Save As, ,
.
. , Web- .
- Internet Explorer. . 15.7.

Mm*
. 15.7. HTML-
, . ,
Performance, , Performance. ,
. 15.8 View Histogram.

732

III.

. 15.8. HTML-

Task Manager
Performance
SQL Server 2000,
.
, SQL Server 2000.
Task Manager, .
<Ctrl>+<Shift>+<Esc>.
, . 15.9.
, .
, Applications, , .
, (taskbar),
. . Running. "" ,
Not Responding.
"" , . . ,
. End Task.

733

15.

. 15.9. Task
Manager, Applications

. 15.10. Task
Manager, Processes

III.

734

, Applications SQL Server 2000.


, SQL Server 2000 ^ . , SQL Server 2000
.
Processes (. 15.10), ,
. ,
Applications. , ,
. , SQL Server 2000,
MSSQLServer SQLServerAgent .

MSSQLServer sqlservr.exe, SQLServerAgent


sqlagent.exe. , sqlservr.exe. ,
.

. 1 5 . 1 1 . Task
Manager, Performance

Performance (. 15.11). , , , , . .

15.

735

Event Viewer
Task Manager , .
Performance, ,
.
, SQL Server 2000 , . SQL Server 2000,
, Event Viewer.
(logs) ,
. :
Security Log. ,
,
, . .
System Log. .
Application Log. ,
SQL Server 2000, Exchange Server, BizTalk Server .

. 15.12. Event Viewer


, SQL Server 2000
Application Log. Event Viewer Pro-

736

III.

grams () Administrative Tools eventvwr.exe. Event Viewer


Application Log . 15.12.
,
, .
. .
Event Properties (. 15.13), . ,
.

. 1 5 . 1 3 .

Event Properties

Description ,
. , , , , . .

SQL Server Profiler



SQL Server 2000
, .
SQL Server 2000
.

15.

737

Performance , . ,
,
.
, . , SQL
Server 2000. SQL Server Profiler.
SQL Server Profiler ,
SQL Server 2000. ,
Performance. , , Transact-SQL, , SQL Server 2000
.
. SQL Server Profiler .
.
SQL Server 2000, . , ,
SQL Server 2000 .


SQL Server 2000
(events). SQL Server 2000
, .
- (event classes),
. SQL Server Profiler
Performance Monitor. SQL Server Profiler, Performance Monitor, . ( )
.
SQL Server . (category). . 15.2
.
15.2. SQL Server 2000

Sessions

738

III.
1S.2 ()

Objects

, , ,

Scans

, ,

TSQL

, Transact-SQL

Cursors

Stored Procedures

Error and Warning

, SQL Server 2000

Transactions

, , SQL Server
MSDTC,

Locks

Databases

Performance

,
, . .

Server

,
, MSSQLServer

Security Audit

User Configurable

, Master.
.
(Data Column). ,
. ,
. (Null).
. . 15.3
, SQL Server.
. * .

SQL Server 7.0 , , . SQL Server 7.0 25,


SQL Server 2000 43.
, . . -

15.

739

, , .
15.3. ,
SQL Server 2000

Application
Name

, SQL Server.
, ,

.

BinaryData

ClientProcessID

,
,

Column
Permission
CPU

( ),

Database ID*

,
,

Database Name*

, ,

Duration*

End Time*

,
,

Error
Event Class*

EventSubClass

FileName

Handle

, . ODBC, OLE DB
DB-Library

Host Name

, ,

Index ID

, ,

Integer Data

LoginName

, .
SQL Server,
Windows NT

740

III.
1S.3 ()

LoginSID

, .
SQL Server,
Windows NT

Mode

NestLevel

. , @@NESTLEVEL

NT Domain Name

Windows NT. ,

NT Domain Name

Windows NT, ,

NT User Name

Windows NT ,

Object

ID

Object Name

Object Type

OwnerName

Permissions

, :
1 (SELECT A L L )
2 (UPDATE A L L )
4 (REFERENCES A L L )
8 ( I N S E R T )
16 (DELETE)
32 (EXECUTE)
4096 (SELECT ANY)
8192 (UPDATE ANY)
16384 (REFERENCES ANY)

Reads

RoleName

Server Name
Severity .

SQL Server,

741

15.

15.3 ()

SPID

(SPID), ,

SQL User Name

Start

Time

State

Success

1 , 0

TargetLoginName

, (, )

TargetLoginsID

,
- (, )

TargetUserName

, - (, )

TextData

Transaction
Writes

ID

,
,

. , .
, ,
. , .
(filters). ,
.
, .
SQL Server 2000 :
Like. .
,
Profiler.
? Not Like. ,
.
Equals. .

742

III.

D Not Equal to. .


Greater that or equal. , .
Less that or equal. , .

Like/Not Like
SQL Server Profiler. , SQL Server
Profiler , .
. ,
SQL Server Profiler, .
SQL Server Profiler
, , . SQL Server Profiler, , .
, . .
,
, .
, . , .
, , BinaryData, I n t e g e r Data
Text Data, .

Sessions
Sessions .
, , , , . SQL Server 2000.
,
. . 15.4 Sessions.
1S.4. Sessions

Connect

BinaryData ,
SET.


, , Sessions
,
.

Objects
, .
, , ,
, , . ., ,
Transact-SQL SELECT, INSERT DELETE.
.
, Objects . NT User Name, SQL User Name Host Name
.
. 15.5 Objects , .
15.5. Objects

Scans
SQL Server
, .
.
, , , , WHERE. , .
, , , .
, . . .
EventSubClass. -. 15.6
:.
15.6. Scans

(Normal)

32

(Reserved)

(First)

64

(Exlatch)

(Back)

128


(Index supplied)

(Unordered)

128

16

(No data)

256

(Marker)

, . 15.6, . .
. ,

15.

745

. , , , 266
(2+8+256).

. 15.7 Scans
.
15.7. Scans

TSQL
,
(RPC), Transact-SQL.
TSQL .
S t a r t Time, End Time D u r a t i o n ,

. , . NT User Name SQL User Name


, .
, TSQL, . 15.8.
15.8. TSQL

746

///,
15.8 ()

SQLStmtCompleted


Transact-SQL

I n t e g e r Data ,

TextData ,

Cursors
,
: , , , , . .
SQL Server 2000 .
. 15.9
1S.9. SQL Server 2000

Keyset ()

, , ()

Dynamic
()


. ,

Forward only
()

Static ()

. ,
,

16

Fast Forward
(
)

, . ,
(Forward-only),

,
. 15.10.

Cursors,

15.10. Cursors

CursorPrepare

()

EventSubClass

15.

747
15.10 ()

Stored Procedures
Stored Procedures
. SP.CacheHit SP:CacheMiss
, .
SP:CacheMiss ,
, SQL Server 2000.
-, SQL Server 2000.
SP:CacheHit ( object I D ) , .
. 15.11 Stored Procedures
.
15.11. Stored Procedures

Error and Warning


Error and Warning , ,
SQL Server 2000 (, OLE DB). ,

. , Missing Column Statistics
, , , . -

15.

749

, , . ^ , .
Execution Warning ,
, . ,
.
Locks.
. 15.12 Error and Warnings
.
15.12. Error and Warning

Transactions
,
. , , , (MSDTC, Microsoft Distributed Transactional Coordinator).
Transactions , , (Save point) .
, . , .
, . ,
.
, Transactions
.
. 15.13 Transactions .
15.13. Transactions

15.

751

Locks
Locks SQL Server 2000. , . , Lock:Acquired
Lock: Released , ,
.
, . .
(deadlock).

SQL Server 2000 . ,


. - , . , , . ,
, , .
, , 1205.

Lock:Deadlock, Lock:Deadlock Chain Lock:Timeout. , ,
, .

, .

.
. 15.14 Locks
.
15.14. Locks

25

207

Databases
Databases , .
. . 15.15 Databases.
15.15. Databases

753

15.

15.15 ()

Performance
(DML, Data Manipulation Language). INSERT, UPDATE, SELECT DELETE, , , , , .
, (. 15.16) .
15.16. Performance

25*

Server
,
MSSQLServer. . 15.17 .
15.17. Server

Security Audit
. SQL Server
. Security Audit , . SQL
Server 7.0 . SQL Server 2000 . Security
Audit . , . ,

15.

755

LoginsiD LoginName, , .
(Database Name, Database ID, RoleName, SQL User Name, Permissions, OwnerName,
Object Name, Object ID, Column Permissions . .) . 15.3.
( Event c l a s s ,
Eventsubciass . .) . 15.18,
. , Event c l a s s .
.
, . ,
Event c l a s s .
15.18. Security Audit

756

III.
15.18 ()

Audit Object
GDR Event


GDR

Event Class = 103


EventSubClass :
1 (GRANT)
2 (REVOKE)
3 (DENY)
P e r m i s s i o n s :
1 SELECT ALL
2 UPDATE ALL
4 REFERENCES ALL
8 INSERT
1 6 - DELETE
32 EXECUTE
4096 SELECT ANY
8192-UPDATE

ANY

16384 REFERENCES ANY,


L o g i n s ID, LoginName,
Database ID, Database Name,SQL
User Name, OwnerName, Object
Name, Column Permission
TextData
Audit Addlogin
Event



SQL Server (
sp addlogin
sp droplogin)

Event Class = 104


E v e n t S u b C l a s s :
1 (Add)
2 (Drop),
LoginSID, LoginName,
TargetLoginSID,TargetLoginName
TextData

Audit Login
GDR Event


GDR ,
Windows NT
(
sp grantlogin,
sp revokelogin
sp denylogin)

Event Class = 105


EventSubClass :
1 (GRANT)
2 (REVOKE)
3 (DENY),
LoginSID, LoginName,
TargetLoginSID, TargetLoginName
TextData

757

15.

15.18 ()

15.18 (

LoginSID, LoginName,
Database ID, Database Name, SQL
User Name, Target User Name
RoleName

Audit Add Role


Event




( sp add r o l e
sp droprole)

Event Class = 111


Event Sub Class :
1 (Add)
2 (Drop),

LoginSID, LoginName,
Database ID,Database Name, SQL
User Name RoleName
Audit App Role
Change Password Event

Event Class = 112


Event Sub Class 1,
LoginSID, LoginName,
Database ID,Database Name, SQL
User Name RoleName

Audit Statement Permission Event

Event Class = 113


EventSubClass 1
Permissions :
1 CREATE DATABASE
2 CREATE TABLE
4 CREATE PROCEDURE
8 CREATE VIEW
16 CREATE RULE
32 CREATE DE FAULT
6 4 - B A C K U P DATABASE
128 BACKUP LOG
512 CREATE FUNCTION,
L o g i n S I D , LoginName,
D a t a b a s e I D , D a t a b a s e Name, SQL

User TextData

Audit Object
Permission
Event

Event Class = 114


EventSubClass 1
Permissions :
1 SELECT ALL

759

15.

15.18 ()

2 UPDATE ALL
4-REFERENCES ALL
8 INSERT
16 DELETE
32 EXECUTE,
LoginSID, LoginNarae,
D a t a b a s e ID, Database Name, SQL
User Name, OwnerName, Object
Name, Column P e r m i s s i o n
TextData

Audit
Backup/Restore
Event

Event C l a s s = 115

(BACKUP

Event Sub C l a s s :

RESTORE)

1 (Backup)
2 (Restore),
LoginSID, LoginName,
Database ID, Database Name, SQL
User Name TextData

Audit DBCC
Event


DBCC

Event Class = 116


EventSubClass 1,
LoginSID, LoginName,
Database ID, Database Name, SQL
User Name RoleName

Audit Change
Audit Event

Event C l a s s = 1 1 7
E v e n t S u b C l a s s :
1
2 ,
LoginSID, LoginName
TextData

Audit
Server/Stop/Pa
use Event

Event Class = 118


Event Sub C l a s s :
1 (Shutdown)
2 (Start)
3 (Pause)
4 (Continue),
LoginSID LoginName

760

III.

User Configurable
, .
. 10 , UserConfigurable:0 UserConfigurable:9.
.

sp_trace_generateevent, :

sp_trace_generateevent [ @eventid = ] event_id


[ , [ @userinfo = ] 'user_info' ]
[ , [ Ouserdata = ] user_data ]


sp_trace_generateevent
xp_trace_generate_event, .
:
[ Oeventid = ] event_id

i n t
, .
8291,
UserConfigurable:0UserConfigurable:9. .
d I Ouserinfo = ]

'user_info'

, nvarchar (128),
,
. , ,
TextData. ,
TextData NULL.

, g u s e r i n f o Unicode. N. ,
Suserinfo = N'No more data for t r a n s l a t e ' .
t Suserdata = ] user_data


varbinary(8000), . . .
BinaryData.

15.

761

.
.
, BinaryData
17FA, Suserdata = 0xl7FA.
UserConfigUrable:5. TextData ' ! ! ! ', BinaryData 0x28305FC3B:
EXEC sp_trace_generateevent
Seventid = 87, @userinfo = ' ! ! ! ',
Suserdata = 0x28305FC3B

TextData BinaryData , :
Application Name;

LoginSID;

Database ID;

O NT Domain Name;

Host Name;

NT User Name;

LoginName;

Server Name.


SQL
Server 2000, SQL
Server Profiler. , ,
. .

SQL Profiler , , Programs () Microsoft SQL


Server SQL Server Profiler Tools Enterprise
Manager. , Profiler ,
s q l t r a c e . e x e .
,
. , ,
(trace profile). SQL Server Profiler , . , . , , , ,
, .

III.

762

SQL Server Profiler . (Trace Definition)


, (Trace File) (Trace Table).
, SQL Server Profiler.
(. 15.14). ,
, . ,
Profiler , .

. 15.14.
SQL Server Profiler
File New, a
Trace <Ctrl>+<N>. Connect to SQL Server (. 15.15),
,
.

. 15.15. Connect
to SQL Server

15.

763

, Connect to SQL Server , Trace Properties (. 15.16),


. , .

. 15.16. Trace Properties, General


General , :
Trace name .
Trace SQL Server , .
Template name.
.
, , . , Trace
Properties.
. ,
, Transact-SQL . .
.

764

III.

Template file name. , , Template


name. SQL Server Profiler , \Program Files\Microsoft SQL
Server\80\Tools\Templates\SQL Profiler.
, . ,
. , . Template name.
Save to file. .
, . , , . :
Set maximum file size (MB) , , .
;
Enable file rollover ,
, . , Save to file,
. , SampleTrace.trc,
SampleTrace_l.trc,
SampleTrace_2.trc . .

Server processes SQL Server trace data ,


,
. , . , .
, , , .

(U Save to table. .
.
, . ,
. Run. . Save to table
1 Set maximum rows (in thousands), , -

15.

765

, . ,
.
, .
Enable trace stop time. , , . , , ,
, .
General . Events
(. 15.17) ,
.

. 15.17. Trace Properties, Events


. (Available event classes)
. (Selected event classes) , .
.
Add Remove. -

766

III.


.
, , , Selected event classes, .
Data Columns (. 15.18)
, .

. 15.18. Trace Properties, Data Columns

Data Columns Events.


Unselected data . , , Selected data. Up Down .
, ,
. . ,
,
Filters (. 15.19).
Fitters , . , ,

15.

767

. . " SQL Server Profiler" .

. 15.19. Trace Properties, Filters


.
, SQL Server Profiler .


, , SQL Server Profiler
. ,
. (. 15.20).
, ( ).
.
j j j , . , -

768

III.

. ,
.
. , , SQL Server Profiler.

. 15.20. SQL Server Profiler

, SQL Server Profiler


, . , .
. . , , .
,
, , .
(replay) Replay.
, . , .

15.

769

.
file Save as.
Replay
Start, Step. Connect to SQL Server (.
. 15.15), , . , .
Connect to SQL Server
Replay SQL Server (. 15.21), .

. 1 5 . 2 1 .
Replay SQL Server

Replay SQL Server , . , . ,


. Output file name
, ,
.
Replay Options
:
Replay events in the order they were traced. This option enables debugging. ,
. .
,
.
, .
Replay events using multiple threads. This option optimizes performance and diasbles debugging. . , ,
, . -

770

III.

, ,
. , , ,
. .
.
Start Replay.
SQL Server Profiler .

Transact-SQL
, SQL Server 2000
. SQL Server 7.0
SQL Server Profiler
Extended Procedures. , , . SQL Server 2000 , .
SQL Server Profiler

SQL Server Profiler. . SQL Server Profiler
, .
, , - .

SQL Server
Profiler. ,
. SQL Server 2000

MSSQLServer. .

, SQL Server 2000 DBCC, -

.
, . .

. , SQL Server Profiler,
.

16


, , ,
.
,
.

.
. 13
,
, . , .
, ,
, SQL Server 2000. ,
, 14, . ,
.
(DTS,
Data Transformation Services), 11. DTS . .
SQL Server 2000,
.

. , ,
.
,

. , .
.
, .

772

III.

24x7. , 24 7 , . .

. .
.
SQL Server 2000 ,
:
. , .
. SQL
Server 2000, . ( 2 4).

.
RAID , .
.


(standby server),
(warm backup), ,
.
,
, .
, .

, .
, KOMnbratepe. .
, .
, . , .
. , .

16.

773

, .
(read only mode).
,
, . . , . ,
, . ,
.
:
. ,
. ,
. , , .

. .

,
Master . .
. ,
(standby mode).
RESTORE STANDBY.
(read only mode). , ,
.
,
.
, ,
,
. ,
, (undo file).
STANDBY . .
.

774

III.

.
, .
, . .
STANDBY , .
.
.

, . RESTORE
RECOVERY BMeCTO STANDBY.

Transact-SQL,
.
USE master
GO
RESTORE DATABASE MyNwind
FROM MyNwind_l
WITH STANDBY = 'c:\undo.ldf
GO
.
RESTORE LOG MyNwind
FROM MyNwind_logl
WITH STANDBY = ' c : \ u n d o . l d f 1
GO
.
RESTORE LOG MyNwind
FROM MyNwind_log2 \
WITH STANDBY = ' c : \ u n d o . l d f
GO
-T
, .
.
:
BACKUP LOG MyNwind
MyNwind_log3
WITH NOJTRUNCATE
GO

.
.
RESTORE LOG MyNwind
FROM MyNwind_log3
,
. ..
.
.
WITH STANDBY = 'c:\undp.ldf'
GO

'

'

"

"'

"

'

'

'

'

'

'

'

'

16.

775

-- () ,
.
RESTORE DATABASE MyNwind
WITH RECOVERY
GO




. :

.
,
, ;
.

, .
,
.
(failover support).
.
. Enterprise Edition
Windows NT Server,
SQL Server 2000. Windows 2000
Windows 2000 Advanced Server Windows 2000 DNA.
, SQL Server 2000.
Enterprise Edition .

,(

, . .
SQL Server 7.0
. SQL Server 2000 ,
, . ,
, . ,
, (virtual server). (nodes). -

III.

775

Clustering Service.
,
. . 16.1.

SQL Server 2000 .

Windows NT
Server
. 1 6 . 1 .


. .
SQL Server 2000 . , .

. ,
.
64.
,
. , (primary server),
,
. Clustering Services ,
, ,
(secondary server). , .
, . , .
;

777_


. . ,
. , .
. '
, .

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


:
"-" (active/passive failover configuration).
(. 16.2)
, .
,
, .

. 16.2. "-"

"-" (active/active failover configuration).


(. 16.3) , .
*:
. -

778

III.

. .
, .
. "-"
, .

16.

779

^ ,
RAID:
RAID 0 (Striping Set).
RAID I (Mirror Set).
RAID 2 , ,
. XOR . .
RAID 3 RAID 2 , .
" ". RAID 3 RAID 2.
RAID 4 ,
RAID 3. , , /.
RAID 5 (Striping Set
with Parity).
RAID 2, RAID 3 RAID 4 .
Windows NT .
RAID , RAID 1 RAID 5. .
RAID :
. RAID
, . " " , : . ,

.
, ,
. RAID
.
. RAID
.
,
.
.

780

III.

RAID
, . . SQL
Server 2000. RAID .
RAID- SQL Server 2000
.
SQL Server 2000 , RAID,
, , , , FAT.
, RAID,
. RAID .
RAID.



,
. , . . RAID 1,
:
;
.
,
, . . , . (original disk).
. .
(shadow disk). ,
,
.
.
. ,
.
, , . ,
.

16.

781_

.
, . . ,
.
RAID 1 .
. , . . Windows NT .
RAID 1 RAID. . ,
.
, .


RAID 0 RAID 5 (striping
disk set). , . , .
.
, . , , .
64 .
. . .
. ,
. , 5,
5.

. ,
.
, . , , .
.
RAID 0 RAID 5 .

782

III.

RAID 0 "" . RAID 0 2 32 .


,
. , RAID
,
.
RAID 5 . . .
RAID 5 ,
.
, .
. ,
,
, ,
. .
, RAID 5,
,
.
. ,
33% .
, 10%.

" " () .
. ,
,
.
RAID 5
. , SCSI . , , ,
. ,
RAID 5
/.
RAID 5
SQL Server 2000.
RAID 5
.

IV.


17.
18.
19.
20.
21.
22.
23.
24.

2 6 . 1207

17


, ,
.
, SQL Server 2000.
, , SQL
Server 2000 . , ,
. .
, . ,
, , ,
"" . , , .
, , .
.
, , . ,
.


.
, .
:
.
,
.
. ,
.
26*

786

IV.

.
:

-.

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

-. ,
,
.
(SQL, Structured Query Language), ,
.
. . , , , . ,
. .
-
,
. , ,
-. , .
-
. - .
, , .

17.

787

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

Microsoft SQL Server 2000


-. SQL Server 2000 , . (distributed query) .

SQL Server 2000, ,
ODBC .



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

().

(entity), (attribute). ( )
, , . , , , . . ,
, , , : , , ,
. . . "" ,
.
, (,
. .). ,
, ,
, , , , , ,

788

IV.

. .
, ,
. , : , , , . . , .
, , , . (field) . :
(name);
, (, , . .);
( ), ,
;
(, , , . .).
(record).
, . , .
(table).
(, ). .


.
( ) . (data model)
.
, . , .
.
:
. , . ( ). ,
( ) . , . ( . . ) . ,

17.

789

. . , . . . .

. . , ( ) , , (, , ,
. .), , , .
.
DNS.
. ,
, . ,
, . . ,
.
, .
. ,
.
.
,
.
, .
,
.
,
.
. , . .
,
,
.
Microsoft SQL Server 2000,
, . SQL Server 2000 -.


6 1970 .,
IBM, . , "
" ("A relational Model of Data for
Large Shared Data Banks").

790

IV.

" ".
60- . , .
. , .
, . , , , , . ,
,
"". ""
"relation". " ".
.

, .

:
;
(, . .);
;
;
.

, , .
, ,
, , , , , . 17.1.
17.1.

18735

13.08.78

27

18745

22.03.77

42

18543

17.11.76

42

18545

21.09.80

27

18732

07.10.72

34

17.

791_

, , , .
. , . .

,
. ,

, : , , , ,
. , .

,
.
, SQL Server 2000
. . . 17.2
.
17.2.

SQL Server 2000

(Entity)

(Relation)

(Table)

(Tuple)

(Record)

(Row)

(Attribute)

(Field)

, (Column)

,
. ,
"" "".
SQL Server 2000 ,
. , dBase,
FoxPro, Access ., , .

,
(domain). .
. , , .
, . . 17.1
, , . .
4 : , , . 5 .

792

IV.

, ,
. ,
() . .

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

~)

( ) " ". .
""
. .

,
. . Microsoft SQL Server 2000, .


A [ I , J ] , , i
, j .
( ) . , , , -. ,
. 17.1, 6.
A[i, j] i j
, , .
( ). , , .

, ,
.

, .
, - -

17.

793_

, .
(key).
, . , . 17.1, " "
"", "" "".
" ".
.

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


, :
. , . . , , , .
.
. , ,
.
, .
. "", ""
""
. , , . . ,
.

SQL Server 2000 . . SQL Server 2000


, , , .

IV.
,
.

,
. , ,
.
. , , . , . 17.1,
, "",
"" "" .

. .
.
, , ,
, .
, . , . , Microsoft SQL Server 2000
. ,
. ,
,
.


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

17.

795

, , (
), , .


,
. ,
. .

(relationship) , , (relation), .
, .
(relationship relation) .
.
SQL Server 2000 Pubs NorthWind. SQL Server 2000,
.
SQL Server 2000 (Diagram).
, .
Enterprise Manager
Diagram. Enterprise
Manager .
, , ,
.

. .

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

IV.

796


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

. . , , .
.
,
.
(

~)

SQL Server 2000 , . SQL


Server 2000 ,
. SQL Server 2000
, ,
. ,
. , ,
.

, . , ,
,
. . 17.3 , . 17.1.
17.3.

17.
(

797

, . ,
. , SQL Server 2000
N u l l .
.
SQL Server 2000.

,
.
SQL Server 2000 Enterprise Manager
.
. 3.


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

IV.

798

. . 17.4
, .
17.4.

36

10

. . 15

36

10

27-2

36

10

. .

18

44

. . 15

. .

38

. .

27-2

. .

38

. .

27-2

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

17.

799

,
( ).
:
,

. , . . .

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

, .
.
,
.
,
.
. :
(INF, First Normal Form). ,
, .
, , . , , ,
, . .
(2NF, Second Normal Form).
, , ,
. ,

800

IV.

.
, . , .
,

. , ,
.
. ,
.

(~

, . . . SQL
Server 2000 ,
, . IDENTITY.
(3NF, Third Normal Form).
,

.

. .
. ( ) .
- (BCNF, Brice-Codd Normal Form).
- ,

.

- , .
(4NF, Fourth Normal Form). ,
. , .

17.

801

, . , .
, ,
.

,
.
- (5NF,
Fifth Normal Form PJ/NF). , . ,
.
, , . . , . ,

. ,
. , ,
,
.


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



(primary) (foreign) . ,
. ,
. , , ,

802

IV.

. ,
SQL Server 2000 .
.

,
, (Null).


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

, SQL Server 2000 . ,


,
IDENTITY. .

. . ,
. , .
, . ,
, . . Null.
, .
, .
,
,
. , .
UNIQUE .

17.
(~

803

SQL Server 2000 (FOREIGN KEY)


, . , UNIQUE PRIMARY KEY,

, , ,
. - , , .
, . , , ,
. , . . . .
SQL Server 2000
, .
( UPDATE) SQL Server 2000 :
(Relation).
, SQL Server 2000 (NULL).
, .
. , , .
(Restrict). SQL Server 2000 ,
, .
,
,
. ,
, , , (NULL).
(Cascading). , .
SQL Server 2000

804

IV.

. .
.
. . ,
. ,
, .
SQL Server 2000
:
(Relation). SQL Server 2000
(NULL). .
(Restrict). ,
, ,
,
. ,
(NULL), .
(Cascading).
.
.

Cascading, . .
. Relation , .
.



.
. :
-- (One-to-one). "--"
(1:1) (
) . , .
.
. .

17.

805

-- (One-to-many). "--"
(1:) ,
. , . . "--" "--".
-- (Many-to-many). ,
,
. .
.
, .

"--",
. .
"--".

, SQL Server 2000. SQL Server 2000


"--". . "--" . UNIQUE.
.
"--" SQL Server 2000 .
"--" . .
, . . , ,
. , "--".
, .

"--" a u t h o r s
t i t l e s Pubs, -

t i t l e a u t h o r .

...........

18


SQL Server 2000 (database).
SQL Server 2000 ().
, ,
. SQL Server 2000 :
. SQL Server 2000
.
,
. ,
: , , . . , ,
.

, ,
, , , , .
SQL Server 2000 . , ,
.

, ,
. , , , , , .
SQL Server 2000 ,
.
, .
.
, ,
, .
,
. , ,
, .
, ,

18.

807

. .
. , .
SQL
Server 2000, 14.


SQL Server 2000
SQL Server 7.0,
. SQL Server 7.0 (devices), SQL
Server 6.x. , , . , ,
. ,
.
SQL Server 2000 , , . ,
.
.
.


, . .
SQL Server 2000 :
(data file). , . , , , , .
(transaction log file). SQL
Server 2000 .
,
,
.

. , , 2.
. ,
.
, .

IV.

, ("" ), . .
, ,
.
,
. NTFS , SQL Server 2000
.
, SQL Server 2000, , . ,
. .
:
Primary File ( ).
.
, .
, .
,
, . Master ,
. ,
.
mdf (Master Data File).
Secondary File ( ). , .
. .
.
. NDF (secoNdary
Data File).
Transaction Log File
( ), .
.

, . SQL Server 2000 , , -

18.

809

.
ldf (Log Data File).
. mdf, ndf Idf, ,
.
. ,
. . .
, .
:
OS File Name ( ) . ,
SQL Server 2000 Windows NT
.
Logical File Name ( ) , SQL
Server 2000 . .
, . SQL Server 2000 .
.
SQL Server 2000 .
.
. .

. ,
. , , , , . .

(~

,
.
. .

:
Primary File Group . ,
(primary file) , , . , -

810

IV.

.
, , .
(primary file) .
User File Group .
.
. , .
Default File Group . , . ,
. , , .
, . .
. .
, , " " (read only).
. , . SQL Server 2000
" ". . ,
. " "
.
" " , .
, , , , (primary file). , .
, , , . .
" "


. " "
-, .
.
SQL Server 2000 ,
, 13. . -

18.

8_

, " ", . .


sysadmin db_owner. dbbackupoperator .
SQL Server 2000
. SQL Server 2000
. , ,
. ., SQL Server 2000
.
, ,
. SQL Server 2000 ,
. , : 10 , 20
30 . 180 , . :
( 10 ) 30 ,
60 , 90 .

/ . . SQL Server 2000
.


, ,
. SQL Server 2000 .
.
. ,
, . , .
. . , , . ,
.

812

. IV.

SQL Server 2000


(page). , SQL Server 2000.
/ SQL Server 2000 , .
, . .
SQL Server 2000 8 .
SQL Server 7.0. SQL Server 6.x
2 .
. ,
. char, nchar, varchar, nvarchar binary 8000 .
, Unicode,
4000. ,
2 . ,
SQL Server 6.x 2000 .

, 8 8192 .
8000 . , ? .
, 8000 ,
, 8060 . , 8060 .
.
, ( , ). , ,
.
:
Data.
. Data image, t e x t ntext.
Index. . , .
d Tex^mage. ,
image, t e x t n t e x t . , . ,
, Data.
image, t e x t n t e x t
. .

813

18.

SQL Server 2000 image, t e x t n t e x t Data, .


Global Allocation Map (GAM).
.
(), .
Page Free Space (PFS).
.
Index Allocation Map (IAM).
, .
.
GAM, IAM PFS. ,
Data. . 18.1 , .

. 1 8 . 1 . Data

, , , , ,
, . . 96 , , (8192-8000=192=96x2). .
.
,
(),
. ,
, .
,
.
(varchar, nvarchar varbinary). ,
,
, .

. 18.1 , ,
, ,
, . -

814

IV.
,
, . .
,
( ).

,
. ,

, (96 ). .
,
. . (row offsets). ( , ), .
.
, . . , .

, ,
SQL Server 2000.
(extent), 8 . , 64 . ,
.
, (
).
,
, .
, , .
:
Uniform. (. 18.2, ) ,
. , . .
8 , , , ,
. .
, . .
.
Mixed. (. 18.2, ) , . . Uniform,

18.

815

64 (8 ),
- , . ,
,
8,
64 . .
, .
Mixed

. 1 8 . 2 . SQL Server 2000

, .
, , .
, , . .
, Global Allocation
Map (GAM) . , . ,
GAM , , . GAM
, . 8 , GAM 64 000
(8000) (8). , , GAM
4 64 000 8 8192 .
, GAM
, :
Global Allocation Map (GAM). . 1, .
0, - .
27

.1207

gjg

IV.

Shared Global Allocation Map (SGAM). . 1, Mixed,


. 0, ,
Uniform ( ),
Mixed, .
, GAM, SGAM 1. ,
. :
8 , .
Uniform. To . GAM , 1.
. GAM SGAM 0.
8 , . Mixed,
, Mixed. GAM , 1.
. GAM 0, SGAM ( 1).
Mixed, 0
SGAM.
, 4 ( 3,95 )
GAM, 16 .
, .
, GAM .
. , - ,
. , , .
( ) Page Free Space (PFS).
8000 Data, Text/Image
Index. , 1 . . , . ,
. .
, :

81% 95%;
96% 100%.
PFS , . , . .
, , . .
PFS
,
.
, PFS , . ,
, .
Index Allocation Map (IAM). 1 , . , (
) IAM.
1 GAM. 1, , . IAM 0,
. , IAM 4 (3,95 ), 64 000 .
, IAM. IAM.
. . 18.3
IAM .

. 18.3. IAM
27*

IV.

(~

, IAM .
, IAM .
.
, IAM?
IAM FirstiAM
sysindexes. IAM,
IAM , . sysindexes
, IAM. ( ), , t e x t , n t e x t image.

sysindexes . , s t a t b l o b , xmaxien
, m i n i e n , keycnt . .

, SQL Server 2000 t e x t , n t e x t image


Data, . .
, .
,
. , . , ( ) IAM
, . , . . 18.4
. , (
) IAM.
, , , . .

IAM , , .
. 18.4, . .
. FAT.

819

18.

, . , , .
.
sysindexes

FirstlAM

. 18.4.
SQL Server 2000 .
, .
DBCC SHOWCONTIG.
DBCC

DBREINDEX DBCC

INDEXDEFRAG.

,
25.

, .
, .
, .
. 18.5 . ,
.
. . . . , PFS .
GAM SGAM
. .
Data. IAM.

. 18.5.

S20

IV.

, , , .


,
, .
.
, , , , , .
, , , . ., , , .
.
, :
(tables). ,
.
21,
28 29.
(views). (virtual tables), , .
. 22.
(indexes).
,
. , . 23.
(keys). .
. , ,
, .
(defaults). , ,
.
.

18.

821

(rules). ,

. .
(constraints). , . , .
21.
(stored procedures).
Transact-SQL, .
. ,
, . , 30.
(triggers). ,
,
.
.
32.
(user-defined data types, UDDT).
, .

.
(user-defined function).
Transact-SQL, . () SQL Server 2000,
27.
,
SQL Server 2000 .
. ,
, .
.
, ,
, . .


, -
. . , , . , , ,
( SQL Server 2000).

822

IV.

,
. , , .
SQL Server 2000 (). , . , . SQL Server 2000.
.

, , .
,
. ,
. ,
,
.
.
.
128 .
256 , . .
Unicode. 116 . 12 SQL Server 2000
.
, , SQL Server 2000. ,
SELECT CASE, . .
. , ,
.

,
_ (). , !, $ . . .
#,
, .
, Unicode Standard 2.0 , @, #, $ _.
, , , !, %, , &, ~, -, .
(), , (), \, * '.

18.

823

(collate), , , SQL Server 2000 ,


. SQL Server 2000 ,
, , ,
.
, ,
(Regular Identifiers). pubs.
sysobjects, Name
.
pubs:
USE pubs
SELECT TOP 10 Name FROM sysobjects

:
Name
authors
byroyalty
CHECK_CONSTRAINTS
CK authors au_id 08EA5793
CK authors z ip 0AD2 A0 0 5
CK jobs max_lvl 25869641
CK jobs min_lvl 24927208
CK publisher pub_i 0DAF0CB0
CK_emp_id
COLUMN_DOMAIN_USAGE
(10 row(s) affected)

SQL Server 2000


(Delimited Identifiers).

. , SQL Server 2000 , , , . . , , - .
SQL Server 2000
, . ,
, .
, , , , , . , . .

824

IV.

, , ,
,
:
CREATE TABLE [3 . 2001 - ]
([01-09] i n t , [10-39] i n t , [] money)

:
CREATE TABLE "3 . 2000 - "
("01-09" i n t , "10-39" i n t , "" money)

~~)

.
. , , .

, .
, (double quotation marks).
SQL Server 2000 . ,
SQL Server . (single quotation marks). To ,
, . , ,
.
SQL Server 2000 .

.
:
SET QUOTED_IDENTIFIER {ON I OFF}

ON . OFF, TO
,
.
.
SET QUOTED_IDENTIFIER ON
SELECT au_fname FROM a u t h o r s , t i t l e a u t h o r
WHERE a u t h o r s . a u i d = t i t l e a u t h o r . a u id AND au l n a m e = " t i t l e i d "

18.

825_

authors,
( auiname) t i t l e id.
SET Q0OTED_IDENTIFIER OFF
SELECT au_fname FROM authors, titleauthor
WHERE authors.au_id=titleauthor.au_id AND au_lname="title_id"

authors,
aulname t i t l e id.
title__id ,
.

(au_lname)
( t i t l e _ i d ) .
pubs .

Transact-SQL . .
,
Transact-SQL .
, ,
[3 . 2000 - ], s p _ t a b i e _ p r i v i l e g e s :
sp_table_privileges @table_name_pattern = '[3 . 2000 - )'


SQL Server 2000
(owner). (full control) . , (
),
, .
,
.
.
:
sp_changeobjectowner [@objname =] ' o b j e c t ' ,

[@newowner =]

'owner'

, ,
[@objname =] ' o b j e c t ' . [@newowner =] 'owner'
.

. , -

826

IV.
db_owner, db_dlladmin db_securityadmin.
,
.

db_owner ,
.
,
. sp_changeobjectowner.
. , ,
. , , - .
(complete name) , , (full
qualified name) . :
[[[server.][database].][owner_name].]object_name

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

,
, . , , dbo.
, .
, dbo, , . . .
, . :
server.database.owner_name.object
server.database..obj ect_name

name

18.

827

server..owner_name.object_name
server...object_name
database.owner_name.object_name
database..object_name
owner_name.obj ect_name
object_name

(linked server) (remote server) . s e r v e r , database, ownername.


object_name.
10.

, , , , ,
. . . :
[[[server.][database].][owner_name].]object_name.column_name

, , SELECT UPDATE.

(, ), :
SQLSrvl.[KHSU Databases]..[RIAC People List]

, (defaults) ,

, . , , , ,
. ,

. , ,
.
, Microsoft
, , SQL Server 7.0,
Default, .

S28

IV.

, SQL Server 2000 . .


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

,
. -, , -,
. ,
, ,
.
, , . ( ) .
, , .
CREATE DEFAULT, :
CREATE DEFAULT d e f a u l t AS c o n s t a n t _ e x p r e s s i o n

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

18.

829

, . . , 20-11-2000,
. , ,
-1991, 20-11-2000, .
' 20-11-2000'.

, . " " .
.
,
GETDATEO


O r d e r D a t e O r d e r s

Northwind, .
OrderDate .
OrderDate
. ,
.

,
, . , , .
, .
. :
USE Northwind
CREATE DEFAULT def_GETDATE AS GETDATEO

OrderDate orders. ,

. :
sp_bindefault [ @defname = ] ' d e f a u l t ' ,
[ Sobj name = ] ' obj ect_name'
[ , [ Sfutureonly = ] 'futureonly_flag' ]


sysadmin, db_owner db_ddladmin, a
.

830

IV.

:
[ @defname =~ ] ' d e f a u l t '
, .

[ @objname = ] 'object_name'
,
. tabie_name. column name, .
, . ( ).

(~

,
timestamp, - ( IDENTITY).
, , .
,
( ), .
[ Sfutureonly = ] 'futureonly_flag'
'futureonly 1
NULL. 'futureonly 1
.
,
,
.
. , , . @futureonly NULL
( ),
,
.

. .
. ,
.
, .
sp_bindefauit.
OrderDate orders.
:
EXEC sp__bindefault 'def_GETDATE', ' Orders. OrderDate

18.

831

defGETDATE My data type:


EXEC sp_bindefault

'def_GETDATE',

'[My d a t a t y p e ] '

, ,
.
sp_unbmdefauit,
:
sp_unbindefault [ @objname = ] 'object_name'
[, [ gfutureonly = ] 'futureonly_flag']

:
[ @objname = ] 'object_name'

,
. sp_bindefault, .
[ gfutureonly = )

'futureonly_flag'

'futureonly'
MULL. 'futureonly' .
, , . ,
@futureoniy NULL (
),
, .
, OrderDate orders
:
EXEC sp_unbindefault 'Orders.OrderDate'

DROP DEFAULT,
:
DROP DEFAULT { d e f a u l t } [ , . . . n ]

, . , DROP
DEFAULT . . , ,
.
, ,
,
.
, def_GETDATE .
DROP DEFAULT d e f GETDATE

832

IV.

, , , .
,
. , . SQL Server 2000
. , .

s p h e i p t e x t , CREATE DEFAULT,
. ,
defGETDATE :
sp_helptext

'def_GETDATE'

:
Text
CREATE DEFAULT def_GETDATE
AS GETDATEO

Transact-SQL. SQL
Server 2000 Enterprise Manager.
Defaults (. 18.6), ,
.
,
.
, ,
.
New Default. Default Properties
(. 18.7).
Name Default Properties ,
, Value ,
.
, Transact-SQL.
. . 18.7,
Bind UDTs Bind Columns, , , .
. Bind UDTs Bind
Default to User-defined Data Types (. 18.8).
Name .
, ,
Data Type. Bind -

18.

833

. Future Only ,
, , . Bind Default to User-defined Data Types

, .

Mm
. 18.6. Defaults

. 18.7. Default Properties

834

IV.

. 18.8. Bind Default to User-defined Data Types

. 18.9. Bind Default to Columns

18.

835

. Bind Columns,
Bind Default to Columns (. 18.9),
.
Table ,
. Unbound columns
, .
Bound columns, .

, Enterprise Manager , , . ,
. - ,
. ,
, , .
Defaults
.

(rules) , , . ,
,
0 100. SQL Server 2000 , 0 100.
t i n y i n t 0 255. ,
, 0 100,
.
. , , . SQL Server 6.x , SQL Server 7.0,
Check.
Check
. ,
Check,
.

, ,
.

, , - -

836

IV.

. , .
, .
, TRUE (), . FALSE
(),
.
, CHECK, TO . CHECK
, .
.
,
. ,
.

,
, .
.

CREATE RULE,
:
CREATE RULE rule AS cendition_expression

, .
, .
. , , c o n d i t i o n e x p r e s s i o n .
,
. . , . ,
AND OR.
,
0 100:
CREATE RULE rule0_100 AS @value>=0 AND @value<=100 ,

, .
.
, .
.
, , , , -

18.

837

, .
, , GETDATE ().
15, TRUE,
.
CREATE RULE rulel AS DATEPARTIdd, GETDATE())<15 AND @a=@a

,
, L I T , DM STORAGE,
, MATRIX\Administrator :
1

C R E A T E RULE r u l e 2 A S ( H O S T _ N A M E ( ) I N ( ' L I T , ' D M ' ,


SUSER SNAMEf) I N ( ' M A T R I X X A d m i n i s t r a t o r ' ,
'sa'))

'STORAGE')
AND @a=@a

OR


, .
. sp_bindrule, :
sp_bindrule [ @rulename = 1 ' r u l e ' ,
[ Sobjname = ] 'object_name'
[ , [ @futureonly = ] 'futureonly_flag' ]


sysadmin, db owner db ddladmin, a
.
, sp bindefauit,
.
r u l e l
:
spjoindrule 'rulel', 'MyDT'


s p u n b i n d r u i e , :

sp_unbindrule [@objname =] 'object_name'


[, [Sfutureonly =] 'futureonly_flag']

:
DROP RULE { r u l e }

[ ,...n ]

, . ,
.

IV.

838

CREATE RULE,
, s p h e i p t e x t . , rule2 :
sp_helptext

'rule2'

:
Text
1

CREATE RULE rule2 AS (HOST_NAME() IN ('LIT , 'DM', 'STORAGE'} OR


SUSER_SNAME() IN ('MATRIXYAdministrator', 'sa')) AND
a=8a

Enterprise Manager Rules (. 18.10), .

. 18.10. Rules


Rules New Rule.
Rule Properties (. 18.11),
.

839

18.

. 18.11. Rule
Properties
Name , .
Text ,
. ,
condition_expression CREATE RULE.
, Rule Properties
Bind UDTs Bind Columns,
. , . . , .
.


SQL Server 2000 ,
.
. SQL Server 2000
(UDDT,
User Defined Data Type).
SQL Server 2000 . ,
,
.
. , phone, 9 NULL.
.
, .

840

IV.

. , .
,
, systypes,
. , .
,
, . .
, systypes.
, r e a l barrakuda:
UPDATE systypes SET [name] = 'barrakuda 1 WHERE [name] = ' r e a l '
:
DECLARE @aa barrakuda
SET @aa = -10.654
SELECT Saa
:
-10.654
(1 row(s) affected)
r e a l :
DECLARE @aa real
:
Server: Msg 2715, Level 16, State 3, Line 1
Column or parameter #-1: Cannot find data type real.
Parameter '@aa' has an invalid data type.
@
r e a l , . . . , ,
. , . .
.
s p a d d t y p e , :
sp_addtype [ @typename = ] type,
[ Sphystype = ] system_data_type
[ , [ Snulltype = ] 'null_type' ]
[ , [ Sowner = ] 'owner name' ]

841

18.

:
[ gtypename = ] type

, . .
( ),
.
[ @phystype = j system_data_type

, .
,
. systypes
, . ,
,
.
. , cursor, t a b l e , timestamp. . 18.1
, .
18.1.
I 'binary(n)'

Image

Smalldatetime

: b i t

Int

Smallint
Text

! 'char(n)'
i Datetime
Decimal
'decimal[(p[, s ] ) ] '
float
'float(n)'
sql variant

nchar(n)'

Ntext
Numeric
'numeric[(p[ , s J ) ] '
'nvarchar(n)'
Real

Tinyint
Uniqueidentifier
'varbinary(n)'
'varchar(n)'

i
;

Bigint

29.
[ Snulltype = ] 'null_type' ]

, ,
,
NULL. :
"NULL1 NULL ;
' NOT NULL NULL ;
' NONULL ' NULL .

842

IV.

gnuiltype ,
NULL SET A N S I N U L L D F L T O N

SET ANSI NULL DFLT OFF.

N U L L .
[ @owner = ]

'owner_name'

,
. , db__owner.
. , , s p a d d t y p e .
s p a d d t y p e , . phone char. 8 .
NULL ,
:
sp_addtype

'phone',

'char(8)',

'NULL'

,
.
:
DECLARE @aa phone
SET @aa='295469283758923' '
SELECT @aa

:
29546928
(1 row(s) affected)

,
8 , phone.
. :
sp_droptype [ @typename = ] ' t y p e '

, .
Enterprise Manager
User Defined Data Type (. 18.12).

18.

843

. 18.12. User Defined Data Type

. 18.13. User-Defined
Data Type Properties

:
Name ;

844

IV.

Owner ;
Base Type , ;
Length ,
;
Allow Nulls 1, NULL, 0 ;
Default , ;
Rule , .
UserDefined Data Type Properties (. 18.13), , User Defined Data Type New User Defined Data Type.
, User-Defined
Data Type Properties.
Name. , . .
Data type.
,
.
Length. ( , ),
. ,
. , ,
,
, Length , .
Allow NULLs. NULL
, .
Rule.
. , .
Default. , .
Where Used ,
,
. , Where Used .
.

.

19


, .
. - , . .
. ,
. , ,
.
, . , .
,
. ,
. ,
,
. . , , SQL
Server 2000.


SQL Server 2000 . (transaction) , . , .
,
. ,
(distributed transaction) . SQL
Server 2000 , , , .

846

IV.

Transact-SQL
.
. . , , , , . ,
.
. , ACID
(Atomicity, Consistency, Isolation Durability), , . .
(Atomicity). , ,
. ,
, , , ,
, .
, ,
, .
(Consistency). ,
, ,
. ,

. , , , .
. (rules) (constraints), . SQL Server 2000
:

. ,
.
(rollback) , .
. ,
. ,
.
(Isolation). ,
, .
, ,
, . , , .

19.

847

, . . . ,
. ,
, ,
, . , . . ,
.
, . , , ,
. ,
,
. ,
.
.
, .
,
, ,
. "" "" (serializability).
(Durability). , ,
(commit transaction). ,
.
, , , .

, , ,
.
ACID
. , . SQL Server 2000, , ACID, . ,
, SQL
Server 2000 (locks).
, .
,
. ,
,
. . 28

.1207

S48

IV.

,
.
.
. .
, ACID SQL
Server 2000, . -, .
.
, -. ,
.
, .
. , ,
. . , -
. , , ,
, , (deadlock).

. SQL
Server 2000 , , .

. ,
, ,
. ,
,
.


(locks) , . ,
. SQL Server 2000
. ,
. . ,

19.

849

. , ,
, . ,
.
SQL Server 2000 ,

.
, . ,
SQL Server 2000 (Lock Manager).
SQL Server 2000 . , . ,
(page) (extent).
.
, .

. , . , .
, , .
,
, .
(The lost update problem).
. , . , . .
, , . .
, , . , . , .
, , , . , , . .
. .
"" (The uncommitted dependency problem). , , , . ,
. ,
28*

IV.

. ,
- . , , ,
.
(The inconsistent analysis problem). .
,

. , .
. . - , . ,
.
, , , . .
(The phantom read problem). ,
, . ,
. ( ) , .
, . .

,
. . (ANSI, American National Standard Institute)
. ,
, .

. :
Level 0 No trashing of data ( "" ).
, . . . . -
,
. .

19.

85?

Level 1 No dirty read ( "" ). "" . , ,


. , , . , , .
Level 2 No nonrepeatable read ( ).
. - ,
, .
. , . , , .
Level 3 No phantom ( ). .
,
,
.
, , . , .
,
. Microsoft SQL Server 2000 ,
.


SQL Server 2000 . .
.
(, ODBC)
, Transact-SQL.
(),
.
. ,
, .
. , , .
.

852

IV.


. . (single user mode).
,
.
SQL Server 2000 : , . ,
.
, . , , (distributed).

, SQL Server 2000 : .


.
.


. , . SQL Server 2000 .
,
, ,
. ,
. , .

, , ,
.
SQL Server 2000 (Autocommit transaction). SQL Server 2000
,
:
SET IMPLICIT TRANSACTION OFF

19.

853


(Explicit transaction)
, . .
SQL Server 2000
. ,
. ,
SQL Server 2000,
Transact-SQL,
. :
BEGIN TRAN. .

. :
BEGIN TRAN [ SACTION ] [ transaction_name I @tran_name_variable
[ WITH MARK [ ' d e s c r i p t i o n ' ] ] ]

transaction_name , .
SQL Server 2000. , 32 .
, @tran_name_variable.
char, varchar, nchar nvarchar. , .
. ,
.
SQL Server 2000 (mark
transaction). . .
SQL Server 2000 ,
.
. WITH MARK. ' d e s c r i p t i o n '
. .
SAVE TRAN. (save point).
,
. ,

854

IV.

.
.
, , , .
,
, ROLLBACK TRAN. SAVE TRAN:
SAVE TRANSACTION] {savepoint_name I @savepoint_variable)

savepoint_name .
BEGIN TRAN,
, SAVE TRAN
.
. 32 .

char, varchar, nchar nvarchar, @savepoint_variable.
ROLLBACK TRAN. .
, , , . ,
.
SQL Server 2000 ,
. , .
. , - . ,
. :
ROLLBACK [WORK]

ROLLBACK

[TRANSACTION]

[transaction_name

point_name I @savepoint_variable]]

@tran_name_variable

save-

ROLLBACK WORK , ROLLBACK TRAN

(. . ). , .
COMMIT TRAN. .
, SQL Server 2000 , .
, . ,

19.

855

.
COMMIT TRAN, :
COMMIT [TRAN[SACTION]

[transaction_name

@tran_name_variable]

, transaction_name @tran_name_variable ,
. COMMIT
, . , . ,
.
.
,
.
. , ODBC
. ROLLBACK TRAN
COMMIT TRAN, . ODBC . , ,
, .

ODBC , . . . OLE DB ADO


.


SQL Server 2000 , , (Implicit transaction)
, .
BEGIN TRAN, . . SQL Server 2000.
, , .
.
, . COMMIT TRAN ROLLBACK TRAN. ,

,
.

856

IV.

, SQL Server 2000 , , .

.
. ,
,
:
(ALTER TABLE);

(CREATE);
(DELETE);
f!J (DROP);
(FETCH);
(GRANT);
(INSERT);
(OPEN);
(REVOKE);
(SELECT);
(TRUNCATE TABLE);

(1 (UPDATE).

~^)


. , . , ,
. .

SQL Server 2000 :


SET IMPLICITJTRANSACTION ON

,
SQL Server 2000 , .
. . , ,

19.

857

. SQL Server 2000


.

,
, , . , . , .
Master.
, :
ALTER DATABASE ;
BACKUP LOG ;
CREATE DATABASE ;
DISK INIT (
);
DROP DATABASE ;
DUMP TRANSACTION (
);
LOAD DATABASE . SQL Server. SQL Server 2000
RESTORE, LOAD
DATABASE. SQL Server LOAD DATABASE,
, ;
d LOAD TRANSACTION . , LOAD DATABASE;

RECONFIGURE ,
sp_configure
SQL Server 2000;
RESTORE DATABASE ;
RESTORE LOG ;
UPDATE STATISTICS .


sp_dboption sp_conf i g u r e , , Master.
.

858

IV.


, , SQL Server 2000
, .
,
.
.
, , . SQL
Server 2000 .
(distributed query)
. , SQL
Server 2000 .
. . , SQL Server 2000
, . ,
- , . .
(distributed transaction) , . ,
. , . - ,
,
, . SQL Server 2000 MSDTC.
(MSDTC, Microsoft Distributed Transaction Coordinator) , . ,
.
SQL
Server 2000. MSDTC SQL
Server 2000, , . , Microsoft Visual C++
6.0 , MSDTC.
,
, (Resource Manager). To
,
. ,
, ,

19.

859

, , . ,
.
(Distributed Transaction Processing) MSDTC , . , , MSDTC. . MSDTC ,

. , , .
, , ,
.
SQL Server 2000.
, . SQL Server 2000.


SQL Server 2000, X/OPEN .


, : .
, MSDTC
.
.
. . ,
,
.
, , - .
, -

860

IV.

. (Durability) ACID ,
, , ,
. (Atomicity) ACID
, . - , . .
(2, Two Phase Commit protocol) ,

. :
(Prepare Phase). . , . .
. , . , , .
(Commit Phase). ( )
,
. , MSDTC
. , . ,
- . MSDTC , , . ,
. .



.
. MSDTC.
.
ODBC OLE DB . .

19.

861

, , , ,
. SQL Server 2000 .

SQL Server 2000 ,
REMOTE_PROC_TRANSACTION ON.
BEGIN DISTRIBUTED TRANSACTION, -

:
BEGIN DISTRIBUTED TRANSACTION] [transaction_name | @tran_name_variable j

,
B E G I N D I S T R I B U T E D TRANSACTION, , , ROLLBACK TRAN COMMIT TRAN, .

, . , ,
REMOTE_PROC__TRANSACTION.
, , .
:
EXEC sp_configure 'remote proc trans', {0 | 1}

, , , REMOTEPROCTRANSACTION . :
SET REMOTE_PROC_TRANS,

{ON

OFF}

, , , . ,
, , .


, Transact-SQL .
. ,

862

IV.

, (nested
transaction).

. ,
(save point). .
. . , .
.
, , . , ACID
. ,
, . , ,
, - , .

SQL Server 2000 ACID


. ,
.
ACID .

ACID.
BEGIN TRAN , COMMIT TRAN. SQL Server 2000 ACID
.

SQL Server 2000 . 32- .


, BEGIN TRAN ,
. ,
.

, -

19.

863

. , .
ROLLBACK TRAN COMMIT TRAN, BEGIN TRAN

,
B E G I N TRAN,
. , .

.

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


(Durability) ACID. .
, . ,
. ,
, . ,
, ACID.
, COMMIT TRAN
, . .
.
, , . .
SQL Server 2000 .
ROLLBACK TRAN
ROLLBACK WORK
.
ROLLBACK
TRAN. .
.

864

IV.


. ROLLBACK TRAN
.
SQL Server 2000 @@TRANCOUNT,
.
0. BEGIN TRAN
,
@@TRANCOUNT. ROLLBACK TRAN

. COMMIT TRAN
@@TRANCOUNT .
@@TRANCOUNT:
BEGIN TRAN trl
PRINT ' :
BEGIN TRAN tr2
PRINT ' :
BEGIN TRAN tr3
PRINT ' :
BEGIN TRAN tr4
PRINT ' :
BEGIN TRANSACTION tr5
SAVE TRANSACTION aaa
PRINT ' :
ROLLBACK TRANSACTION aaa
PRINT ' :
COMMIT TRAN tr5
PRINT ' :
COMMIT TRAN tr4
PRINT ' :
ROLLBACK TRAN
PRINT ' :

'+CAST(@@TRANCOUNT AS char(2))
'+CAST(@@TRANCOUNT AS char(2))
'+CAST(@@TRANCOUNT AS char(2))
'+CAST(@@TRANCOUNT AS char(2))

'+CAST(@@TRANCOUNT AS char(2))
'+CAST(@@TRANCOUNT AS char(2))
'+CAST(@@TRANCOUNT AS char(2))
'+CAST(@@TRANCOUNT AS char(2))
'+CAST(@@TRANCOUNT AS char(2))

:




*



:
:
:
:
:
:
:
:
:

1
2
3
4
5
5
4
3


, , ACID. -

19.

865

.

.
. , , (Concurrency Control).
, , .
, . :
sp_configure

' l o c k s ' , num_locks

num locks ,
. 0, . numlocks
5000 2 147 483 647.

96 .
2% , SQL
Server 2000. , , . , , 40%.

.
(Concurrency control theory)
:
(Optimistic Concurrency Control).

. ,
. ,
.
(isolation) ACID.
, .
,
, , , - . ,
, .

866

IV.

(Pessimistic Concurrency Control). ACID.


. ,
, ,
,
.
.
. , .
, .
SQL Server 2000 .
,
.
, . ,
.

(OLE DB, ADO, ODBC . .) .

,
, ,
.
SQL Server 2000 , , ACID, . ,
, .
, SQL Server 2000
(Lock Manager).
, , . ,
. , , ,
, ,
.
. ,
-

19.

867

.
.

.
, . SQL Server 2000 .

.
. , . ,
.

:
SET LOCK_TIMEOUT timeout^period

timeout_period ,
.
0,
, , . 1,
.

S E T L O C K _ T I M E O U T .
, . , .

@@LOCK_TIMEOUT.


, , .
, . ,
.
SQL Server 2000
:

868

IV.

. , ,
. SQL Server 2000 :
RID .
Key . (The phantom read problem).
, ,
, .
Page . .
.
Extent ().
, .
8 .
Table , .
DB .

SQL Server 6.x ,


2 . SQL Server 2000
.
, . " "
. ,
, . ,
.
. , , .

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

19.

869_

.

.


. ,
, .
, 20 , . , ,
. ,
70% , .
. . . .

(lock
escalation). .



, .
ANSI ,
. SQL Server 2000
, ANSI SQL-92.

. , (isolation) ACID. , .
SQL Server 2000 :
SET TRANSACTION ISOLATION LEVEL {

READ COMMITTED | READ UNCOMMITTED | REPEATABLE READ | SERIALIZABLE }

870

IV.

SQL Server 2000


:
READ UNCOMMITED

(The lost
update problem) 0 ANSI
SQL-92. SQL Server 2000. , . ,
, .
(dirty) (unrepeatable) . ,
, , .
READ COMMITTED


(The uncommitted dependency problem), 1 ANSI SQL-92. , ,
. , , , , , . .
. READ COMMITTED SQL Server 2000 .
REPEATABLE READ

, 2 ANSI SQL-92.
(The inconsistent analysis problem).
To , , .
SERIALIZABLE

,
. (The phantom read problem).
,
. , , , .


READ
COMMITED. .
, -

19.

871

, . SQL Server 2000 xunrrtu (hint), . SQL Server SELECT. SQL


Server 2000 UPDATE, INSERT
DELETE.


WITH,
. ,
t i t l e s , 15 .
.
SELECT title FROM titles WITH (ROWLOCK) WHERE price>15

, SQL Server 2000


:
ROWLOCK. .
, .
PAGLOCK.
.
TABLOCK.
. , TABLOCK
HOLDLOCK, TO . TABLOCK SELECT, .
TABLOCKX.
, . TABLOCK
, .
HOLDLOCK. ,
, . HOLDLOCK
SERIALIZABLE,
.
UPDLOCK. (update locks) (shared locks).
.
, , . , .
.

872

IV.

(~

NOLOCK.

,
NOLOCK. READ UNCOMMITTED.
READCOMMITTED.
READ COMMITTED. SQL Server 2000 .
REPEATABLEREAD.
REPEATABLE READ.
SERIALIZABLE. , HOLDLOCK. SERIALIZABLE.
READPAST. ,
, ,
.
SELECT. ,
READ COMMITTED.

. ()
. , , , NOLOCK. TO
, . SELECT.

READUNCOMMITTED.


: . , . , SQL
Server 2000 ,
. ,
.


SQL Server 2000 :
(S, Shared).
SQL Server 2000. -

19.

873

(read only operation)


. SELECT. ,
. , , .
.
(U, Update). ,
, .
. .
, .
, . .
,
.
, .
. , .

. , .
. , .
,
.
(, Exclusive).
.
, . , . ,
. .
(BU, Bulk Update).
TABLOCK. , , sp_tabieoption table lock
on bulk load.
/ ,
.
.

874

IV.

bcp.exe, BULK INSERT DTS.

. , SELECT
,
. ,
. .


,
SQL Server 2000,
.
. SQL Server 2000
:
(Intent Lock);
(Key Lock);
(Schema Lock).
. . , ,
,


.
, .

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

19.

875

, .
, .

(~

, .

SQL Server 2000 :


(IS, Intend Shared). -

,
. ,

.
, ,
, ,
.
(IE, Intent Exclusive). -

,
. ,
. ,
70% , ,
.
- (SIX, Shared with Intent Ex-

clusive). , .
, . .
, -
. - . .

, -

876

IV.

( IE). ,
. , (U) (), - .
,
- . - , .
, ,
.
SQL Server 2000 , , , . (Key Locks).
(The phantom read problem) (Serializable).
, ,
, . , .
,
.
, , , , - .
.
,
WHERE .
, . , ,
.
,
.

, . ,
,
;
SERIALIZABLE.

(Shm, Schema Locks).


(DDL, Data Definition Language).
ALTER. -

19.

877

, SQL Server, . .
SQL Server 2000 , , , . . ,
, . ,
systabies, . . systabies , .
, , , , ,
, . . .
SQL Server 2000 :
(Sch-S, Stability Lock).
. ,
. , ,

, , ,
, . ,
. ,
. .
(Sch-M, Modification Lock).
.
, , .
. ,
, ,
ACID.
,
.


,
SQL Server 2000 ACID
. , , . , , .

IV.

878

. . 19.1 SQL Server 2000.


19.1.


S
(S)

(U)

*
*

IS

IX

*
*

SIX

(X)
(IS)

(IX)

- (SIX)

, , ,
. , , , .
,
.

,
, . ,
, .
.


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

19.

879

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

(~


, . . . .
(deadlock) , ,
. ,
. ,
, .
.
,
. , .
. ,
, ,
.
.
.
:
SET LOCKJHMEOUT t i m e o u t _ p e r i o d

t i m e o u t p e r i o d . . ,
1, .

, -/
. , *
29

.1207

880

IV.

, . . ,
.
SQL Server 2000
,
. ,
.
.
,
, , . ,
. , . ,

, , ,
. ,
.
. .
, . , ,
1205 ( ).
, , ( ) . ,
. ,
:
SET DEADLOCK_PRIORITY {LOW | NORMAL I @ d e a d l o c k _ v a r }

LOW ,
.
NORMAL .
Sdeadiockvar .
3 LOW, 6 NORMAL.

.
,
.

,
- .
.
, , .

20


SQL Server 2000 , .
. , SQL Server 2000.
- .
,
(database owner); dbo .
18
SQL Server 2000. :
;
;
;
;
;
.
, Transact-SQL,
Enterprise Manager .



, , . , .
.

IV.

882

/.
"" ,
, .
, , . .

, , .
. ,

, .
.
, t e x t , n t e x t image,
. text, ntext image ,
.
t e x t , ntext image .
, .
, .
, , . . .
, .
, , , .
, , .
,
, .
SQL Server 2000 ,

. . . , ,
, .
, .

20.

883

SQL Server 2000



.
.


, SQL Server 2000 .
, ,
. , /
. , SQL Server 2000
.
, SQL Server 2000 .
.
, , . , . , .
, , . ,
.
. , , .
, .
, ,
, . . ,
, ,
,
.
, SQL
Server 2000 , .

.

, /. .

884

IV.


. SQL Server 6.x
.
,
, .
, . ,
.
7.0, SQL Server
.
( )
.
, .
, .
. , ,
. , , .
. ,
.
, , .
, . ,
. .
, , .
, ,
, , .
, . ,
. SQL Server 2000
.
, , .
, . , . . ,
.
,
. -

20.

885

,
. . ,
.
.


,
. SQL
Server 2000 (raw partition), , (fdisk.exe Windows 98, Disk Administrator Windows NT 4.0
Computer Management Windows 2000), . , .
, .
SQL Server 2000
.
.
, , . .

, , .
(attach) .
, . . SQL Server 2000. . .


SQL Server 2000
(collation),
. SQL Server, . . SQL
Server 7.0, ( ) ,
, . .
, , . ,
.

, , . 4.

886

IV.

SQL Server 2000 . , , , ,


- .
, SQL Server 2000 ,
pubs Northwind.
, , . . , , (case insensitive),
, . AUTHORS Authors
. , .
, (case insensitive),
.
,

, , ,
. , , .

, , . ,
. , SQL Server 2000
.

, ( GOTO),
,
.
. . ,
,
, , , .
, ,
. , , , . :
CREATE TABLE tbll (
Coll nvarchar(lO) COLLATE Latinl_General_CI_AS,
Col2 nvarchar(lO) COLLATE L a t i n l G e n e r a l C S A S

20.

887

t b i i ,
c o l l 12. , ,
. :
INSERT INTO tbll VALUES (N'Aaa1, N'AAa')

, , .
. :
SELECT * FROM tbll WHERE Coll=Col2

:
Server: Msg 446, Level 16, State 9, Line 1
Cannot resolve collation conflict for equal tc operation.

.
, . . , , ,
. COLLATE, . , :
SELECT * FROM tbll WHERE Coll=Col2 COLLATE Latinl_General_CS_AS

:
Coll

CO12

888

IV.

. , SQL Server 2000,


fnheipcoiiations, :
SELECT * FROM : : f n _ h e l p c o l l a t i o n s ( )

,
. . , .
, :
SELECT name FROM ::fn_helpcollations() WHERE name LIKE 'Cyrillic%'

:
Cyrillic_General_BIN
Cyrillic_General_CI_AI
Cyrillic_General_CI_AI_WS
Cyrillic_General_CI_AI_KS
Cyrillic_General_CI_AI_KS_WS
Cyrillic_General_CI_AS
Cyrillic_General_CI_AS_WS
Cyrillic_General_CI_AS_KS
Cyrillic_General_CI_AS_KS_WS
Cyrillic_General_CS_AI
Cyrillic_General_CS_AI_WS
Cyrillic_General_CS_AI_KS
Cyrillic_General_CS_AI_KS_WS
Cyrillic_General_CS_AS
Cyrillic_General_CS_AS_WS
Cyrillic_General_CS_AS_KS
Cyr i11i c_Gene ra1_CS_AS_KS_WS
(11 row(s) affected)

,
.
cyriiiicj3enerai_cs_AS.
, . .
(,
Danish_Norwegian_cs_Ai).
, . General
. ,
. , . ,
.
, :
;
;

20.

889

w . , , ( Unicode) (Unicode);
,
Hiragana Katakana.

, . , ,
. , Hiragana Katakana.
:
s ;
i .

, , . CS CI, AS AI, WS WI, KS KI.


,
BIN, ,
(characters set), (code page).
(binary sort order). , .

, . . .
,
Windows
.
COLLATIONPROPERTY, :
COLLATIONPROPERTY (collatlon_name, property)

,
, . property :
'CodePage' Unicode, .

890

IV.

'LCID'
(LCID, locale ID), . SQL Server, NULL.
'Comparisonstyle' , Windows .

Cyrillic_General_CS_Ai:
SELECT COLLATIONPROPERTY('Cyrillic_General_CS_AI', 'CodePage')
SELECT COLIATIONPROPERTY('Cyrillic_General_CS_AI', 'LCID')
SELECT COLLATIONPROPERTY('Cyrillic_General_CS_AI', 'ComparisonStyle')

:
1251
(1 row(s) affected)
1049
(1 row(s) affected)
196610
(1 row(s) affected)
, .
Latinl_General. 1252, . Latinl_Generai:
SELECT name FROM : : f n _ h e l p c o l l a t i o n s ( )

WHERE name LIKE

'Latinl_General%'.

20.
Latinl_General_CS_AS_WS
Latinl_General_CS_AS_KS
Latlnl_General_CS_AS_KS_WS
(17 row(s)

affected)

891

892

IV.

,
. , , ,
. ,
, dbo.
SQL Server 2000 , . , ,
Model. . . , , .

")

, , .
, ,
Model. , Model -
,
. , , -, , . .
, , ,
. , Model, Master, (
). Model
768 , 512 .

Transact-SQL
Transact-SQL
. , Enterprise Manager
, ,
. , Enterprise Manager
. .
Transact-SQL:
CREATE DATABASE database_name
4,
[ON [ <filespec> [,...n]] [, <filegroup> [,.. .n]]] "''"'""
[LOG ON { <filespec> [ ,...n ]})
[COLLATE-collation_name]
[FOR LOAD I FOR ATTACH]

20.

893

, C R E A T E D A T A B A S E ,
s y s a d m i n
d b c r e a t o r . ,
, -

CREATE DATABASE. ,

GRANT ALL. -

CREATE DATABASE -

sysadmin securityadmin. , , 9.

:
database_name
, .
Unicode
128 . CREATE
DATABASE.
, . CREATE DATABASE
database_name,
.
, Data
Log .
128 ,
databasename (, ) 123 .
ON

,
, , . ON , .
768 (0,75 ). Model.
LOG ON

, . ,
. ,
LOG ON .
, 25% , 512 , ,
, Log.

QQ4

IV.

COLLATE collation_name
,
. . "
" . , ,
SQL Server 2000.
FOR LOAD


SQL Server ( SQL Server 7.0). FOR LOAD
,
.
( ) sysdatabases. , . . .
, . SQL Server 7.0,
( RESTORE
DATABASE), FOR LOAD .

, FOR LOAD Loading


( dbo use only).

FOR ATTACH

FOR ATTACH
, .

. , FOR ATTACH
, , .
CREATE DATABASE
sysdatabases
. .
,
.


, . , ,

<f i i e s p e o .
, , . .
. ,
.

20.

895

<f i l e s p e o :
< f i l e s p e c > : : = [ PRIMARY ]
( [NAME = l o g i c a l _ f i l e _ n a m e , ]
FILENAME = ' o s _ f i l e _ n a m e '
[, SIZE = s i z e ]
[, MAXSIZE = { m a x _ s i z e I UNLIMITED}]
[, FILEGROWTH = g r o w t h _ i n c r e m e n t ] ) [ , . . . n ]

PRIMARY

, .
,
. , , PRIMARY .
.
. PRIMARY
,
, . . ON.
NAME = logical_file_name
. . , ,
. . .
.
FILENAME = 'os_file_name'
.
SQL
Server 2000,
. .
(compressed) . ,
. ( S I Z E ) (
MAXSIZE), ( FILEGROWTH).

896

IV.
, , dblspace drvspace (
Windows 95/98).

,
mdf, ndf, Idf.
, . , . . .
SIZE = s i z e
, .
, (secondary file) 1 . ,
Model. , ( , ), 512 .
. , ,
, , GB . , 0,5 512 .
, .
d MAXSIZE = { max_size I UNLIMITED }

, ,
. , ,
. MAXSIZE
, , .
UNLIMITED. (
maxsize) , SIZE.

, .
FILEGROWTH = growth_increment
, (growth increment),
. , . , ,
GB, %.
, %

20.

897

. , . . , (
)
( SIZE), , 64 . .
,
,
MAXSIZE. .
[ ,... ]
,
< f i i e s p e o .
, .
< f i i e s p e o .
.
:
PRIMARY
(NAME=PriDataFile,
FILENAMESC:\SQL2000\primary', SIZE=100 MB),
(NAME=SecFilel,
FILENAMESC:\SQL2000\secl', SIZE=1OO MB, MAXSIZE=300, FILEGROWTH=25%)
(NAME=SecFile2,
FILENAME='C:\SQL2000\sec2', SIZE=3O MB, FILEGROWTH=5 MB)

, . CREATE DATABASE
ON. .


,
. , ,
. ,
.
.
, <fiiegroup>,
:
<filegroup>

: : = FILEGROOP f i l e g r o u p _ n a m e < f i l e s p e c >

,...n ]

,
FILEGROUP, .
, . ,

898

IV.


<f i l e s p e o , .

:
FILEGROUP PrimGroup
PRIMARY
(NAME=PriDataFile,
FILENAME='C:\SQL2000\primary', SIZE=100 M B ) ,
(NAME=SecFilel,
FILENAME='C:\SQL2000\secl', SIZE=100 MB, MAXSIZE=300,
FILEGROWTH=25%)
(NAME=SecFile2,
FILENAME='C:\SQL2000\sec2', SIZE=30 MB, FILEGROWTH=5 MB)

20.

899_

, FirewailLog,
:
CREATE DATABASE FirewailLog
ON PRIMARY
=I
(NAME=FirewallPrimary, FILENAME c:\Firewall\Firewalldatal.mdf,
SIZE=120 MB, MAXSIZE=300, FILEGROWTH=15%),
(NAME=FirewallSecl, FILENAME='c:\Firewall\Firewalldata2.ndf',
SIZE=150 MB, FILEGROWTH=25 M B ) ,
( NAME=FirewallSec2, FILENAME^c:\Firewall\Firewalldata3.ndf',
SIZE=150 MB, MAXSIZE=300, FILEGROWTH=25%)
LOG ON
(NAME=Firewalllogl, FILENAME='c:\Firewall\Firewalllogl.ldf',
SIZE=10 MB, MAXSIZE=50 MB, FILEGROWTH=5),
(NAME=Firewalllog2, FILENAME^1c:\Firewall\Firewalllog2.ldf,
SIZE=10, MAXSIZE=50, FILEGROWTH=50%)

,
. stdDB, , .
, :
CREATE DATABASE StdDB
FILEGROUP PrimGroup
PRIMARY
(NAME=StdDB_prm, FILENAME='c:\SQL2000\DataBase\StdDB_Primary.mdf ,
SIZE=75, MAXSIZE=150, FILEGROWTH=15) ,
(NAME=StdDB_secl,
FILENAME='d:\SQL2000\DataBase\StdDB_Secondaryl.ndf',
SIZE=20, MAXSIZE=50, FILEGROWTH=20%),
(NAME=StdDB_sec2,
FILENAME='d:\SQL2000\DataBase\StdDB_Secondary2.ndf',
SIZE=20, MAXSIZE=50, FILEGROWTH=20%) ,
FILEGROUP Groupl
(NAME=StdDB_sec3,
FILENAME=':\SQL2000\DataBase\StdDB_Secondary3. ndf',
SIZE=30, MAXSIZE=150, FILEGROWTH=20%) ,
(NAME=StdDB_sec4,
FILENAME='d:\SQL2000\DataBase\StdDB_Secondary4.ndf,
SIZE=20, MAXSIZE=150, FILEGROWTH=20%) ,
(NAME=StdDB_sec5,
FILENAME='e:\SQL2000\DataBase\StdDB_Secondary5.ndf',
SIZE=20, MAXSIZE=150, FILEGROWTH=20%) ,
FILEGROUP Group2
(NAME=StdDB_sec6,
FILENAME=':\SQL2000\DataBase\StdDB_Secondary6.ndf,
SIZE=30, MAXSIZE=50, FILEGROWTH=25%) ,
(NAME=StdDB_sec7,
FILENAME='d:\SQL2000\DataBase\StdDB_Secondary7.ndf',
SIZE=30, MAXSIZE=50, FILEGROWTH=25%),
(NAME=StdDB_sec8,
FILENAME='e:\SQL2000\DataBase\StdDB_Secondary8.ndf',
SIZE=3O, MAXSIZE=50, FILEGROWTH=25%),

900

IV.

LOG ON
(NAME=StdDB_Logl, FILENAME^ :\SQL2000\DBLog\StdDB_Logl.ldf',
SIZE=25 MB, MAXSIZE=75 MB, FILEGROWTH=5 MB)
(NAME=StdDB_Log2, FILENAME^d:\SQL2000\DBLog\StdDB_Log2.ldf,
SIZE=25 MB, MAXSIZE=75 MB, FILEGROWTH=5 MB)

Enterprise Manager

Transact-SQL. ,
.

Enterprise Manager.
, , . Enterprise Manager
Transact-SQL ,
. Enterprise Manager
CREATE DATABASE, .

. 20.1. Databases

20.

901

SQL Server 2000 Databases


(. 20.1), .
, . ,
, .
,
,
Enterprise Manager ,
. Registered
SQL Server Properties (. 20.2) Show system databases and
system objects.
Edit SQL Server Registration Properties.

. 20.2. Registered SQL


Server Properties
Database Properties
(. 20.3). :
Databases New Database;
New Database;
Enterprise Manager New Database;
Action New Database.
, Enterprise Manager . , , -

902

IV.

.
.

. 20.3. Database Properties Chair


, Database Properties .
. General (.
. 20.3) ,
.
CREATE DATABASE, General
databse_name COLLATE collation_name.
General .
, (Unknown) () None ().
Database Backup .
, Name,
, CREATE DATABASE. ,
, Collation
name. (Server default), -

20.

903

,
SQL Server 2000.
.
. " ".
,

, ,
Collation name ,
. , .
.
Data Files (. 20.4),
,
.

. 20.4. Database Properties, Data Files


Data Files Database files, . File
Name ,
NAME=logical_file_name,

904

IV.

CREATE DATABASE. Location , FiLENAME='os_fiie_name'.


, Location
.
Locate Database File,
, Location.
Initial size (MB) ,
. -
, , . (), (), GB
() (). Filegroup
, .
PRIMARY. Filegroup
, .
,
, .

, Database files,
(primary file).
(PRIMARY). Enterprise Manager .
Enterprise Manager ,
Database files. , . - ,
Delete.

, Database files
. .
, Database files,
, . File properties, Data
Files. .
Automatically grow file.
. ,
File properties .
File growth ,
:

20.

905

In megabytes ,
;
By percent . , 10%.
Maximum file size, ,
:
Unrestricted file growth. ,
, . , .
Restricted file growth (MB).
,
.
Data Files .
Transaction Log (. 20.5),
.

. 20.5. Database Properties, Transaction Log

906

_^____

/.

, Transaction Log Data Files. ,


.
, ,
, .
Enterprise Manager .
CREATE DATABASE . Enterprise Manager .


Create Database Wizard

Transact-SQL Enterprise Manager.
, , .
Create Database Wizard.
Select Wizard, Run a Wizard,
Enterprise Manager. , .
Database.
,
. , , .
.
Name the Database and Specify its Location
(. 20.6) :
Database name. ,
.
Database file location.
, ,
. , . ,
Select a directory for the files, , .
Transaction log file location. ,
. ,
,

20.

907

.
.

. 20.6. Name the Database and Specify its Location


Create Database Wizard

, Database Settings (. . 8.9) , , Default data directory Default log directory.


, , , , Name the Database Files (. 20.7).
.
Database files,
File Name Initial Size (MB), .
File Name ,
.
, Database file location
.
, Name the Database Files .
, , . -

908

IV.

, Define the
Database File Growth (. 20.8).

. 20.7. Name the Database Files Create Database Wizard

. 2 0 . 8 . Define the Database File Growth Create Database Wizard

20.

(~

909


, , , .
(primary file group).
, .
:
Do not automatically grow the database files ;
Automatically grow the database files .

,
, . ,
.

:
Grow the files in megabytes (MB).
.
.
Grow the files by percent. ,
, .
Maximum file size. ,
:

Unrestricted file growth ;


Restrict the file growth to MB , .

Define the Database File Growth. , . , , ,


- ,
.
,
, ,
Name the Transaction Log Files (. 20.9).

910

IV.

. 20.9. Name the Transaction Log Files Create Database Wizard

. 20.10. Define the Transaction Log File Growth


Create Database Wizard

, Name the Transaction Log Files Name the Database Files (. . 20.7), .
, -

20.

911

Name the Transaction Log Files . ,


, .
Define the Transaction Log File Growth (. 20.10) .
Define the Database
File Growth, .
.
. . ,
:
The name of the database is Administrator Database.
The database files will be placed in
the directory G:\Program FilesXMicrosoft SQL Server\MSSQL$TRELON\data.
The transaction log files will be placed in
the directory G:\Program FilesVMicrosoft SQL Server\MSSQL$TRELON\data.
The database files are:
Administrator Database_Data, size 10
Administrator Database_Sec, size 5
The database files will automatically grow by 10 percent.
The database files' growth is unrestricted.
The transaction log files are:
Administrator Database_Log, size 10
The transaction log files will automatically grow by 5 Mb.
The transaction log files' growth is restricted to 50 Mb.

Finish
CREATE DATABASE . .


. , , , ,
.
.
,
30

.1207

12

IV.

. , . ,
Transact-SQL,
Enterprise Manager. , SQL Server 2000
, Enterprise
Manager .
.

Transact-SQL
, ,
,
. , Transact-SQL .

sp_dboption

s p d b o p t i o n . .
:
sp_dboption [ [ gdbname = ] 'database' ]
[, [ Soptname = ] 'option_name']
[, [ @optvalue = ] 'value']

20.

913

arithabort
auto create statistics
auto update statistics
autoclose
autoshrink
concat null yields null
cursor close on commit
dbo use only
default to local cursor
merge publish
numeric roundabort
offline
published
quoted identifier
read only
recursive triggers
select into/bulkcopy
single user
subscribed
torn page detection
trunc. log on chkpt.

s p d b o p t i o n
, . :
[Sdbname =]

'database'

, .
[@optname =] 'option_name'
, . sp_dboption .
. 20.1.
[Soptvalue =] 'value'
. ,
. @optvaiue
TRUE ON, , FALSE OFF, .
20.1.

ANSI n u l l d e f a u l t


NULL , -

ANSI SQL-92
30*

914

IV.
20.1 ()

ANSI nulls


NULL, TO
UNKNOWN, TRUE FALSE. TRUE

, NULL. FALSE
ANSI padding

, .
, , ,

ANSI warnings

,
, , .
,
.

arithabort

, .
.
, NULL .
,

auto create
statistics

.
, , . .

auto update
statistics

.

,

autoclose

, . ,

autoshrink

20.

915
20.1 ()

concat null yields


null

() NULL NULL. NULL


cursor close on
commit


( , ). ,

( S T A T I C I N S E N S I T I V E )

dbo use only

.

,

default to local
cursor

,
(LOCAL).
(GLOBAL)

merge publish

numeric roundabort

,
.
, , .

a r i t h a b o r t

offline

published

quoted identifier

.

, . . .

, . .

read only

,
" ". , ,

recursive triggers


( ) ( ). ,

, . 20.1,
, . , , , , , ,
, , ,
, .
quoted identifier.

20.

The following options are set:

917

gig

IV.

. , .
sprenamedb, :
sp_renamedb [ Sdbname = ] ' old_name',
[ gnewname = ] 'new_name'-

, , . ,
, .
pubs superPubs:
EXEC sp_renamedb ' p u b s ' ,

'SuperPubs'

, sprenamedb
, ALTER DATABASE MODIFY NAME. , -

ALTER
DATABASE. ,
. ALTER DATABASE, ,
:
ALTER DATABASE d a t a b a s e
MODIFY NAME = new_dbname

, database
, newdbname. :
ALTER DATABASE p u b s
MODIFY NAME = S u p e r P u b s


, .
, . dbo (database owner), . ,
( guest), . dbo , .
.
(,
, ), . dbo,
, . , dbo .

20.

019

, , , spchangedbowner, :
sp_changedbowner [ @loginame = ] 'login'
[ , [ @map = ] remap_alias_flag ]


sysadmin ,
db_owner.
,
. gioginame , dbo ,
, . ,
,
. .
@ dbo
.
True,
, .
@ False,
dbo .
pubs
sa:
USE pubs
EXEC sp_changedbowner ' s a ' ,

'True'


s p h e i p i o g i n s ,
, ,
:
EXEC sp_helplogins 'sa 1

:
LoginName SID

DefDBName

DefLangName

AUser ARemote

sa

master

us english

yes

0x01

(1 row(s) affected)
LoginName DBName

UserName

UserOrAlias

sa
sa

db owner

dbo

MemberOf
User

master
master

YES

20

sa
sa
sa
sa
sa
sa
sa
sa
sa
sa

IV.
model
model
msdb
msdb
Northwind
Northwind
pubs
pubs
tempdb
tempdb

db owner

dbo

db owner

dbo
db owner

dbo
db_owner

dbo
db owner

dbo

Memberof
User
MemberOf
User
MemberOf
User
MemberOf
User
MemberOf
User

(12 row(s) affected)


Transact-SQL
. s p h e i p d b , :
sp_helpdb [ [ @dbname= ] 'name' ]

,
. . , ,
. :
name ;
d b s i z e , ( . . ), ;
owner , -;
dbid . DB_ID(dbname);
created ;
s t a t u s , ,
s p d b o p t l o n , ;
c o m p a t i b i l i t y l e v e l .
s p h e i p d b
.
:
name ;
f i l e i d ,
;

20.

921

filename ,
, ;
f ilegroup , ;
size ;
maxsize unlimited,
;
growth . , ;
usage . data only
, log only .
,
. sp_heipf i l e , :
sp_helpfile [ [ Sfilename = ] 'name' ]

s p h e i p f i l e . , , . ,
Sfiiename. ,
, , s p h e i p d b .

, . :
sp_helpfilegroup [ [ @filegroupname = ] 'name' J

,
, . ,
.
@f ilegroupname.

:
groupname ;
groupid ;
f iiecount , .
, , :
f i i e i n g r o u p , ;
f i l e i d ,
;

Q22

IV.

filename ,
, ;
size ;
maxsize unlimited,
;
growth . , .

pubs:
USE pubs
EXEC sp_helpfilegroup 'PRIMARY'
:
groupname

groupid filecount

PRIMARY

file_in_group
pubs

fileid filename
1

...\data\pubs.mdf

size

maxsize

1792 KB Unlimited

growth
10%

20.

923

, . . ,
. 20.2.
20.2.

924

IV.
20.2 ()

pubs:
SELECT DATABASEPROPERTYEX('pubs', 'UserAccess')

20.
:

database size

unallocated space

database_name
pubs

2.50 MB

0.52 MB

reserved

data

index _size

unused

1264 KB

456 KB

680 KB

128 KB

, . gobjname. authors:
EXEC sp_spaceused 'authors'

(11 row(s) affected)


DBCC execution completed. If DBCC printed error messages, contact your system administrator.

926

IV.

Database Name . Log s i z e


() .
Log Space used (%). 0.


,
.
(shrinking database).
.

, . ,
. , , .
.
(truncate transaction Jog).

(~

, . . . , .
13.

BACKUP LOG,
:
BACKUP LOG { database_name I @database_name_var }
{ [ WITH { NO_LOG I TRUNCATE_ONLY ) ] }

databasename ,
. , .
8database_name_var.
( , )
WITH, ,
. NOLOG TRUNCATEONLY -

.
.
SQL Server 2000
.
' t r u n e , log on c h k p t . ' , :
EXEC sp_dboption "database 1 , 'trunc. log on chkpt. 1 , 'TRUE'

20.

927

database . (checkpoint), ,
, . ,
, . . .

. .
. , . :
DBCC SHRINKDATABASE;
DBCC SHRINKFILE.

,
.
.
:
DBCC SHRINKFILE
( { file_name | f i l e _ i d )
{ ( , t a r g e t _ s i z e ) [ , ( EMPTYFILE | NOTRUNCATE I TRUNCATEONLY } ] } )

:
file_name

, . , DBCC SHRINKFILE . , ,
(,
USE database).
file_id

, , ,
.
, ,
F i L E i D C f i i e n a m e 1 ) .
, .

, sysfiles,
. , , .

Q28

IV.

L*] target_size

,
. , , , .
. , .
. t a r g e t s i z e ,
. . , (
),
( ).
EMPTYFILE


. , , . . , .
DBCC SHRINKDATABASE EMPTYFILE

,
ALTER DATABASE REMOVE

FILE. tar-

get_size .

NOTRUNCATE


t a r g e t s i z e ,
. ,
.
.

TRONCATEONLY


,
. , t a r g e t s i z e .
.

DBCC SHRINKDATABASE
NOTRUNCATE TRUNCATEONLY target_size.

pubs
1 . ,
. sysf l i e s :
USE pubs
SELECT f i l e i d , name FROM s y s f i l e s

20.

929

:
fileid name
1

pubs

pubs_log

(2 row(s) affected)

p u b s l o g :
DBCC SHRINKFILE

(2,

1)

:
Cannot shrink file '2' in database 'pubs' to 128 pages as it only contains
96 pages.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

, . .
96 (768 ), 1 (128 ).
pubs:
DBCC SHRINKFILE ( 1 , 1)

:
Dbld

Fileid CurrentSize MinimumSize UsedPages

168

80

160

EstimatedPages
160

{1 row(s) affected)
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

. :
Dbid ;
F i l e i d ;
CurrentSize ;
MinimumSize , ;
UsedPages , ;
EstimatedPages , .

DBCC SHRINKFILE. DBCC

SHRINKDATABASE.

IV.

.
:
DBCC SHRINKDATABASE
( database_name [ , t a r g e t _ p e r c e n t ]
[ , { NOTRUNCATE I TRUNCATEONLY } ] )

:
database_name
, .
target_percent
, . , 100 ,
60 , 40 20
25. ,
, 100
( 1 0 0 + t a r g e t p e r c e n t ) . , t a r g e t _ p e r c e n t
, ( 40). , . , DBCC

SHRINKDATABASE

DBCC SHRINKFILE, .

NOTRUNCATE


,
.
TRUNCATEONLY

,
( ).
. t a r g e t p e r c e n t .
Northwind 20%:
DBCC (Northwind, 20)

:
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
,
. , ,
. ,
, , -

20.

931

. 1%:
DBCC SHRINKDATABASE (Northwind, 1)

:
Dbld

F i l e l d C u r r e n t S i z e MinimumSize UsedPages

EstimatedPages

352

360

80

352

(1 row(s) a f f e c t e d )
DBCC execution completed.
tem a d m i n i s t r a t o r .

If DBCC p r i n t e d e r r o r messages,

c o n t a c t your s y s -

UsedPages , . , ( C u r r e n t S i z e )
usedPagesx1,01. 355,52 (352x1,01).
C u r r e n t S i z e 360. , ( 8 ).

Enterprise Manager
1 Transact-SQL.
, Enterprise Manager.

.
Properties.
. 20.11 . , ,
. (. 20.11)
General .
,
s p h e i p d b . , :
Name , ;
Status . Normal, Offline,
Restoring, Recovering, Suspect, Read Only, Dbo Use Only, Single User Mode;
Owner ,
;
Data created ;
Size ' ,
, . . ;

932

IV.

Space available ;
Number of users , ;
Last database backup ;
Last transaction log backup ;
Maintenance plan , .
Database Maintenance
Plan Wizard . 12; ,
Collation name , .

. 2 0 . 1 1 . , General

, General ,
. (, )
.
Data Files (. 20.12).
. Data Files

20.

933

. , ,
,
. , , . ,
. Enterprise Manager .
Transact-SQL.
.

. 20.12. , Data Files


Transaction Log (. 20.13)
. , .
.
Filegroups (. 20.14).
. Filegroups, . Name
. Files.
Read-Only Default .
, "

934

IV.

". , , , . Default
.
. , , , .

. 2 0 . 1 3 . , T r a n s a c t i o n Log

, Options (. 20.15)
. Options spdboption. , :
Restrict access.
. :
Members of db_owner, dbcreator, or sysadmin
dbo use
only.
dbowner, dbcreator sysadmin.
Single user
, .

20.

. 20.14. , Filegroups

. 20.15. , Options

935

Q36

IV.

Read-only.
" ".
, . " " , .
Model
, . :

Simple , .
,
;

Full
,
,
;

Bulk-Logged
,
SQL Server ^, .
SELECT INTO, BULK INSERT,
CREATE INDEX, WRITETEXT, UPDATETEXT bcp.exe.

ANSI NULL default. ANSI SQL92 NULL , , NULL.


Recursive triggers. ( ) .
Auto update statistics. .
Torn page detection. .
Auto close. , .
Auto shrink.
.
Auto create statistics. .
Use quoted identifiers. . ,
, . . . -

20.

937

, . . .
Level
, .
(compatibility level) , SQL Server
.
Options .
Permissions (. 20.16)

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

. 20.16. , Permissions

938

IV.

, Permissions:
Create Table ;
Create View ;
Create SP ;
Create Default ;
Create Rule ;
Create Function ;
Backup DB ;
Backup Log .
Permissions, , .



, . .
Transact-SQL.
Enterprise Manager .
Transact-SQL
ALTER DATABASE, :
ALTER DATABASE database
{ ADD FILE <filespec> [,. ..n] [TO FILEGROUP filegroup_name]
I ADD LOG FILE <filespec> [,...n] I REMOVE FILE logical_file_name
I ADD FILEGROUP filegroup_name I REMOVE FILEGROUP filegroup name
I MODIFY FILE <filespec> I MODIFY NAME = new_dbname
~
I MODIFY. FILEGROUP filegroup_name {filegroup_property
i NAME = new_filegroup_name}
I SET <optionspec> I,...n] fWITH <termiriation>J
I COLLATE <collation_narae>
}

:
database

, .
ADD FILE

. <fiiespec>, . "
" .
FILEGROUP filegroup_name ,
. ,

20.

939

(default file
group). ALTER DATABASE
.
.
ADD LOG FILE


. ,
<f i l e s p e o . .
REMOVE FILE logical_file_name
ALTER DATABASE ,
logical_fiie_name. . , .
. " "
.
ADD FILEGROUP filegroup_name
.
,
sysfiiegroups. , ADD FILEGROUP
,
, f i l e g r o u p n a m e . .
REMOVE FILEGROUP filegroup_name
, fiiegroup_name. , .
, .
MODIFY FILE <filespec2>

.
<f ilespec2>, :
( NAME=logical_file_name
[ , NEWNAME=new_logical_name ]
[ , FILENAMESos_file_name' ]
[ , SIZE=size ]
[ , MAXSIZE={ max_size I UNLIMITED } ]
[ , FILEGROWTH=growth_increment ] )

NAME=logical_file_name ,
;

40

IV.

NEWNAME=new_logical_name
;

FiLENAME='os_file_name'
. ,
Tempdb. SQL Server;

sizE=size ;

MAXSizE={max_size | ONLIMITED} . UNLIMITED


;

FiLEGROWTH=growth_increment .

MODIFY NAME = n e w _ d b n a m e

.
newdbname.
MODIFY FILEGROUP f i l e g r o u p _ n a m e

,
.
filegroup_name. , NAME=new_filegroup_name, .
f i l e g r o u p p r o p e r t y ,
:

READONLY " ";

READWRITE "-" (
, );

DEFAULT
. , ,
.
COLLATE <collation_name>

ALTER DATABASE ,
. , . . .
SET <optionspec> [,...n] [WITH <termination>]
.

,
< o p t i o n s p e o <termination>, , ,
:

20.

941

<optionspec> ::= <state_option> I <cursor_option> | <auto_option>


| <sql_option> | <recovery__option>
<State_pption> ::= {SINGLEJJSER I RESTRICTED_OSER I MULTIJJSER}
I {OFFLINE I ONLINE} I {READ-ONLY I READ_WRITE}
<cursor_option> : := CURSOR_CLOSE__ON_COMMIT {ON I OFF}
I CURSOR_DEFAULT {LOCAL I GLOBAL}
<auto_option> ::= AUTO_CLOSE {ON I OFF}
I AUTO_CREATE_STATISTICS {ON I OFF} I AUTO_SHRINK (ON | OFF}
I AUTO_UPDATE_STATISTICS {ON I OFF}
<sql_option> ::= ANSI NULL_DEFAULT {ON ! OFF}
I ANSI_NULLS {ON I OFF} ! ANSI_PADDING {ON | OFF}
I ANSI__WARNINGS {ON I OFF} | ARITHABORT {ON I OFF}
I CONCAT_NULL_YIELDS_NULL {ON I OFF}
I NUMERIC_ROUNDABORT {ON | OFF}
I QUOTED__IDENTIFIER {ON | OFF}
I RECURSIVEJTRIGGERS {ON i OFF}
<recovery_option> ::= RECOVERY {FULL | BULK^LOGGED | SIMPLE}
I TORN_PAGE_DETECTION {ON | OFF)

<termination>, WITH,
. . <termination> :
<termination> ::= ROLLBACK AFTER integer [SECONDS]
I ROLLBACK IMMEDIATE I NO_WAIT

ROLLBACK

AFTER

integer

[SECONDS]

. , ;

ROLLBACK IMMEDIATE
ALTER DATABASE;

NOWAIT ,
ALTER DATABASE , .
. , ALTER DATABASES. Northwind
MyGroup, ,
:
ALTER DATABASE Northwind ADD FILEGROUP MyGroup

. :
ALTER DATABASE Northwind ADD FILE
(NAME=SecFilel, FILENAME='C:\SQL2000\secl',

42

IV.

SIZE=10 MB, MAXSIZE=25, FILEGROWTH=25%),


(NAME=SecFile2, FILENAME='C:\SQL2000\sec2,
SIZE=10 MB, FILEGR0WTH=5 MB)
TO FILEGROUP MyGroup

s e c F i i e 2 ,
, 50 , 10%,
TxtimgData.
ALTER DATABASE Northwind
MODIFY FILE
( NAME=SecFile2, NEWNAME=TxtImgData, MAXSIZE=50 MB, FILEGROWTH=10%)

, , Bulk-Logged:
ALTER DATABASE Northwind
SET SINGLE_USER, RECURSIVEJTRIGGERS ON,
RECOVERY BOLK_LOGGED WITH ROLLBACK AFTER 15 SECONDS



SQL Server 2000 . (detach) , sysdatabases Master . .
,
.
(attach) .

. , -
.
. .
, .
:
sp_detach_db [Sdbname =]

'dbname1

[,

[@skipchecks =]

'skipchecks']

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

943

20.

.
" " (read only).

, .
, .
Enterprise Manager.
All Tasks,
Detach Database. Detach Database
(. 20.17),
, Update statistics prior to
detach. , , .

. 20.17. Detach
Database
pubs
:
EXEC sp_detach_db ' p u b s ' , 'TRUE'

,
, sysdatabases
Master .
,
. :
sp_attach_db [@dbname =] 'dbname', [Sfilenamel =] 'filename_n' [,...16]
,
. ,
.
3 1 . 1207

IV.

944

.
sysfiles,
. ,
.
, . s p a t t a c h d b
16 . , CREATE DATABASE FOR ATTACH.

(~

. ,
, ,
Log.

pubs:
EXEC sp_attach_db 'pubs' ,
'G:\Program FilesXMicrosoft SQL Server\MSSQL$TRELON\Data\pubs.mdf'

, . .
. ,
, .

CREATE DATABASE FOR ATTACH:
CREATE DATABASE pubs
ON PRIMARY (FILENAME =
'G:\Program FilesNMicrosoft SQL Server\MSSQL$TRELON\Data\pubs.mdf')
FOR ATTACH

s p a t t a c h d b , . , :
sp_attach_single_file_db [Sdbname =]

'dbname1,

[@physname =] 'physical_name'

, .
, . , .
Enterprise Manager Attach Database (. 20.18),
Databases, All Tasks,
Attach Database.

20.

945

. 20.18. Attach
Database



. . :
DROP DATABASE database_name [ ,...n ]

,
. , . sysdatabases,
.
, . ,
, .

DROP DATABASE Master.


Model, Tempdb, Msdb Master.

31*

21


. ,
. , . .
. . . 21.1 authors pubs, Enterprise Manager.

pubs Microsoft SQL Server 2000 . .

. 21.1. authors pubs

21.

947


, .
, , , , , .
SQL Server 2000
Enterprise Manager, Transact-SQL. , SQL Server 2000 .
,
, ,
,
. . ,
.
, , .
17. , ,
. .



, , , ,
.
(constraints) , . SQL Server 2000 :
Check ,
;
Null ;
Default ;
Unique ;
Primary Key ;
Foreign Key ;
No Action .
SQL Server 7.0;
Cascade .

948

IV.

~^

SQL Server 2000.

Check
Check
, .
, . ,
.
, , SQL Server 2000.
, cost , 100 15,
:
cost>=15 AND cost<=100

cost BETWEEN 15 and 100

. . ,
, Check
. ,
mincost , maxcost , cost ,
. , cost
mincost maxcost. :
cost>=mincost AND cost<=maxcost

Check SQL Server 7.0.


(rules).
SQL Server 2000
.
. .
. "" 18. .

Microsoft
Check . ,

21.

949

SQL Server .
.
Check.
SQL Server 2000 .
,
Check.

Null
SQL Server 2000 , .
, 0 . , ,
. NULL.
, ,
NULL
.
,
NULL. . ,
, .
, , NULL, .
:
SET ANSI_NULL_DFLT_ON (ON

OFF}

ON , ( ) , ;
SET ANSI_NULL_DFLT_OFF

{ON

OFF}

NULL .

ANSI_NULL_DFLT_ON ANSI_NULL_DFLT_OFF SET -

. ON, OFF. OFF .


, (NULL)
(NOT NULL) .

, .

gSQ

IV.


sp_configure 'user o p t i o n ' . Enterprise Manager.
MSSQLServer Connections Default connections options .
, , sp_dboption. .

Default
,
. ,
Address cityiD, , .
, . cityiD
(defaults),
,
. ,
, .
.

, ,
.
,
(SID, Security ID) , . , .

S U S E R S I D O . SQL Server 2000 .
ROWGUIDCOL , NEWIDO.

(GUID, Global Unique Identifier) .
.
.
ROWGUIDCOL
. , . .
.


.
, (computed) . , , , .

21.

951_

Default SQL Server 7.0.



, .
, .
,
, .
. "" 18.
, SQL Server 2000 . . Microsoft
, , . .
. SQL Server 7.0.
, SQL Server 2000 (
) .

Unique
,
. ,
, ,
. , .
.
Unique . , . , ,
. , , Unique .

Unique ,
,
(NULL). Unique .
Unique .
.

IV.

952

Primary Key
. , . , ,
.

(~

17.

. (Primary Key).
SQL Server 2000 ,
.
.
Primary Key
(Unique Index), , Unique, ( ) . , Unique
.
, ,
, SQL Server 2000 .
(NULL). Unique Primary Key. , ,
Unique. , , .

N U L L , Unique, , Primary Key. SQL Server 2000


, ,
Unique.

,
. t i n y i n t , s m a i i i n t , i n t b i g i n t . ,

. , authors pubs a u i d , id, varchar ( i i ) .

21.

953

Foreign Key
, ( )
( ) .
SQL Server 2000 Foreign Key. .
SQL
Server 2000 . ,
Foreign Key,
, . , . SQL Server 2000
.

^)

, SQL Server 2000


( )
Unique .
, (NULL). .
, .
, , ,
. , ,
, , .

, , ( ), , . ,
.

No Action Cascade
SQL Server 7.0.
SQL Servetf 2000 , -

954

IV.

, . , ,
,
. .
.
SQL Server 2000 ,
( )
.
No Action Cascade. , , .
Foreign Key.
No Action . ,
. , , No Action, , .
SQL Server.
, SQL Server 2000, .

Cascade.
, . , ,
,
. .

, , , No Action, a
Cascade. , . . , , ,
No Action.
,
Cascade , No Action.


, SQL Server 2000
, , . -

21.

955

, , . , .
COLLATE , .
. " " ,
.


(data
type). ,
. , SQL Server 2000, 26. ,
, Transact-SQL. ,
cursor t a b l e . , , . . , ,
.
timestamp, t e x t , ntext image. ,
, . 21.1.
21.1. ,

varchar

Unicode
8000

timestamp

numeric

text

Unicode 2

sqlvariant

money

(8-)

nchar

Unicode
4000

smallmoney

(4-)

nvarchar
uniqueidentif i e r

Unicode 4000
,

. ,
.
. , . , .

,

.
,

int)

bigint),

10

(
(

21.

957

)
. SQL Server 2000
. .
, IDENTITY (ID entity, ). . ,
.
IDENTITY .
.
,
, . .


IDENTITY. IDENTITY .
,
timestamp. , (GUID, Global Unique Identification). GUID
SQL Server 2000 u n i q u e i c l e n t i f i e r .
u n i q u e i d e n t i f i e r , NEWID ( ) , ,
.
- .

. , ,

. .
- :
SET IDENTITY_INSERT [ database. [ owner. ] ] { table } { ON I OFF }

,
, .
, - .
, ,
.
-
( , , ,
. .). ( s p d b o p t i o n ) ( sp_configure) .

Q58

IV.


Transact-SQL

SQL Server 2000 . ,
. , , .
Transact-SQL, Enterprise Manager.
Transact-SQL.
, Transact-SQL . SQL Server 7.0
Transact-SQL. , Enterprise Manager
(computed columns),
, . Enterprise Manager , , -
,
Transact-SQL,
.


:
. , , 18 20 . ,
, , , ,
. .
.
SQL Server 2000 CREATE
TABLE. .
CREATE TABLE
[database_name.[owner] I owner] table_name
({ <column_definition> I column_name AS compi}ted_column_expression
I <table_constraint>} [ , . . . n ] )
[ON {filegroup | DEFAULT}]
[TEXTIMAGE_ON {filegroup | DEFAULT}]

21.

959

.
database_name
, .
. , . ,
, ,
.
owner
, . ,
. . . , ,
. sysadmin
db_owner db_ddiadmin
, . , , , . sysadmin db_owner dbo.
table_name
, . 256 , , . . Unicode,
128 .
.
, .

.

,
116 #.
. Tempdb.
, ,
Tempdb.
<column_definition>
.
.
column_name AS computed_column_expression
(computed) .

. , , (price) (count), -

960

IV.

(cost) . :
cost AS count * cost

, , .
. ( coiumnname)
AS ( computed_coiumn_expression),
.

, , .

, ,
Unique, Primary Key, Foreign Key
Default.

SQL Server 2000 ,


SQL Server.
<table_constraint>

. .

[,...]

,
.
, image, t e x t ntext.
ON { f i l e g r o u p | DEFAULT}


(filegroup), .
.
DEFAULT, ,
.
TEXTIMAGE_ON ( f i l e g r o u p I DEFAULT}

t e x t ntext
image, .
. -

21.

961

. , .
.
"" , , ,
. TEXTIMAGEON
DEFAULT, TO image, t e x t ntext
.


, , <coiumn_def i n i t i o n > , :
< column_definition > : : = {column_name data_type}
[COLLATE <collation_name>]
[[ DEFAULT c o n s t a n t _ e x p r e s s i o n ]
I [IDENTITY [ ( ' s e e d , increment ) [NOT FOR REPLICATION]]]
]
[ROWGUIDCOL]

[< column_constraint >] [ . . . n ]


:
column_name
, .
. SQL Server 2000 Unicode, .
, , %, * . ., ,
. . timestamp, .
.
timestamp.
data_type
,
. SQL Server 2000,
(UDDT, User Defined Data Type). , NULL, ,
.
COLLATE <collation_name>
, .
. " " . , -

962

IV.

, .
DEFAULT constant_expression
, ,
.
time stamp
IDENTITY. , ,
, .
.
IDENTITY [(seed,

increment)]

. SQL Server 2000


IDENTITY ,
.
IDENTITY i n t ,
s m a l l i n t , t i n y i n t , d e c i m a l (,0) numeric (p, 0 ) .

IDENTITY.
, IDENTITY . 1 1.
.
seed, increment.
NOT FOR REPLICATION


IDENTITY . SQL Server 2000
. , . IDENTITY IDENTITY
, .
, IDENTITY
NOT FOR REPLICATION.
IDENTITY .

ROWGUIDCOL

ROWGUIDCOL, TO
SQL Server 2000
(row global unique identifier Column).
, , (merge replication). ROWGUIDCOL -

21.

963

uniqueidentifier.
.

ROWGUIDCOL
.
unique N E W I D O .
NEW () , .
<column_constraint>

.

.
[ ...]

, , .


,
<coiumn_constraint>.
. <column_constraint>
:
< c o l u m n _ c o n s t r a i n t > : : = [CONSTRAINT c o n s t r a i n t _ n a m e ]
{[NULL I NOT NULL] | [{PRIMARY KEY I UNIQUE}
[CLUSTERED I NONCLUSTERED]
[WITH FILLFACTOR = f i l l f a c t o r ]
[ON { f i l e g r o u p I DEFAULT}]] I [[ FOREIGN KEY]
REFERENCES r e f _ t a b l e [ ( r e f _ c o l u m n ) J
[ON DELETE {CASCADE I NO ACTION}]
[ ON UPDATE {CASCADE I NO ACTION}]
[NOT FOR REPLICATION] ] I CHECK [NOT FOR REPLICATION]

(logical_expression)
}

CONSTRAINT

constraint_name

CONSTRAINT , . constraint_name
, .
. CONSTRAINT constraintname . -

gg4

IV.

,
.
NULL I NOT NOLL

,
.
. NULL , NOT NULL . ,
NULL ,
, A N S I N U L L D F L T O N
ANSI_NULL_DFLT_OFF.
PRIMARY KEY

.
, .

UNIQUE

Unique, . Unique .

Primary Key Unique.


CLUSTERED I NONCLUSTERED

,
Primary Key Unique.
CLUSTERED
. NONCLUSTERED
. .
Primary Key ,
Unique . Unique ,
.

. , .

WITH FILLFACTOR = fillfactor


(fill factor)
. -

21.

965

1% 100%. , .
. 0, 100% .
ON { f i l e g r o u p I DEFAULT}


(filegroup), .
. DEFAULT, TO
,
.
FOREIGN KEY...REFERENCES ref_table [(ref__column)]
. FOREIGN KEY .
REFERENCES , Foreign Key. . ,
Foreign Key,
Primary Key Unique.
, ,
ref_tabie.
. .
ref_coiumn .
ON DELETE {CASCADE I NO ACTION}
Cascade No Action .
,
( CASCADE) ( NO ACTION).
ON UPDATE {CASCADE I NO ACTION}
Cascade No Action . ,
( CASCADE)
( NO ACTION).
NOT FOR REPLICATION

,
Foreign Key ,

966

IV.

, . ,
NOT FOR REPLICATION.
. NOT FOR REPLICATION
Check
.

(~

NOT FOR R E P L I C A T I O N , . . .
CHECK

(logical_expression)

CHECK , , .
logicaiexpression. TRUE,

. FALSE, TO .

,
.
. Check
.


. . , Primary Key Unique
. .
.
<tabie_constraint>, :
< t a b l e _ c o n s t r a i n t > : : = [CONSTRAINT c o n s t r a i n t _ n a m e ]
( [ {PRIMARY KEY | UNIQUE}
[CLUSTERED | NONCLUSTERED]
{ (column [ASC I DESC] [ , . . . n ] ) }
-[WITH FILLFACTOR = f i l l f a c t o r ]

21.

967

[ON { filegroup I DEFAULT }] ] I FOREIGN KEY [(column [ ,...n])]


REFERENCES ref_table [(ref_column [ ,...n])J
[ON DELETE {CASCADE I NO ACTION}]
[ON UPDATE {CASCADE | NO ACTION}]
[NOT FOR REPLICATION] I CHECK [ NOT FOR REPLICATION]
(search_condit ions)
}

,
. , :
CONSTRAINT constraint_name

CONSTRAINT , . c o n s t r a i n t n a m e
, .
. CONSTRAINT constraint_name . ,
.
PRIMARY KEY, UNIQUE, CLUSTERED, NONCLUSTERED
, .
.

(column

[ASC

DESC]

[,...n])

, .
ASC ( ) DESC ( ) ,
( ).


CREATE TABLE
.
Employees, .
EmpiD
. 1000
1. PassNum PassSer
, , .
.
(Lname, Fname Sname) ,
. NULL,
, . :

gS8

IV.

CREATE TABLE Employees


(EmpID int IDENTITY (1000,1) PRIMARY KEY,
PassNum nvarchar(6) NOT NULL, PassSer nvarchar(lO) NOT NULL,
Lname nvarchar(30) NOT NULL, Fname nvarchar(30) NULL,
Sname nvarchar(30) NULL, UNIQUE (PassNum, PassSer))

, jobs, employee publ i s h e r s pubs.


.
jobs
CREATE TABLE jobs
(job_id smallint IDENTITY(1,1) PRIMARY KEY CLUSTERED,
job_desc varchar(50)
NOT NULL DEFAULT 'New Position - title not formalized yet 1 ,
min_lvl tinyint NOT NULL CHECK (min_lvl>=10),
max_lvl tinyint NOT NULL CHECK (max_lvl<=250))
employee
CREATE TABLE employee
(emp_id empid CONSTRAINT PK_emp_id PRIMARY KEY NONCLUSTERED
CONSTRAINT CK_emp_id CHECK (emp_id LIKE
1
[A-Z][A-Z][A-Z][1-9][0-9][0-9][0-9][0-9][FM]' or
emp_id LIKE ' [A-Z]-[A-Z] [1-9] [0-9] [0-9] [0-9] [0-9] [FM] ' ) ,
/* , , 10000 99999
( - , W - ). ,
, . */
fname varchar(20) NOT NULL,
minit char(l) NULL,
lname varchar(30) NOT NULL,
job_id smallint NOT NULL DEFAULT 1 REFERENCES jobs(job_id),
job_lvl tinyint DEFAULT 10,
pub_id char(4) NOT NULL DEFAULT ('9952') REFERENCES publishers(pub_id),
hire_date datetime NOT NULL DEFAULT (getdate(J))
publishers
CREATE TABLE publishers
(pub_id char(4) NOT NULL CONSTRAINT UPKCL_pubind PRIMARY KEY CLUSTERED
CHECK (pub_id IN ( 3 8 9 1 , '0736', '0877', '1622', '1756')
OR pub_id LIKE '99(0-9][0-9]'),
pub_name varchar(40) NULL,
city varchar(20) NULL,
state char(2) NULL,
country varchar(30) NULL DEFAULT('USA'))


, , . , ,
, . . . SQL

21.

969

Server 7.0 . , . ,
, ,
. .
SQL Server 7.0, . , , . ,
, , .
,
.
SQL Server 2000, . ,
. . SQL
Server . , .
,
SQL Server 2000. SQL
Server 6.x (compatibility level) 65 60, . ,
70 80 , :
t e x t , ntext image;
(computed) , ;
, ;
. varchar varbinary,
;
, CREATE STATISTICS . ,
;
, ;
, Unique
Check. (varchar, nvarchar varbinary);
, . , ,
;
ROWGUIDCOL.

IV.

970

. (, ).

Enterprise Manager, Transact-SQL. Transact-SQL. Enterprise Manager


.
Transact-SQL ALTER
TABLE, :
ALTER TABLE t a b l e
{ [ALTER COLUMN column_name
(new_data_type [ ( p r e c i s i o n ! , s c a l e ] ) ]
[COLLATE <collation_name>]
[NULL

NOT NOLL J

{ADD

DROP} ROMGUIDCOL

ADD ( [ < c o l u m n _ d e f i n i t i o n > ]


column_name AS c o m p u t e d _ c o l u m n _ e x p r e s s i o n } [ , . . . n ]
[WITH CHECK I WITH NOCHECK] ADD { < t a b l e _ c o n s t r a i n t > } [ , . . . n ]
DROP {[CONSTRAINT] c o n s t r a i n t _ n a m e | COLUMN column} [ , . . . n ]
{CHECK | NOCHECK} CONSTRAINT {ALL I c o n s t r a i n t _ n a m e [ , . . . n ] }
{ENABLE I DISABLE} TRIGGER {ALL I t r i g g e r _ n a m e [ , . . . n ] } }

:
table
, . (owner)
(database), . ,
dbo. , .
ALTER COLUMN column_name

ALTER COLUMN , . coiumn_name , , . , timestamp.


timestamp.
new_data_type [(precision!, scale])]

new_data_type ,
. ,
,
( precision)
( scale).

21.

971

,
.
,
NULL . ,
timestamp. IDENTITY , .
COLLATE <collation_name>

,
.
. " " 20.
NULL I NOT NULL

, (NULL). NULL , NOT NULL


. ,
NULL , .
,
, . NULL ,
NULL. NULL, TO
. NULL, TO
WITH VALUES.
NULL.

NULL , .
NULL ,
NULL. , NULL.

{ADD

DROP}

ROWGUIDCOL

,
ROWGUIDCOL .
u n i q u e i d e n t i f i e r .
ROWGUIDCOL.
ADD
,
( . . ) .

/2

IV.
<column_definition>

.
. " " .
column_name AS computed__column_expression

(computed) .

.
. " " .
[, . . . ]

, ALTER TABLE
.
.
[WITH CHECK I WITH NOCHECK] ADD

, . WITH CHECK

( ), ,
. WITH NOCHECK
.
- .
<table_constraint>

,
.
. " " .
DROP {[CONSTRAINT] c o n s t i n t _ n a m e | COLUMN column_name}

. c o n s t r a i n t n a m e
CONSTRAINT. COLUMN,
(coiumn_name). :
;
;

, Check, Unique,
Primary Key Foreign Key;

, (default)
;

, (rule).

21.

973

, , , .
.
, .

{CHECK I NOCHECK} CONSTRAINT



. CHECK .
. NOCHECK ,
. CHECK
FOREIGN KEY .
ALL I constraint_name[,...n]
, .
ALL , . c o n s t r a i n t n a m e . , .
{ENABLE I DISABLE} TRIGGER
(ENABLE)
(DISABLE) .

. , INSERT, UPDATE

DELETE .
DROP TRIGGER.
.
D ALL I t r i g g e r _ n a m e f , . . . n ]
, .
ALL .
.


, ,
, ,
,
. Enterprise Manager . Transact-SQL .

Q74

N.

.
sp_heip,
. :
sp_help [[Sobjname =] name]
(name) , . ,
authors pubs :
USE pubs
sp help 'authors'

s p _ h e l p ,
, . , .
, ,
.

,
. .
. :
.
:
Name , ;

owner ;

.
user table;

Created datetirae .

. ,
.
.
.
:

coiumn_name .
nvarchar(128), . .
128 Unicode.

, . , . .
nvarchar (126).

21.

975

computed yes,
. ,
(computed), . varchar (35).

Length , .
i n t .

Prec .
( . . ), . char (5).

scale .
,
. 0.
char (5).

Nuiiable yes,
. ,
(NULL).
. varchar (35).

TrimTraiiingsBianks ,
. yes, . , . .
, (n/).
v a r c h a r (35).

FixedLenNullinSource SQL Server 2000,


SQL Server 7.0, .
varchar(35).

Collation ,
.

identity. IDENTITY. :
i d e n t i t y , IDENTITY.
nvarchar(l28).
IDENTITY,
No identity column defined.

Seed ,
. numeric, .

increment .
IDENTITY.
numeric, .

3 2 . 1207

97$

IV.

Not For Replication i n t ,


0 1. 1, IDENTITY . IDENTITY ,
. 0, .

ROWGUIDCOL. ,
ROWGUIDCOL. RowGuidCol, sysname.
,
ROWGUIDCOL. , No
rowguidcol column defined.

. , . t e x t ,
ntext image .
Data_iocated_on_fiiegroup,
nvarchar(128).
. , . :

indexname , .
sysname.

i n d e x d e s c r i p t i o n ,
( , ,
. .) , . varchar(210).

i n d e x k e y s , .
, .
nvarchar (2078).

, . :

c o n s t r a i n t t y p e . , . , Check a u i d
CHECK on column a u i d . nvarchar (14 6).

Constraintname , . ,
SQL
Server 2000

(-

CK_authors_au_id_08EA5793). nvarchar (128).

D e i e t e a c t i o n , . cascade No Action.

21. 1 :\

977

U p d a t e a c t i o n ,
,

. cascade NO Action.

s t a t u s e n a b i e d , . SQL Server 2000


Check Foreign Key. , Disabled. Enabled.
, , (/). varchar (8).

s t a t u s _ f o r _ r e p i i c a t i o n ,
.
Check Foreign Key, .

i s F o r R e p i i c a t i o n . Not_For_Repiication. Check
Foreign Key (/).
varchar(19).

constraint_keys , . Check
, , Default . .
nvarchar (2078) .

. , Foreign Key, .
. , .
Table is referenced by, nvarchar (516).


,
,
. s p h e l p , ,
, . . ,
.
. , , . , , , .
, , , ,
.
32*

978

IV.

, ,
spdepends, :
sp_depends [Sobjname =] 'object'

('object')
, . . , , .

, sp_depends , .

spdepends
, sysiogins Master:
USE Master
1
EXEC sp_depends ' s y s i o g i n s

:
In the current database, the specified object references the following:
name
type
updated selected column

,
.

21.

, . ,
. syslogins
.
, .


s p h e l p , Foreign Key .
. , .
SQL Server 2000 s p f k e y s ,
. :
sp_fkeys [@pktable_name
[,[@pktable_owner =]
[, [@pktable_qualifier
{, [@fktable_name =]
[, [@fktable_owner =]
[,[@fktable_qualifier

=] 'pktable_name'
'pktable_owner']
=] 'pktable_qualifier']
'fktable_name'}
'fktable_owner']
=]
'fktable_qualifier']


:
[@pktable_name =] 'pktable_name'
,
, .
[@pktable_owner =] 'pktable_owner']
,
. , ,
(dbo,
database owner).
[@pktable_qualifier =]

'pktable_qualifier']

, , . , , .
[@fktable_name =]

'fktable_name'

, . ,
[@fktable_owner =] ' fktable pwner' ]
. ,
( [@fktable_qualifier =]

'fktable qualifier ]).

980

IV.

~)

sp_f keys , . , .


, ,
. DROP TABLE,
:
DROP TABLE t a b l e _ n a m e

, ,
tabie_name. -
. , .
, , .
.
, Foreign Key . ( ), .
(constraints)
(triggers), . (rules) (defaults) . .
,
. . ,
. .
,
. SQL Server 2000 ,
. , .
.
(truncate)
TRUNCATE TABLE.


Enterprise Manager
Transact-SQL. ,
, -

21.

981

,
. Enterprise Manager,

.
, , . ,
Enterprise Manager
Tables (. 21.2), . ( Name), ( Owner), (
) (User) (System),
( Create Date).

, . ,
Enterprise Manager .
Show system databases and objects.

. 21.2. Tables

IV.

982


, (
), .
Enterprise Manager
New Table (. 21.3),
Tables New Table.

. 21.3 New Table. , .

. 21.3.
New Table
New Table .
, , .
, . . .
,

21.

983

. ,
:
Column Name. , .

. .
.
, , ,
, ,
. ,
.
Data . , ,
.
Length. , . ( char, nvarchar, binary ) ,
, .
(, i n t , datetime, money
. .) Length .
Allow Nulls. NULL. , ,
timestamp,
NULL .
.
,
,
Set Primary Key. , , .
. 21.3 .
New Table.
, ,
.
. , :
Description.
, .
Default Value. , .
Precision. ( . .
), . ,
(decimal). numeric decimal.
( )
, (approximately),

Q84

IV.

r e a l float, (24 53 )
.
(tinyint, smallint, int bigint).

Scale.
,
. ,
.
Identity. Yes,
-.
.
Identity Seed. ,
.
Identity Increment. , -
.
Is RowGuid , uniqueidentif i e r , Yes No. ,
ROWGUIDCOL CREATE TABLE.

Default Value newid (). , . ,


. ,
uniqueidentif i e r newid ().
Formula. ,
. ,
(computed columns).
, , , . .
, , ,
NULL, . . .
Collation. ,
, . .
, .
,
, ( <database default>). ^ Collation.
, . 21.4.

21.

985
, , .
Save, .
Choose Name, ,
. .
, Enterprise Manager ,
Choose Name.


.
, , , , . 21.4.
Check. Properties,
.



, .
Properties (. 21.5), Table and Index Properties, .

Properties ,
. ,
. Selected table, , . ,
.
, Properties .
(. . 21.5) Tables
. ,
:
Selected table.
, .
.

986

IV.

. 21.5. Properties,
Tables
Owner. ( ) , . , .
Table name. Selected table ,
, .
Table Identity Column.
, -. ,
-
. , , .
Table ROWGUID Column.
, u n i q u e i d e n t i f i e r .
, .
Table Filegroup.
, . ,

987

21.

( t e x t , n t e x t image) .
(
PRIMARY).

Text FHegroup. ,
t e x t , ntext
image.
Description. .
.
Tables .
.


Relationships (. 21.6),
. Relationships ( ) , ,
, .

. 21.6. Properties,
Relationships

988

IV.

, :
Table name. , .
New. , ,
.
Delete. ,
Selected relationship.
Selected relationship.
, . ,
, .
Relationship name. , . , .
Primary key table. , . .
.
Foreign key table. , . , , .

. .
, ,
,
. ,
. , :
Check existing data on creation. , , .
, ,
, .
Enforce relationship for replication.
NOT FOR REPLICATION
CREATE TABLE. , ,
.
^
Enforce relationship for INSERTS and UPDATES.

989

21.

. :

Cascade Update Related Fields


.
,
, .

Cascade Delete Related Records


. .

Relationships .


Properties, ,
Indexes/Keys (. 21.7), ,
.
.

. 21.7. Properties,
Indexes/Keys

IV.

, , Table name , .
Selected index,
, , Unique
Primary Key. .
Unique
New. ,
Indexes/Keys . , Delete
, Unique.
, Selected index. :
Index ;
Primary key ;
Unique Unique,
.
( ) Index name. . , , Unique Primary Key. ,
Column name Order, . ,
.
.
Index Filegroup
, . Create UNIQUE .

. ,
:
Constraint
Unique;
Index .
Ignore duplicate key.
( )
, .
, . ,
. ,
,
.

991

21.

Fill factor,
, . Pat Index, .
:
Create as CLUSTERED.
. , . .
Do not automatically recompute statistics. ,
.
Indexes/Keys .


, Check Constraints (. 21.8),
Check , .

. 21.6. Properties,
Check Constraints

_ ^ _ ^ _ _

IV.


.
. , Constraint expression. ,
. , , , .
:
Check existing data on creation.

.
Enforce constraint for replication. , , NOT
FOR REPLICATION Check
CREATE TABLE.

Enforce constraint for INSERTS and UPDATES.


, .
.
Check,
.


Enterprise Manager . , ,
Transact-SQL.
Design Table, , New Table,
.

Properties, , .
. 21.9.
, . , ( Rows), , ( Filegroup),
.
Permissions,
.
\

993

21.

. 21.9.


Enterprise Manager <Delete>, Delete
. ,
, , , .
Dependencies for (. 2I.10). ,
All Tasks, View Dependencies.
Object,
, .
, . ,
, . . .
Objects that depend on
'objectname' n Objects that 'objectname' depends on1.
, . -

' 'objectname' , . .

994

IV.

,
.

. 21.10.

22


. ,
, , , , , . .
. ,
, . , .
SQL Server 2000
. - . .
(views) ,
. ,
, .
SELECT,
. SELECT. To Coin) (union) , , , .
, ,
, , . , , ,
, , . , .
. , , SELECT * FROM <table_name>. . SELECT
,

996

IV.

, , ,
. 32 .
,
,
. , , 1024. .
.
, , - SELECT, , ,
.
, ,
.
.


SQL Server 2000 :
Enterprise Manager;
Create View Wizard;
Transact-SQL.

Enterprise Manager.
. ,
, , , .
, ,
Transact-SQL, . Transact-SQL, .

Transact-SQL
Transact-SQL CREATE
VIEW, :
CREATE VIEW [ < d a t a b a s e _ n a m e > . ] [ < o w n e r > . ] v i e w _ n a m e
[(column [ , . . . n ] ) ]
[WITH < v i e w _ a t t r i b u t e > [ , . . . n ]]
.
AS s e l e c t s t a t e m e n t [WITH CHECK OPTION]

22.

997

:
<database_name>
, . ,
. SQL Server, . .
SQL Server 7.0, . ,
.
<owner>
,
. , .
d view_name
, .

. ,
, . # ##, . . SQL
Server 2000 .

(column

[,...])

,
. (column [, .. .])
,
SELECT, .
, SELECT
, , ,

. (column [, .. .])
, . ,
, .
(

SELECT. (column [, . . . ] ) .
<view_attribute>


. :
< v i e w _ a t t r i b u t e > : : = {ENCRYPTION | SCHEMABINDING I VIEW_METADATA}

:
WITH ENCRYPTION.
, .

998

IV.

syscomments,
. ,
,
.
SCHEMABINDING. ( )
( ),
. ,
,
.
( ) , .
SCHEMABINDING
, .
VIEWMETADATA.
DBLIB, ODBC OLE DB API , , .
AS select_statement

SELECT, . ,
, ,
. .
, , , . .
, :
, , , . .
ORDER BY;
COMPUTE, ;
INTO,
;

WITH CHECK OPTION

,
,
. ,
SELECT, , WHERE
price>=20, , p r i c e
20.

999

22.

sysobjects, .
, . , , syscomments. SELECT,
. WITH ENCRYPTION, TO syscomments . syscoiumns
, .
, , sysdepends,
.
:
CREATE VIEW union_view AS
SELECT title_id, title=CAST(title as char(30))+
CASE WHEN LEN(title)>30 THEN '...' ELSE " END,
value=price*ytd_sales, type='psychology1
FROM titles_psychology
UNION
SELECT title_id, title=CAST(title as char (30)) +
CASE WHEN LEN(title)>30 THEN '...' ELSE '' END,
value=price*ytd_sales, type='business'
FROM titles_business

, :
SELECT * FROM union_view

:
title id title

value

type

BU1032
The Busy Executive's Database ...
BU1111
Cooking with Computers: Surrep...
BU2075
You Can Combat Computer Stress...
BU7832
Straight Talk About Computers
PS3333
Prolonged Data Deprivation: Fo...
PS1372
Computer Phobic AND Non-Phobic...
PS2091
Is Anger the Enemy?
PS7777
Emotional Security: A N e w A l g o . . .
PS2106
Life Without Fear
(9 row(s) affected)

81859.0500
46318.2000
55978.7800
81859.0500
81399.2800
8096.2500
22392.7500
26654.6400
777.0000

business
business
business
business
psychology
psychology
psychology
psychology
psychology

Enterprise Manager
Transact-SQL. Enterprise Manager.

1000

IV.

Enterprise Manager , , Views (. 22.1). ,


( Name), ( Owner),
( ),
( Create Date).

. 22.1. Views

Views New View New . New View (. 22.2),
.
,
:
Diagram Pane. , , , , .
, Add table . Add Table, Diagram Pane. Add Table -

22.

1001

Tables, Views, Functions, , , ,


.

. 22.2. New View


,
, ,
. , , .

( SELECT).
. Sort A