lktlucky2002@yahoo.com Page 1 of 44 Bài 1: Gii Thiu SQL Server 2000 !"! #!!$! %!! & #'%( ( ) * +, !" +- ! . "/ "/0% #'%$!"1!!$!2!!$!34*5+, 3$/673!" #'%0 +898+,:,;&<=8>?@A&! #!!$!B"(<+CD!E'&:,/**5F"0 :,7C9/ GH G @ 3 738%""IJJI"!" JJ(2BE." 2K"L&0000 :M"N • N.4!+O&+P3+Q8P!:,;&<<+C R.KSTUV' W%0D<"+:::3X*F/"/YZ? W!&( • N ?Z9/"3=&[!\]3^_"@B/ B"28;$X@;4H!"?/!!I!(732"&: ,;&<<+CU.KSV' W%0 • N+898:!+,;&<K.<:,+Q<OC3/<$`"` 7,a"`bc0 • N.:+O&+P3ZHP!B/B"8+89C;"+Q$8@ ;898>7C"5F0000dY&"3$;e O :0 .F ! f 5 " & " 7:! e0 B" & : , < a"`K"I"!!&agDa"7!"0 • %#B(NdY&h;&<7"/7=: I! !"(0DZ9/",7!4*3&0iZ8@!!$!$X@; 7"V'0 • N#5"34*;&<a"`.B • N.:3ZHP!B/B"2"`"!I28@;>!)*0 1.1. Cài Ðt SQL Server 2000 (Installation) .3$;O:Z?TU%' W%2j%'!7+,:,! 0 '; : , ! < a"` !& a"` kK K"I"!2 a"` K"I"!!&gDa"7!"87=,!<abcI!&0 A]"+Q+,P!3/l%""Im!<F=7=] $&C_3!!&3$8@!h]$&3+,O87!=0gC 3$;Q/;"!]:,+8!<I"+,\<0i!$;O83 +,!N n]4!$;e0!7!L"$;: ,!<W!&C$;Z0 n]$;e0 !+:$;<e7, !"#3$/6P!0g"!< !$$%&'% I!( n]( )@e)*)08]:,5 C+$"6&(@agDo:,5C+$"6<P!:0D" lktlucky2002@yahoo.com Page 2 of 44 K"" 8> ! 8> 5 a"` W!"] + ! " !" m " 8>;"8>)*0gp!7$;+89?/6!!(7C ""!]$;:&_&6/!!!("0D&<!<e%L %"+,m"e6/0 !7!$;f?&"q:/$<8@]2+Y&Z %!!0';:,!2"/3m$q3"$E7""&0 1.2. Mt chút kin thc v các Version ca SQL Server P!%""I+89X8>?/6r7,["T0j0!+:%""I +rCO8C;@"M00."<:,:["T0j< "M0$8@&e0.:+QZP!M07=8Z@" T0j0D"7+:[A"M0<"c0(]CP&C 3ZH_`$"+36&0 %+,+Q$+38")0g:"m,$;: ,!"@3"8@7=O/!F0gp!$;:, ;&"""T0j"QM0@"<53&+_&7=,L&!@ 3"8@+Y&(0i+:"o<3&$;s"@[! !f+0 1.3. Các thành phn quan trng trong SQL Server 2000 +89?;"$_/O8 !"!#!!$!B2W!& B&0000.3/O&7/9/@!;"/3/"h F/"8/YZ3m0 lktlucky2002@yahoo.com Page 3 of 44 1.3.1. Relational Database EngineE.3tP!N dY&:7H4!!!3&=73!8@;!$ //"?37,7C!!""(=*P!%""I8Wk#!! u$vW#u(2uB#'2!u/#!!$!."&u#'.(0g"!:s:7Hw +_h/(Z*8)*<3&<"(P!3&7O; &<"+_7""II0 1.3.2. ReplicationE.C;"$!" /!(N V)$;:!!$!5+,4!+8934*8>L&<6/ 60%&+x/>$;:3!!$!&8C<73 +,;&$3"3"/"!!$!(3&8>5+,38+C /I"!P!Z(0A?+_/"P!$;oO/+896/6 8>L&<+,+$"ZZL3P!3$3"3"0';7=,5C$!7/ !""8>9/&0DC]$;/!"yF+:C/!"P! f+89)*+,$"+"!!$!+89+1$&"z(0 /!"f+89$7{"$| 1.3.3. Data Transformation Service (DTS,E%X*&,X!!=5 gC$;"=&@"+:!!+894!"_73 !3;73!*,84!"u!2#'P!J'%(22 %""IW0000';}}f:O&,!!!3&!!& !I(7=h&,$;s+X;I"!(:8@78"!!$! 7327+:$;f?&#DF/$;&C=<m8C"0#Df +89$7{"$c0 1.3.4. Analysis Service -%X*/YZ?!&P!%""I ##!!(4!"!!$!f~:p!]_C8$;7=, ?&+89=JI"!"($-Z[+:0#"+:%""I?/"$;= *?;F/"/YZ<m$q3573 ]7__E"$(7{6G+"\G!!(f+89 F=@"$|R0 1.3.5. English Query -%X*8>Ag!}Z5NE(y( dY&X*F/"&!!$qCWGG/!B(0 1.3.6. Meta Data Service: #X*&F/"4!+wGL"?G%!!!m0DC]%! #!!3]6&y%!!!==_?FP!!!"!!$!8 !!";"!&J0002"+::/K!&7&!&7=0000'] =&o+894!"!!$!<o;!!8+,/Y $@!!GZG8>!e:%!#!!0KO&}$;/L< "/O73P!}/@!+Y&-.] 7=:$""";$&:t_X*&0 1.3.7. SQL Server Books Online - &,iD37=,CN lktlucky2002@yahoo.com Page 4 of 44 ."5$;:+e3373!;&_]$;of?&$""7 "&?*7=,C+89"<%""I@"/:+Z7•" (0 1.3.8. SQL Server Tools -dY&$+1_P!8>X#'W( €C7,C!]_+?&"<$;O+e<"$""7"0 n+Y&8>Ch7,!=*=*=0 dO</7,+C)0dY&=*"!?&" 3?w!0g:?Z+Q$"8>@e7== ;"}_0 iC+C/(/00d@#'W\]O8hO=*&:, !!$!7=O+C4730dY&=8> 73]!:,+3$?7•Y";&!&6/4+Q$:F/"! $?&3"/"m0 .=*4$!O/7,+C0g::7HG*/G!/(?3w 7!&";+m!<8;8@;LI?*" 7,"3";+P!0 g"=*w!8<F!o8>!&51$7 "/&(""!/"/0 lktlucky2002@yahoo.com Page 5 of 44 Bài 2: Gii Thiu S Lc V Transact SQL (T-SQL) D!!E=w!<lP!JuJ!"!u!z!" I"!!z!"(WgJW!g!"!!!J(+89)*"73 @KEK"!E(5"u!0 D"$&F!f],!_DE0.F+89!R:N 2.1. Data Definition Language (DDL): dY&5+,3ZP!!!$!8+Xp!3"Q P!!$2!&XZ!!IP!!!$!0008>:; • .! "$v‚g! • W "$v‚g! • #"/ "$v‚g! D"+: "$v‚g! :,!$2`2"/"2L000 AZ*N .!!f;"!!$<J/"@R."/!&J#2."/!&g!2."! USE Northwind CREATE TABLE Importers( CompanyID int NOT NULL, CompanyName varchar(40) NOT NULL, Contact varchar(40) NOT NULL ) W!+Y&"/ƒ/!!&+-+Xp!P!!$8<!&$@(!& ."!000D"Z*&!f<."!D"!$J/" USE Northwind ALTER TABLE Importers ADD ContactTitle varchar(20) NULL #"/!+Y&f""L:!!$7\!!$! 23#'% 2435 '67"73@#hL:!!!8!$„1;(0 USE Northwind DROP TABLE Importers 2.2. Data Control Language (DCL): dY&3&_&6/<["$v!$2`2"/"000(0D8>: ;!N • V! • "7 • #& lktlucky2002@yahoo.com Page 6 of 44 AZ*N !f"/ƒ/"K$ "+89&_+@!$.""!!$! g"`8738a"`V"/f+89$7{"/O&( USE Northwind GRANT SELECT ON Customers TO PUBLIC !f[&_+@!$.""!!$!g"`P!3" K$ " USE Northwind DENY SELECT ON Customers TO PUBLIC !fL:!$\3*P!3&_+89"/ƒ/!&[8@+: USE Northwind REVOKE SELECT ON Customers TO PUBLIC 2.3. Manipulation Language (DML): dY&/-$C5+,L)!!82S/!2J2# AZ*N USE Northwind SELECT CustomerID, CompanyName, ContactName FROM Customers WHERE (CustomerID = 'alfki' OR CustomerID = 'anatr') ORDER BY ContactName USE Northwind INSERT INTO Territories VALUES (98101, 'Seattle', 2) 9 USE Northwind UPDATE Territories SET TerritoryDescription = 'Downtown Seattle' WHERE TerritoryID = 98101 USE Northwind DELETE FROM Territories lktlucky2002@yahoo.com Page 7 of 44 WHERE TerritoryID = 98101 A]/O&73H$<F=Cp7=OZ_0.F"#$; :,:…"!&7=+_+890 + :3 ;< =/ >$?@5A'BC d,;&3YZ*<$;O)*@/(/ ; $4D KO&F!f$_3/O;"<F/3/P!DE dY&Z<P!3!!$!"$v0g:5+,L3+X"$v0.F7:+Cu$v" F!+_6/+C!$2`2"/"2L00000A]O8e4" +_+89C7C"7,8@+89"$vE"((0D"Z*!D!$k2 i&."2#/"I CREATE TABLE TableX (KeyCol INT PRIMARY KEY, Description NVARCHAR(80)) .: ! "; JI "; = 8> 8 ( "; e 2";&O:?GG!&?†‡+,H30";#+895+@35 @[7:!P!7&`"(!&3:7"0 lktlucky2002@yahoo.com Page 8 of 44 AZ*N SELECT * FROM [My Table] WHERE [Order] = 10 D"Z*<u5@7&`"u<O+Q"?"Q=†‡0 EF-7, 'C"DEo:4H8w8"3=6/]73p!O7!$3" 8@";8@7)*0'C+89$}+O$q?ˆd@3"$!!!$]:! ?ˆˆ( AZ*N USE Northwind DECLARE @EmpIDVar INT SET @EmpIDVar = 3 SELECT * FROM Employees WHERE EmployeeID = @EmpIDVar + 1 GFH3, .:";";$E";EI .3-+89!R:N • 8IGN";&8>_"$v+89+L)8!$0AZ*8 uKBgSB ‰f_":,+4XZP!!$"Y 0 • (GN";&<3X_3X+!&3 3X-0AZ*8WAVf_3X$]P!0 • GN";&<3X+_3X+0D"";& ;!_";\83_"3e2_>!2L)7,0000AZ* 8%ugDŠ‹EbER‹(f_3b0 .39+89;"!$Y. BWDB…Sg.DJug/O$"&8>+89:" Q/'BVJg000Bg#(o+89!3:8!N • GN";&o_3X+$qY BDS g0 • GN";&_!$ /F=JK, .3";"f+89$7{"3$! * .3BL/":;Œ.8Œ2E2•2Ž2•000(ŒE $ 3 L.GI g8'BVJg000Bg#2' BWi2.ugDJgSB2VuDu2J…000BB2 BDS g2aŠJB0000kL<'""7u+, $C<_3/O&0 lktlucky2002@yahoo.com Page 9 of 44 F ; ? , DE5?EE+,+3?/OFZ"Y+5Ž•000•Ž+,FZ" : DwD.3.Y M NBK 'OD %Y+89/Y!3/OF/3/8<$/!2!+: u/z$/6!eP!(f/YZ]3wBLK!(8 ?Z*83"!Z&<P!3&?000!+:Bfw _7C0 M N PK F- , iw:f/YZ]$/3/8"3Y8Y +4!L"/!+r+89$<X"/("$@!+:C:< +89e;O!]7=O$<X:,w!&+_&F/" $!;&!0 K Q. &h5+,Z"$C+r7CF$!v"$&<Ow0 g:7=/"DE0 lktlucky2002@yahoo.com Page 10 of 44 Bài tp 2 SQL Server 2000 Manipulate Data and Stored Procedure K!I""`"/"/!N |0 S"L/"!!!I"u!$"IK!#'"N•u0L""N•u0( 0 .!"!!N•u0L!!0D/""u!$I"LI $/ R0 J/"u0L"u!$-9R+8 U0 .! ! ‘7K!#'’ ` 7 " ! W !!$! ‘K!#'0$’ I&&"!"!!W!!$!!"K!#'!/" !!(0D"!!!I"E/!!!.+98S j0 S ` .+8. ! .+((.98 I" " !!I"‘K!#'0$’ T0 .!I""` #B.W Bˆ!‚!!!U(2ˆ!‚I!!!( #B.W BB/"&‚.".S u …u BB.D!g!2…g!… u%g"`0$"0B/"& uKBgB/"&‚." …BD.ŠgBkD… u%B/"&‚."JgDuˆ!‚!2ˆ!‚I! aŠJBˆˆ…BD.Š‚DWDS• 'BVJg K JgD‹W"N‹Œˆ!‚I!Œ‹‹Œˆ!‚! …BD.ŠgBkD… u%B/"&‚."JgDuˆ!‚!2ˆ!‚I! Bg# .uBB/"&‚." #BWu.WDBB/"&‚." M0 .!I""`!&"L`"! . BWDBK u.B#S BWg`u ˆuJ#!2 ˆK"g!!!j(2 ˆ."g!!!j(2 ˆ !•|u/ W #B.W Bˆ."J#! 'BVJgD WgW.DJug JI"BLBB.D."J#… u%."aŠB B†g!‡•ˆ."g!( 'BVJg BDˆ."J#•BB.D%!L."J#(… u%."( BDˆ."J#•ˆ."J#Œ| JgB DJgDu."AWSBˆ."J#2ˆ."g!( JIBLBB.DuJ#… u%†u‡aŠB BuJ#•ˆuJ#( 'BVJg BB.Dˆ •| u'W.iD WgW.DJug Bg# B 'BVJg JgB D JgDu †u‡uJ#2K"g!2."J#( AWSBˆuJ#2ˆK"g!2ˆ."J#( BB.Dˆ • .u%%JDD WgW.DJug [...]... B.D ˆ • u%%JD D Wg W.DJug J#2K " g! 2 " J#( Bg# Bg# K ˆ b0 S | 0S E- T " A'0gBD " L * T L lktlucky2002@yahoo.com " ‘W g `u /" ’ " " /" ! ! L/‚ ‘ Š "’( Page 11 of 44 Bài 3: Design and Implement a SQL Server Database 3.1 C u Trúc C a SQL Server g 8 +r ] $ & 3 $ 8@ " < 7 : +C ( " +: 8> +: # I! J ! 0% J ! P! ! !$! 0 3 & ! !$! $!" 1 N • • • • N 4! ? ! !$! 7 3 " P! N 4! ? $ !& " $ Y 7 7 + ; ) N #! !$!... d, : ! !$! 8 [! 7 = C $; O $ C & F = 7 = $ 0 lktlucky2002@yahoo.com + < Y " " _ 3 P _ +_ p! C 7C !" " ! ! 4! " ! !$! 7 = 6 + 0 0D & < " / ; 7 :! e &2 $; : , L < " 3 3 ;& &C Page 20 of 44 Bài 4: Backup And Restore SQL Server 4.1 Chi n L c Ph c H i D Li u (Data Restoration Strategy) : +_ F !/ F O 8 $? 7• ! !$! " o O +89 / * 1 " +: " 7• P! :0 8> #! !$! W ! " $; O / +! O / / * 1 2 = " t2 7, ! 8> L &< +,... " 5 +, 4! ! ! P! !$ 0 dO < !$ ! +: 7 !! H 8 ] !$ 3 5 ~ : O / < 7 " " L 0 : "; BL N)* * "; BL 9 * "; O ?( 3 K! " % L BL +, 4! ! ! " S I" BL " !$ +:0 3.3 Nguyên T c Ho t Ð ng C a Transaction Log Trong SQL Server D! ! " " I " 5 +, ; 3 !& +- L & ! " ! !$! 0 3 ] & m ! 8 ! N +O < 7 : w !& +- ! ! 8 J 2 S/ ! 2 # +89 &< O [ 3 4 * 2 f "! ( ! ! /! 8 4 < "& 5 $ @ & e !! ! (2 ! +: ! ! " !! ! +89 !& +! $X !& +- s... ! " U f +89 " I" `! ] & +r +89 L & ! 8@ > +, 7 /" 7C C/ < ! ! 8! 7X/ 8 " p!0 D4 +89 < " I " " : +O& +P +, C " p! 4 0 ] 8! +89 " " $X "` $? >( " < f " $! 7 ! ] +89 < " I 0 3.4 C u Trúc Logic C a M t SQL Server Database " ! ŠO 8 e 4 " +89 /" 2 L 2 " ! 0000 g & & !& /0 3 "$v < f +89 < 4 O h$ ! & "$v = * " % & & "$v 8> " K" /‚ / †‹"$v ‹‡ /‚ 5 / $ †‹ ! !$! ‹‡ /‚ " /‚ /! "$v " 3 $ ! ! !$! _ ! !$! "$v _... ! " 3 ] 0 3 !$ !& " /" & f $C ? !& 7 ! " 0 ! s 8 $ 7^ / ! ( " 3 ! !$! 7 3 0 g p! ;" ! ] f "/& " $ 3 & "$v !$ 2 ! !$! ! ! !$! @ [! ;"0 W ) * +, "; +X 3 $3" + 3 = ! v"$ (0 3.2 C u Trúc V t Lý C a M t SQL Server Database %“ ! !$! " !!I / * _ • • • +_ " ! &( 8> / !$ #! ! " f 8@ +Y&N 4! Z ? !!I ! " " I 0 :/ O U Z ( N +Y& / I ! &(2 : Z , : 4! ! ! < !& & 0 ! !$! ! ! " 8> ! +, 8> / +89 / Y ! !$! +89 4! lktlucky2002@yahoo.com... !! & " $q 3 5 3 "; ! o $C ! _ 7{ 6 & Y !"0 ! $ e & 3 $; :! ; 7 C 4 +r e [ $ | +C $ j 8@ 7 $; e C/ $ T0 " 4 w Y P " 3 &< O P! $ 6/ +Q !0 i = < $\ lktlucky2002@yahoo.com Page 34 of 44 Bài 6: Stored Procedure and Advance T -SQL D" $ & F ! 3 "; " K" $ 6.1 S BL & " ! f ] , "0 3 d ng bcp và BULK INSERT /" L/" : , d, : , !! 0 F 7 ! ! +89 ] !$ +: / !!I ] I @ f " ! &, !! " " " 0 ! +: f !! [ !! I D L I !& 89... 3 P! $! 7 /( 8 ! !$! 8 ] !& [ 4 : ™ f ! N @ 7 3 $; : e G 0 ! ! +89 $! 7 / $; : , e "/ " Page 26 of 44 Z '; < 0 : , e ! lktlucky2002@yahoo.com ! !$! "/ ! " ! !& " "/ ! " ! 5& " 8> 9/ 8 +r Page 27 of 44 Bài 5: Data Integrity and Advanced Query Technique g: +C #! ! J & ! : +C 4! " ! !$! / Z L3 +3 ! !$! ? Z " x " !! " ! !$! +89 " x 0 5.1 Các Ph +C " • • • • • • • • 5 3 $ Z " x P! ! !$! !& : 3 7 3 !! 6&0 . lktlucky2002@yahoo.com Page 1 of 44 Bài 1: Gii Thiu SQL Server 2000 !"!. L"/""!!L/‚‘Š"’( lktlucky2002@yahoo.com Page 12 of 44 Bài 3: Design and Implement a SQL Server Database 3.1. Cu Trúc Ca SQL Server g8 +r ] $& 3 $ 8@ ". Q. &h5+,Z"$C+r7CF$!v"$&<Ow0 g:7=/"DE0 lktlucky2002@yahoo.com Page 10 of 44 Bài tp 2 SQL Server 2000 Manipulate Data and Stored Procedure K!I""`"/"/!N |0