Tải bản đầy đủ - 0 (trang)
Chapter 2. How Does SQL Server Work?

Chapter 2. How Does SQL Server Work?

Tải bản đầy đủ - 0trang

IntroducingTriggers

UsingTransactionstoProtectDataIntegrity

AdministrativeFunctions

WorkingwiththeTransactionLog

Summary



Introduction

FromtheveryfirstHitchhiker'sGuide,Iassumedthatmy

readersunderstoodSQLServeraswellastheroutetheytake

toworkeverymorning.Theykneweveryshortcutandback

alleytobeatthetrafficandhowtobypassthatspeed-trapover

bythelake.Basedonquestionsfromthenewsgroupsandthose

attendingmyconferencesessions,it'sclearthatsomeofyou

wouldliketoknow,orneedtoknow,alotmoreaboutSQL

Server'sinnerworkings.Inordertogetthebestperformance

outofanyengine,youreallyshouldknowwhatmakesittick

andpurr.No,Idon'tplantogetintotheintimatedetailsofthe

queryengineandexactlyhowitchoosesoneindexover

anotherorhowthefilesystemwritesdatatothedrive,butIdo

plantoprovideyouwiththeknowledgeyouneedtogetthe

mostoutofthequeryengineandoptimizewhatgetswrittento

disk.

SinceSQLServerhascapturedabout50%ofthemarket,a

numberofdevelopers(perhapsyou)areintheprocessof

migratingfromAccess/JET,Foxpro,MySQL,oroneoftheother

databasemanagementsystemsthatyou'veoutgrown.You

mightalsobetransitioningfromoneofthe"enterprise"-class

DBMSs,likeOracle,DB2,orInformix,orsimplywantto

improveyourSQLServerskillset.Ontheotherhand,youmight

simplybereadytomigratefromSQLServer2000or,ifyou

workforthegovernment,perhapsSQLServerVersion7.0or

earlier.Thischapteroutlineshowtochooseanappropriate

versionofSQLServer,howtheserverhandlesconnectionsand

security,how(insomedetail)SQLServerprocessesthequeries

yousubmit,andhowthedataisreturned.TheinformationI

providehereshouldhelppreventyoufrombeingsurprisedat

SQLServer'sbehavior,performance,orlackthereofasyour

applicationputsitthroughitspaces.Ican'thopetoduplicate

SQLServer'svoluminousdocumentationIdon'tplantotry.Ido



hopethatthepointsIraisemakeyouawareofthebase

featuresaffordedbySQLServerespeciallythenewfeatures

exposedbySQLServer2005.







ServersandVersions

WhilethisbookcanonlyattempttokeepupwithMicrosoft's

ever-morphingversionconfigurations,itcantrytooutlinethe

basicversions,highlightthedifferences,andnotewhereeach

versionisbestappliedtoyourapplicationrequirements.Yes,I

touchedontheseissuesinChapter1,"Application

Architectures,"whenIsuggestedhowtochooseoneversionof

SQLServeroveranother.Inanycase,Isuggestyoulookon

Microsoft'swebsite[1]forup-to-the-minutedetailsandprices.

Basically,therearenowsixbasicversionsofSQLServer

2005andoneversionthatonlycallsitselfSQLServer,butisn't:

[1]www.microsoft.com/sql/howtobuy/default.asp



SQLServer2005EnterpriseEdition:Thisisthemost

comprehensiveversionofSQLServerandmostexpensive(it

retailsfor$14,000orso).Itcontainsacomprehensiveset

oftoolstocreate,manage,tune,andprofiletheDBMS.It

alsoincludesmanyfeaturesthatlargecorporateproduction

sitesneed.No,Idon'texpectalotofyouhaveaccessto

thisversionunlessyouworkinalargecorporate(or

independentlywealthy)organization.Thisversionisthe

onlyplacethatyoucangetthenewReportBuilder.No,this

isnotjustReportingServices,butanentirelynewreporting

interface.

SQLServer2005DeveloperEdition:ThisisalicenserestrictedversionoftheEnterpriseEdition.Itgenerally

costs$50orlessandincludesallofthetoolsand

functionalityincludedintheEnterpriseEdition.Thisversion

cannot(bylicense)beusedinaproductionenvironment.

Thiseditionispopularwithdevelopers(andauthors),asit

hasallthetoolstheyneedtomanagedatabases,users,and

rights.Unfortunately,sinceitexposesfunctionalitynot



availableinotherversions,applicationsdevelopedagainst

theDeveloperEditionmightnotworkagainstthemore

affordableversions.Justbecognizantofthefeaturesyou're

accessing.Theaforementionedwebsitehasachartthat

liststhespecificfeatures.IsummarizethatchartinFigure

2.1.



Figure2.1.ComparingversionsofSQLServer.



[Viewfullsizeimage]



SQLServer2005StandardEdition:Supportsmost

functionalityandtoolsincludedintheEnterpriseEdition,

exceptthehigh-endfeaturessuchasAdvancedAnalysis

FeaturesforOLAP,ComprehensiveAnalysisServices,

DistributedPartitionedViews,HighAvailabilityextensions,

VirtualInterfaceSystem-AreaNetwork,andWeb-enabled



analysis.ItalsodoesnothavethenewReportBuildera

featureyoumightconsiderifyouwantyourcustomersto

writetheirownreportsPeterandIarenotthatthrilledwith

it.Forthoseconsideringawaytomanageanddistribute

reportsonamorelimitedbasis,you'llfindthatReporting

ServicesishostedinvirtuallyallversionsofSQL

ServereventheExpressbutnotinSQLServerEverywhere.

TheStandardeditionislimitedinthesensethatitsupports

only4CPUsbutanunrestrictedRAMcachebutit'smore

expensivethantheSQLServer2000version:Itretails

between$2,800and$3,000,buttheWorkgroupeditionis

cheaperthantheoldStandardedition.Newfor2005isthe

abilitytomirrorthedatabaseandautomaticallyredirecta

clientintheeventofdatabasefailure(postSP1).Italso

supportsthoseofyouwhoplantousethenew64-bit

processorsfromIntelandAMD.Inthisversion,"passive"

serversarefree.Thatis,youcansetupclustering,backup,

andrecoveryserversatnoadditionalcost.

SQLServer2005WorkgroupEdition:Thisversionis

newfor2005andprettymuchreplacestheStandard

edition.It'smeanttoprovidealower-costbridgebetween

thefreeExpresseditionandthenowpriceyStandard

edition.It'salsocheaperthantheoldStandard

editionretailingforabout$740to$3,900,dependingon

howyouchoosetoscalethelicenses.It'sfeature-limited

liketheExpresseditionit'sheldtotwoCPUsand3GBof

buffercache,soit'sdesignedtobeacheaperstepupfor

thoseworkingwiththeExpresseditionthatneedmore

performanceandscalability.

SQLServer2005ExpressEdition:Thisversionisfree,

butit'slimitedevenfurtherto1GBRAMcacheandoneCPU.

SQLServerExpresseditionisdesignedtoreplaceMSDEbut

leavesthethreadgovernorbehind.Theonlylimiton

performanceisthebuffercacheandsingle-processor

support.Itnowincludesatoolssuite,betterperformance,



andscalability.I'lltakeacloserlookatthiseditionnext.

NotethatSQLServerExpressalsochangeshowreplication

issupportedit'sanimportantdifference,sowhenitcomes

timetoconvertanexistingMSDE-basedsystem,beaware

thattherearenewreplicationrestrictions.

SQLServer2005ExpressAdvancedServicesEdition:

ThisversionisidenticaltoSQLServerExpress,exceptthat

itcomesbundledwithReportingServices,full-textsearch,

andacustomizedversionofSQLServerManagement

Studio.Therealdifferencehereisthatithasabigger

footprintit'sabout235MBondisk.Thismakesitharder

(moreexpensive)todownloadanddeploy.

SQLServerEverywhere:AsIsaidinChapter1,thisisn't

reallySQLServer,butitplaysSQLServerinasoapopera.

Well,notreallyit'sreallySQLCE,er,SQLMobileEdition

renamed.Whileit'sverydifferentfromSQLServer,itcan

playanimportantrolewhenyourapplicationneedsalight,

fast,easilydeployableandencryptabledatabase.I'llbe

providingalotmorecontentinmynewEBook.Checkthe

supportsitefordetails.

SinceIexpectthatmostreadersareinterestedintheStandard,

Workgroup,andSQLExpressversionsofSQLServer2005,I

don'tplantospendalotoftimetalkingabouttheadvanced

featuresaffordedbytheEnterpriseEditionI'llleavethatupto

Microsoft.Alloftheseversions(exceptSQLServerEverywhere)

usethesamecorebinaryexecutables.Theyallexecutethe

sameT-SQL,usethesamedatabasefiles,andrunthesame

server-sideexecutables,includingCLR-basedstored

procedures,functions,triggers,aggregates,anduser-defined

types.ThismeansapplicationsdevelopedfortheExpress

EditioncanbeeasilyupgradedtotheStandardorEnterprise

editions.



SQLServerSide-By-Side

OneoftheMSDNleadsatMicrosoftaskedmetoincludemy

ownside-by-sidecomparisonchartthathighlightsthe

differencesamongthevariouseditions.Whilethechartshown

inFigure2.1mightnotbeparticularlyscientific,itdoesputthe

versionsintoaslightlydifferentperspectivethanthechartsand

sexymarketingmaterialprovidedintheMicrosoft

documentation.Sure,thenumberofuserssupportedispretty

arbitraryasyou'veseensofarinthischapter(andwillfindout

laterinotherchapters),therearealotoffactorsthatgatehow

muchworkandhowmanyuserscanbesupportedonasingle

SQLServerlicense.Ofcourse,thisnumberassumesthatyou

choosetousethe(moreexpensive)processorlicenseorhave

purchasedasufficientnumberofClientAccessLicenses(CALs).

AlloftheseversionsaresupportedbyVisualStudiotoone

extentoranother.Insomecases,you'llhavetorevertbackto

SQLServerManagementStudiotogetsomerealworkdone.

Don'tthrowawayyourtoolsetbeforeventuringintosupport

SQLServerEverywhereit'salsosupportedbyVisualStudioand

SQLServerManagementStudio(tosomeextent).



Introducing...SQLServerExpressEdition

InaSQLServerMagazineeditorialpublishedin2003,Mike

Oteyhitanervewhenhesaidthat"MSDEisfree,but

unsuitableformostmulti-userprojects."Idon'tthinkthisis

true.Ifollowedupwithanarticlethat,foronereasonor

another,wasneverpublished.WhatIattemptedtodointhat

articlewastohelptocorrectanymisconceptionsthereaders

(andMike)hadaboutMSDEandbetterdescribewhatitisand

whyit'simportanttoSQLServerdevelopers.Well,clearly,it's

toolatetobetalkingaboutMSDEit'salreadymorphedintothe

SQLExpresseditionofSQLServer.Atthispoint,Iwantto



compareMSDEandthenewWorkgroup,Express,and

"Everywhere"versionstohelpeveryone(evenMr.Otey)

understandwheretheseeditionsfitandwhattheyarecapable

ofdoing,andunderstandtheirlimitations.

IhavebeenchampioningMSDEforquiteawhilenowwellbefore

IleftMicrosoftin2000.Asaresult,Ifeelacertainkinshipto

thisparticularversionofSQLServer.Ilikeditbecauseit

provideda"free"alternativetoJETandwasafarbetterchoice

forsmall-tomedium-sizeapplicationsneedingaccesstoa

professional,morescalable,andmoresecureDBMS.Isaw

MSDE(andnowSQLServerExpress)likethefreecigarettes

giventoGIsintheirCrationsbutwithoutriskoflungcancer.

TheseSKUsaredesignedtogetdevelopersatalllevels

comfortablewithwritingapplicationsthatdependonSQL

Server'suniquefeatures.Whentheyfindthatthefreeversions

aren'tenough,theyhavetocomebacktoMicrosoftforafixon

therealthing.

Foryearsafteritsrelease,MSDEwasanorphanitreallydidn't

haveitsownproductmanagertochampionit,protectit,and

helpeducatethedevelopercommunity.Iwroteanumberof

articlesaboutMSDEandcontinuedtolurkonthepublic

newsgroupsinanattempttokeepthedevelopercommunity

informedaboutMSDEandhowitcanbestbeused.Thiswasan

uphillbattle,asMSDEwasfarhardertoinstallthanJETand

generallymisunderstoodthankstocountless"experts"telling

developersthatMSDEwaslimitedtoeight(orfive)

connectionsit'snot.

Allofthathaschanged.MicrosoftandtheSQLServerand

VisualStudioteamshavefullyembracedMSDEintheSQL

ServerExpressEdition(SSEE).Today,there'sanentireteam

dedicatedtoSSEE.No,I'mnotthrilledabouthowit'sbeing

"positioned"inthemarket,butasdevelopers,wecanuseitas

wethinkbestregardlessofhowMicrosoftwantstopositionit.

Theproblem(asIseeit)isthatSSEEisbeingtargetedtosocalled"hobbyists"peoplebuilding"toy"applications.Incontrast,



IseeSSEEasaviableSQLServerengineforsmall

businesssuitableforusealmostanywherethatJETisused

today.Itcansupportonetohundredsofusersiftheapplication

iswrittencarefullyandcanevenbeusedtohostdataservices

onawebsite.WiththeannouncementoftheAdvanced

ServicesEdition,SQLServerExpressnowsupportsfulltext

searchandReportingServices.Thatputsitintheclassof

seriousDBMSenginesit'smorethanatoy.



WhatIsSQLServerExpress?

AsIsaid,SQLServer2005ExpresseditionisMicrosoft's

replacementfortheMSDEEditionofSQLServer.Itusesthe

sameSQLengineimplementedinSQLServer2005butcomes

packagedforusewherefarfewerusersareexpectedtobe

servicedinsmallerenterprisesandsmallerwebsites.The

biggestdifferencesbetweenMSDEandSSEEareinhowthey're

installedandhowtheylimitscalability.We'llseehowSSEE's

architecturehasbeencompletelyredesignedtomakeitsuse

morelikethewayyouinstallanduseAccess/JET

databaseswithoutthedeploymentproblemsassociatedwith

MSDE.SincethenewAdvancedServicesversionofSSEE

includesReportingServices(forlocaldata)andfull-textsearch,

youmightfindit'snotnecessarytoupscaletoWorkgroupor

Standardeditionsjusttogetthosefeaturesatleast,notright

away.

SQLServerExpressEditionhasgonealongwaytoward

buildingabettersolutionforapplicationsthatneed:

AreplacementforJETdatabases.Thatis,aDBMSthatcan

betakenoverbyanITdepartment,ifneededonethat

meetsHIPAsecurityrequirements,usesallofthepowerof

SQLServertoprotectdataandreferentialsecurity,and

doesallofthisregardlessofhowtheusermistreatsit.



ADBMSthatcanscalefromasingleusertoseveraldozen

userswithoutrequiringanupgradetoSQLServerStandard

editionwithouthavingtoworryaboutagovernordegrading

performancewhenit'sneededmost.

ADBMSthatrunsthesamestoredprocedures,functions,

aggregates,user-definedtypes,andextendedstored

procedures,whetherthey'rewritteninT-SQL,inC++,orin

aCLRassembly.

ADBMSthatcanworkaseasilyonasmallwebsiteasina

client/serverconfiguration.

ADBMSenginethatcanbeinstalledeasilyandcanbe

easilyupdatedinplacewhenservicepacksaremade

available.Thismeanssetuproutinesthatareeasyto

integrateintoyourapplication'sdeploymentscripts.

ADBMSthatcanbeaccessedbysimplypointingtoaDBMS

fileinstalledwithorpassedtoanapplicationincode.

BecauseSQLServerExpressisdesignedtopermit

databasestobeattachedon-the-fly,it'seasierthaneverto

use"loose"SQLServerMDFdatabasefilesanddeploythem

withyourapplication.Thismakesitfareasiertodeploya

stand-aloneSQLServerExpressdatabase.MDFfile,as

couldbedonewithJETdatabases.

ADBMSthatexposesastandardwaytorefertoashared

instanceofSQLServer.WhenSSEisinstalled,bydefault,

it'sinstalledwiththesameinstancename:SQLEXPRESS.

Thismeansyourapplication'sconnectionstringcanmore

easilytargettheSQLServerExpress,whetherit'sinstalled

onthelocalsystemoronthelocalareanetworkassuming

theapplicationsetuproutinestakeadvantageofthis

feature.I'lltalkaboutinstanceissuesalittlelater.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 2. How Does SQL Server Work?

Tải bản đầy đủ ngay(0 tr)

×