Date post: | 17-Feb-2019 |
Category: |
Documents |
Upload: | phungnguyet |
View: | 215 times |
Download: | 0 times |
9 9 pl p l n
4. aauawislumsGinaiu$ fln~zi?A?unisi)inni5In~u5un5'~4 ?dd5'ul~lnanm d w d
d.jzFervdaain~au.aiu urns; , A a
~~~~~ ....... ~ ..... ~ .... ~ ....... ni.j%+.j~uu0~u~0y~.~.i~~~~~~~~4~~."a..~.%1.~~~u.na~~.na~e!..n3a~~.t!~~.~.~~~~.pa ~ .............................
faut7u %G'inaiudn~msl'u a~azmsa~~nl$4~ua ina iu5a~a~am5~t7una iu i~~n i . j . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Intro to Database System
Database %I n~uuos?inP?aiaiua4nsn"u aaaziim3~nni3ndisixznrnr dil~iafi~1'6a~-aau?-?
a 3 u $ a ~ u a ~ u m m ~ s l l 4 f a u 6 ' l a i u $owCfisiu i iaapiw's Suaiou a8uZu
Data Structul.e
wPd'iiuos-aznrnrpiw&ya
1. Define and Store Database Structure : iiipiun ~aaza6~Tn'asnfis~iu$oya
2.LoadData : ~ ~ ~ ~ y a ' a i f l p i u ~ o y a 1 9
3. Store and Maintain Data :LnlIUaXgLLaV8%J,a
- w e
4.Work with Operating System : 'dz~1~l~nnls~iu~o;a~zi1nl'dd'dzaiu9l~dn'~1'6zu~ld~~~1ni'd~u
m.sdsnl l ~a6?uGoya nTeauloya
5.Security Control :fla~1~unaiudaonsl'u
6.Backup and Recover :~nii3icdnsGo;aarazni5$du
7 . Concurrency Control :na~1~~lnir lBGn~aw5'~un'uvo~{lB
8.Integriv Control : R ~ E ~ ~ P I R ~ ~ u ~ u Q S ~ V ~ ~ ~ O ~ ~
9.Data Directory :~~iin-i-i~GGn;a
Database Component
1. Hardware % ~ 5 Z ~ P 1 ~ 1 ~ $ ~ 1 Q a R 2 ' d ~ ~ 1 ~ ~ 1 6 7 ~ ~ 1 9 7 WdwfouWd~xn9~un~5~l~zuaawa~'oya1u
5"I l?$o~l9~Pl5z3~6"nlw
2. software ~nlxain-duozwiwGii~~~anixai~i9 nisdwnl~$o;ani.so"nwi~iu~iu m~d?uadi%~u
aa3.u ~ f l - d 9 a 5 ' 1 9 m ' d f l a ~ ~ P l ~ 9 5 ~ E l ~ l ~ l ~ ~ ~ ~ a
3. Data ~ ~ ; A ~ ~ ~ 9 ~ 5 o " R ~ ~ ~ l ~ l P d 5 ~ ~ l ~ l ~ l ~ ~ B ~ ~
9d 9 4. Database User f j w ~ ~ ~ z u ~ u ~ o ~ a anueiouz~snfj$o;a w ? n n a ~ 1 ~ u x z u ~ u G n q a ~ ~ I h '
5. Maintenance Procedure ~ ~ O w ~ n ~ u ~ ~ u 1 u f l l ' d 1 ~ 3 l u n?onauqu~auEnGn~a
Database User bad~?&fh 5 f l i ~
1 .User
2. Operator
3. Programmer
4. Database Administrator
5. System Analysis
i i$wudoa71uziu~o;a
Entity ~ 3 u ~ ~ ~ l B ~ ~ ~ ~ ~ f l 8 ~ n ~ u l o ; a w a i u ~ Goqa $at$unu$oyald"u7
Attribute Go;aeinsw"o~niul~n~u~~n6i9a"9$au entity
Relation : b b a i ~ ~ f l ? l ~ ~ ~ W " ~ ~ ~ ~ p l l . d 1 9 ~ ~ 9 Entity aiu Entity ~fl~nk!lbba'. Entity % d ' ~ ~ b n ' d ~ % l i
naiut?uvYu~lu$iu ccr8uGn8npli&%~$ kudo Cn8nplibadaznuaisn'no~luFd~i1fl'1u?~il~5~~
~ $ 9 i~Pj~Yh'~3u 3 d ~ " ~ l n ~ b n 1:i 1 : ~ N:M d a d
Key : primary key a d ~ f l u w k $~n~wluni~i~lnYaa~uan'uGnyaoz?si~in'u r d B
Secondary key ~ ~ ' d 0 9 1 $ l ~ ~ % ~ ~ ~ P l r i ? R 6 5 2 % ~
Compound key L W ~ O U primary key 11d&7a1f17 field ~ U f l l . d f i l W ~ R
d d d Foreign key ~$~n86%~~lb~d~uai 'b lapIa"n 6 ~ 8 1 ~ 4 8 ~ a ~ a ~ i ~ R ~ ~ l R
Database Server
Oracle
MySql
DB2, Informix
MS SQL Server
Access
Excel
etc.
Implement Software
- Install Windows 2003 Server
- Install MS SQL Server 2000
MS SQL Edition
Personal Edition
can works on the Windows 98, Windows NT Server 4.0 with Service Pack 5 or later, Windows
NT Workstation 4.0 with Service Pack 5 or later and on the all editions of Windows 2000.
This edition has some restrictions:
maximum 2 CPU
- no Distributed Partitioned Views
- no Log Shipping no Parallel DBCC
- no Parallel index creation
- no Failover clustering
- no publishing for transaction replication
- maximum 2Gb RAM
** L W ~ J ~ ~ ~ ~ W : ~ Y P ~ ~ ~ M W ~ ~ , ' U ~ ~ ' S ~ ~ ~ ~ U ~ l U l 4 ~ n s t a l l UUWrndows i d u w o r k Station 16 . Standard Edition
Standard Editioncan works on the Windows NT Server 4.0 with Service Pack 5, Windows NT
Server 4.0 Enterprise Edition and on the Windows 2000 ServeriAdvanced ServerDataCenter. This
edition has the following restrictions:
maximum 4 CPU (up to 8 CPU on the Windows NT Enterprise Edition)
no Distributed Partitioned Views
- no Log Shipping
- no Parallel index creation
- no Failover clustering
- maximum 2Gb RAM
** SW&PIUOS & 8 ~ ~ c r v e r Imi$u
Enterprise Edition
Enterprise Editioncan works on the Windows NT Server 4.0 with Service Pack 5, Windows
NT Server 4.0 Enterprise Edition and on the Windows 2000 ServeriAdvanced ServeriDataCenter.This
edition can use:
- up to 32 CPU on the Windows 2000 Datacenterup to 8 CPU on the Windows 2000
Advanced Server and on the Windows NT Server 4.0 Enterprise Edition up to 4
CPU on the Windows NT Server 4.0 and on the Windows 2000 Server
up to 64Gb RAM on the Windows 2000 Datacenterup to 8 GbRAM on the
Windows 2000 Advanced Server up to 4 GbRAM on the Windows 2000 Server up
to 3 GbRAM on the Windows NT Server 4.0 Enterprise Edition up to 2 GbRAM on
the Windows NT Server 4.0
Distributed Partitioned Views
Log Shipping
Parallel index creation
Failover clustering
** ~ 1 ~ 1 5 ~ l ~ l ~ l u s t e r i n Yg
Desktop Engine
The Desktop Enginehas no graphical user interface and is related to the MSDE, not to the SQL
Server 7.0 Desktop Edition. The size of Desktop Enginedatabases cannot exceed 2 GB. The Desktop
Enginecan use maximum 2 CPU.
SQL Server CE (Windows Mobile)
The SQL Server CE edition can works only on the Microsoft Windows CE, so it has all
restrictions of this operation system (can use only 1 CPU, no Parallel index creation, no Full-Text
Search and so on).
Evaluation Edition
The Evaluation Editioncan be used only for the test purposes to learn more about the new
features and enhancements and should be uninstalled after a 120-day evaluation period.
Before Software Install
Check System Requirement
CPU, RAM, Hard disk
- Hard disk Plan
Server Location
- Other
.MS 2003 Server CD Installer
.MS SQL 2000 Server CD Installer
.Hardware Drivers
.Network Configuration
System Requirements
Intel or compatible platform
- Pentiun~ 166 MHz or higher (Pentium 11, Pentium 111 and compatible)
- 32MB RAM (minimum for Desktop Engine), 64MB RAM (minimum for all other
editions) 128 MB RAM or more recommended
270MB (full installation), 250MB (typical), 95MB (minimum), 44 MB (Desktop
Engine) plus Analysis Services: 50 MB minimum and 130 MB typical and 80MB for the
English Query
Hard disk Plan
i g i n a s ~ o l s a l + 1 w ~ ~ l n 1 s 1 G d 1 ~ Hard disk
- n'inaiua~alun1saisFiiu4~~a i w d a ~ a h bps
- n a ~ u a ~ a s o u l u m s w ~ u w d a ~ a 3 u w ~
- plda8nalXJil~uffer wda~afiu MB sle sl - ~ a ~ i n i s a . u ~ o ~ v o ~ a ~ ~ u ~ w ~ 8 wPda8ah ns
d~:~flwv8d Hard disk
IDE (PATA)
-133 Mbps
-5400-7200 RPM
-2MB -8MB
-4.5 -12.5 ns
-Max. 4 IDElServer
SATA
- 150 Mbps -3 Gbps
-5400-7200-10000 RPM
-2MB 1 6 M B
-4 1 2 . 5 ns
- Max. NIA
SCSI T
-350 Mbps -3 Gbps
-10000 -15000 RPM
-16MB
-3 4 . 5 ns
-Max. NIA
a&r&,n**d *.<.**.%a*&!" awa C i nr*NI
SAS (SERIAL ATTACHED SCSI)
-350 Mbps -6 Gbps
-10000 -15000 RPM
- 16MB
-3 4 . 5 ns
-Max. NIA
SSD (SOLID STATE DRIVE)
-350 Mbps -6 Gbps
-0 RPM
-3 ns
- Max. NIA
** l ~ ~ ~ f l % l ~ ~ l ~ % ~ c h i ~ l w h u Tumb Drive
RAID Controller
Redundant Array of independent disks
a w n ~ u ~ a ~ v e ~ w ~ a o a 8 ~ l l o ~ a ~ % 4 a ~ o d 5 ' u d ~ ~ s ~ u ~ 1 % $ i f l ~ i ~ a i ~ ~ i ~ s 7 ~ ~ u ~ r i ~ 1 ~ l ~ i u 1 ~ a 1 1 a z d s d g
f l 3 l P J ~ i 1 ~ ~ ~ ~ ~ ~ 3 ~ 1 ~ ~ ~ 1 8 ~ ~ ~ ~ ~ ~aomsaw"usisnnan~viId~u~z~~~lwaioq 63 MD Zwaio
szduiaon"~a~rd~%BFnu6a?eli 4 szdu;~ d i d
.RAID 0 h~nd2:asfl a w e w ~ : a ~ u f l a i u a ~ a % u n i s d i ~ d l a ~ u u ~ ~ ~ a ~ n u ~ s i ~ ~ n i s r ~ u d s d v d s
l ~ y a d i s e s dddufi"isisnnanwa~ndawudiflnIiuwio $azaiswa~$eoyaff~wuw?daiuisfiI.a"siu
IiGu; ee d A
.RAID 1 PJe)fl%e~1usii disk mirroring o:dsznnuldbau hard disk 2 63~lfiu4eya
aw8ou~ugnds:nis a a i o u r n s d i s s s 4 ' ~ ~ ~ win hard disk d3~aa~6aw&a~~11~~~flu s:uu%d
~ l P J l 7 ~ ~ d ~ ~ ~ ; w o l n hard disk ~ f l ~ ~ ~ 1 ~ 9 ~ 7 1 ~ 9 i ~ ~ ~ ~ i P J n 1 n ~ 9:IGHard disk anl]ui 2 ,4 ,6
-RAID 3 a d 8 3 i Hard disk ~ d l . l & ~ 3 63
lLLaz2 ?? i I~u RAID 0 6 2 i 3 9 ~ ~ 8 U P r i o r i t ~ bit v89 1-3 e ~ ~ U ~ P J % $ H D D a i o l i i 63
-RAID 5 f l ~ i o q ~ D 3 a a ~ i n s a ~ u ~ r i o r i t ~ bit o:duflaz&uld e o u u o u I G ~ ~ ~ azuli i da
.RAID 10 W% RAID O+I a ? I u ~ i ~ w n ~ ~ n i u s : v i ~ ~ RAID o iiaz RAID 1 ahiauh ill# lye Y flisav1n~voya!~u?d?i~ei19~awa~a iaa-zflis61 mirror 4Bya (backup u'o~a) \d$'2'au
f l i s a i ~ r a w u f l l s ~ ~ ~ a r d disk
- aasr:5 Hard disk a9au?; 1 G'2 l'aidD!;?Jo~
-Hard disk $%$a?hJ;o;i %"%BRAID %@I $os~adaal'aihuau Hard d i s k ! i ~ ~ ~ d ~ ~ ? J l ~ ~ 8 ~ ~ ~ ' 2 ~ 9 1 ~
Server Location
Installing Windows 2003 Server
fisuir:t?@Ii9SQ~ 9 ~ ~ ' ~ ~ s ~ f l l S d ? ¶ J ~ e r f o r m a n c e l w d 8 ~ 0 9 ~ ~ f l l ~ ~ % B 9 1 ~ ~ 1 ~ ~ 0 ~ a
1. Install Server 2003 as "New Installation"
2. Format all the disk arrays on your server using NTFS
3. single physical server to each of your SQL Servers
4. Install Windows 2003 as a stand-alone server
5. Defragment the drives
6. Turn Off Auto update
7. Define Virtual Memory
8. Report Error
9. Performance Setting
10. User Managements
11. Disk Managements
12. Device Manager
13. Event Viewer
14. Performance meter
15. Remove any unnecessary network protocols from your sen8er
Turn off some Service
- Alerter
- Application Management
- Clipbook
-Distributed Link Tracking Server
- Fax Service
-File Replication
- FTP Service
- Indexing Service
- Internet Connection Sharing
- IntersiteMessaging
- Kerberos Key Distribution Center
- License Logging Service
- Logical Disk Manager Administrative Senrice
- Messenger
- Microsoft Search
- NetMeeting Remote Desktop Sharing
-Network DDE
-Network DDE DSDM
- Print Spooler Senrice
- QoSRSVP
-Remote Access Auto Connection Manager
- Remote Procedure Call Locator
- Routing and Remote Access
- RunAsService
- Smart Card
- Smart Card Helper
- SMTP Service
- Telnet
- Utility Manager
-Windows Installer
- World Wide Web Service
Installing MS SQL Server2000
Installation Types
SQL Server Setup offers three installation types in the Setup Type dialog box, when you install
the SQL Server 2000 Enterprise Edition, SQL Server 2000 Stan&rd Edition, or SQL Server 2000
Personal Edition, There are three installation types:
' Typical
The Typical installation option is recommended for most users. This is the default installation
option. The Typical option installs the upgrade tools, replication support. client management tools,
online documentation and so on.
Minimum
This installation can takes only 95Mb on your hard drive and contams the minimum
configuration necessary to run SQL Server. There are no upgrade tools, full-text search, client
management tools, online documentation, debelopment tools and code samples.M~crosoft recommends
this installation for users who have computers with minimum available disk space.
Custom
Tlus type of installation allows you to change any or all of the default options. Custom
installation is recommended for advanced users.
Verifying installation
Installat~on result
SQL Server Services
- Management tools
System Database
Sample Database
Check Event Log
SQL Service Management Automatically
-SQL Server Enterprise Manager
-SQL Server Service Manager
.Windows Servlce Management
Manually
.SQL Server Enterpnse Manager
-SQL Server Service Manager
.Windows Service Management
.Command line
Net (start(stoppuase) mssqlserver
Connect to Server
SQL Quely Analyzer
Enterpnse Manager
Create and Management Database
Structure
9
f iBW~lm5 create database P ~ ~ ~ G ~ ~ ~ ~ ~ ~ s L L w u K ~ M u w ~ ~ ~ ~ ~ I ~ ~ ~ d a, A d
1.Primary file ?danaflmLflEI'UY~l;av89database
2.Secondaty file ?da"38S~L~EI~8~aLd8?da"wa"fldm"P]
3.Transaction Log ~ ~ ~ f i l ~ ~ l ~ l ~ f i ~ l ~ n ] 5 ' ~ 1 d ~ ~ DB
4.File nape and location i~t%l~B~?da"
5.Sire 9JWlRL?P]~W91BSdata file and log file A 2 2'
6.File grow 41~1fl~L~P]91~4189?da"
7.Maximum size 41WlR%M~~f l91B9?d i l "
8.Collation f l 1 3 f l l ~ l l U ~ ~ l character set
DB Creation
Use Enterprise manager
d . 9 n a d d Shrinking Database z0fll3l'h~atabase $ % 9 1 ~ 1 ~ l ~ i l ~ 9 ~ ~ 0 1 ~ 1 ~ a t a file B I ~ U W W L H U ~ E ~ U
Enterprise manager
.Automatic
.Manually
Command sql
-Alter database auto-shrink
Delete DB
Enterprise manager
C SQL
.Drop database
Restrict on delete
.Database being restore
.Use by other user
-Database replication
.System database
Storage Plan
Performance or Fault tolerance
Create one file for each physical disk
Transaction log on separate disk
tempdbon a fast I10
L] RAID
.RAID 1 for redundancy transaction log
.RAID 5 for performance and redundancy
.RAID 10 performance for datafile
Security Management
.4ulhentication Mode L L ~ S L ~ U ~ d ~ ~ ~ n m i ? ~
fl Windows User mode
Mixed Mode
.Windows Users
'SQL DB User
Fired Server Roles
Fixed Database Roles
Basic of SQL Command
1. n"l$d Select
SELECTselect-list[ INTOnew-table]
[ FROM table-source] [ WHEREsearch-condition]
[ GROW BY group-by-expression]
[ H.4VINGsearch-condition]
[ ORDER BY ordcr~cnxprcssion[ ASC( DESC] I
Sample :
Select * from employee;
Select * from employee where id=2;
Select * from employee order by name asc;
select salary from employee2 group by salary having salary --- 200
2. il& Alter
-Alter table
salter table x drop column a
salter table x add a char( 1) not null default 'P'
- Alter dayabase
.Alter database auto shrink
3. ilk Drop
Table. Database, Trigger, View
Sample:
drop table employee;
drop database web-dev;
drop trigger trigger-dev;
drop view view-cust;
d 9; w
4 . d I k Enee 1 ~ ~ a ~ i ? q a f l ~ % ~ f l 4 9 ~ store procedure
Sample :
Exec sp-helpdb;
EXEC ('USE Ad\.entureWorks; SELECT EmployeeID, Title FROM
HumanResources.Employee~);
5. dl& Grant L8uins$961 security
-Database
GRANT CONNECT TO usemame;
GRANT CREATE TABLE TO usemnme;
-Object
GRANT SELECT ON ObjectTO usemame;
6.61& Revoke durnsaaihi~ security
-Database
REVOKE CONNECT From usemame;
REVOKE CREATE TABLE Fromusemame:
.Object
REVOKE SELECT ON ObjectFromusername;
7.41% View ( Store Procedure and Trigger)
Createview f l ~ 1 9 ~ ~ U ~ 9 ~ 0 9 ~ 0 ~ a ~ U 1 ~ 7 f l ~ ~ 1 8 ~ 1 5 1 9
Sample :
CREATE VIEW hiredate-view
AS SELECT c.FirstName, c.LastName, e.Emp1oyeeID. e.HireDate
FROMHumanResources.EmployeeeJOIN Person.Contactc
on e.ContactID= c.ContactID;
DROP VIEW hiredate-view:
create Trigger diO?tl~fid~~15~3LYll rdem~si~iii1wun~n~srdierutt~la~ (insert, update, delete)
Sample :
CREATE TRIGGER Trigger-name
ONTabIe-name
AFTERINSERT, UPDATE, DELETE
ASAction:
Drop TRIGGER Trigger-name;
Create Store Procedure % ~ ~ . ~ W ~ O ~ ~ ~ ~ ~ " ~ ~ ~ U % U ~ ~ ~ ~ Y ' I I I R ~ ~ I I L I L I W ~ " ~
Sample :
CREATE PROCEDUREProcedure name
AS
SET NOCOUNT ON;
SELECT LastName, FirstName, JobTirle, Department FROM
HumanResources.vEmployeeDepartment;
GO
Drop Procedure procedurename;
Backup Solutions
m ~ d 1 5 ~ ~ 3 ~ ~ ~ a u l ~ 1 ~ ~ ~ d n ^ ~ d w ~ ~ n d a " i d r n b n s n ~ ? u ~ ~ v " ~ ~ a ~ u ! d ~ ~ e r ~ : ~ ~ n i s Backup adu
.Create or modify
.Auto grow
.Shrinking database
.Create indexes
Step to backup
1. Create backup device
2. Create backup tile
3. Using muItiple backup fdes to Store Backup
4. Using backup statement
Backup data to backup device
I. create backup divice
*Use master << tt <<
-Exec spaddumpdevice,,disk . ,,mydevice , ,,d:bssql-bkk\bkkl.bak
2. run backup data
.Backup database northw~ndto mydeb Ice
Backup data file
Run backup
.Use master < c
-Backup database northwindto disk = ,, d:\ ...
Backup Log
1. create backup divice
.Use master
2. run backup log
.Backup database northwindto mydevice
3. Run backup log
.Use master <<
.Backup log northwindto disk = ., d:' t...
Restore
Database Monitoling
Performance Meter
Service Monitoring
SQL Performance
- SQL CPU
-SQL Memory
- SQL Disk
- SQL Network
Netstat Command . ,
ilk4 netstat L ~ ~ n 1 ~ 4 ~ ~ 4 W s a a H ~ P I Network a~uun'uma<audo Port ~uan~e)~asifi~lan$aq
%UIU ~ e t w o r k r ~ ~ g option
- 3 , -a Opiton i f a x 8 u f l i s ~ f 1 i s e u d o Port & v U d (~1+8qtfuq=bn$ss~~ld) %ninsu laa&
d somsahuiZ~n's aadwa~aannsozaSusiudo service i%ncdie~~an$oq (!nms~uq=an$ss~tuj aiu d d , * a d r a m lcannso.aean$oq 'liaaa~saTlui'aaav IP
-e 0piton ~ a ~ 3 ~ m ~ ~ a n 8 o ~ f i ~ l ~ ~ Z ~ i ~ q l u n i s 5 " u i a i ~ ~ ~ ~ a d i ~ q & 9 % 4 ; 2 ~ 6 ~ Opiton -s
Y I Y aSumsa~mumsd5"~ai~4sUadi~q Gsans%.aa l a d d a A d
-n Opiton 6vzrn~oun'~r -a~rdnisaanwswaa-a3uiav IP 6 ' ~ port aawuaeansoswsorara~
lca~~l~q~9, .~"lsZRdBn~oadou"ls~,cdio
Netstat Result ( i89z W D ~ W 1433)