sql server command line tools to manage your server
DESCRIPTION
important sql toolsTRANSCRIPT
-
5/14/2015 SQLServerCommandLineToolsToManageYourServer
http://www.mssqltips.com/sqlservertip/1029/sqlservercommandlinetoolstomanageyourserver/ 1/4
enteremailaddress Join
LatestSQLServerTips
SQLServerMonitoringwithPowershellandtheSQLServerPlatform:DataCollection(Part1of3)
TheSQLServerJobManagementYouWishYouHad
SQLServerCommandLineToolsToManageYourServer
By:GregRobidoux|ReadComments(4)|RelatedTips:More>Monitoring
ProblemThereareseveralusefulcommandsandfunctionsthatareavailableinSQLServer,butnotknowingwhattheyareorwheretofindmoreinformationaboutthemissometimesaproblem.Havingthesecommandsatyourfingertipsisveryhelpfulwhentryingtosolveaproblemorforjustdoinggeneralanalysisonyourdatabaseinstances.
SolutionFollowingisalistofusefulcommandsthatcanberunusingQueryAnalyzer.AlotofthisinformationcanberetrievedusingEnterpriseManager,butitisoftenfastertousethesecommandsdirectlyinQueryAnalyzeraswellasmoredetailedinformationisprovided.EachofthesecommandshasdifferentfunctionalityandknowingthatthecommandexistsandwhattypesofinformationtheyproduceisextremelyhelpfulinmanagingyourSQLServerenvironment
Command Purpose SampleUsagesp_helpdb Thisgivesyouinformationaboutalldatabasesinthe
instanceorspecificinformationaboutonedatabase. sp_helpdbsp_helpdbdatabasename
fn_virtualfilestats Thiscommandwillshowyouthenumberofreadandwritestoadatafile.Usesp_helpdbwiththedatabasenametoseethelogicalfilenumbersforthedatafilesandthedatabaseid.
SELECT*FROM::fn_virtualfilestats(dabaseid,logicalfileid)SELECT*FROM::fn_virtualfilestats(1,1)
fn_get_sql() ReturnsthetextoftheSQLstatementforthespecifiedSQLhandle.ThisissimilartousingDBCCINPUTBUFFER,butthiscommandwillshowyouadditionalinformation.ThiscanalsobeembeddedinaprocesseasierthenusingtheDBCCcommand
MSSQLTipsadditionalinfo
DECLARE@Handlebinary(20)SELECT@Handle=sql_handleFROMsysprocessesWHEREspid=52SELECT*FROM::fn_get_sql(@Handle)
sp_lock ThiscommandshowsyouallofthelocksthatthesystemiscurrentlytrackingThisissimilartoinformationyoucanseeinEnterpriseManager.
sp_locksp_lockspidsp_lockspid1,spid2
sp_help Thiscommandgivesyouinformationabouttheobjectswithinadatabase.Thecommandwithoutanobjectnamewillgiveyoualistofallobjectswithinthedatabase.
sp_helpsp_helpobjectname
sp_who2 GivesyouprocessinformationsimilartowhatyouseewhenusingEnterpriseManager. sp_who2
sp_who2spid
sp_helpindex Givesyouinformationabouttheindexesonatableaswellasthecolumnsusedfortheindex.
MSSQLTipsadditionalinfo
sp_helpindexobjectname
sp_spaceused Thiscommandshowsyouhowmuchspacehasbeenallocatedforthedatabase(orifspecifiedanobject)andhowmuchspaceisbeingused.
sp_spaceusedsp_spaceusedobjectname
DBCCCACHESTATS Displaysinformationabouttheobjectscurrentlyinthebuffercache. DBCCCACHESTATS
DBCCCHECKDB Thiswillchecktheallocationofallpagesinthedatabaseaswellascheckforanyintegrityissues. DBCCCHECKDB
-
5/14/2015 SQLServerCommandLineToolsToManageYourServer
http://www.mssqltips.com/sqlservertip/1029/sqlservercommandlinetoolstomanageyourserver/ 2/4
TroubleshootingCommonSQLServerBulkInsertErrors
SQLServerAnalysisServiceLevelsofGranularity
MonitorSQLServerTransactionLogFileFreeSpace
FreeSQLServerLearning
Avoiding,Detecting,andRepairingSQLServerDatabaseCorruption
IsHApittingSQLDatabaseAdminsagainstVMAdmins?KeepingthePeacewithSANLessclusters.
TheArtofStressFreeDatabaseAdministration
SQLServerAuditwithSQLComplianceManagerandSQLSecure
HowtoRollyourOwnValue,RegExandSoundExPatternProfilerinSSIS
GregRobidouxisthePresidentofEdgewoodSolutionsandacofounderofMSSQLTips.com.
Viewallmytips
RelatedResources
MoreSQLServerDBATips...
DBCCCHECKTABLE Thiswillchecktheallocationofallpagesforaspecifictableorindexaswellascheckforanyintegrityissues. DBCCCHECKTABLE
(tableName')
DBCCDBREINDEX Thiscommandwillreindexyourtable.Iftheindexnameisleftoutthenallindexesarerebuilt.Ifthefillfactorissetto0thenthiswillusetheoriginalfillfactorwhenthetablewascreated.
MSSQLTipsadditionalinfo
DBCCDBREINDEX(tablename,indexname,fillfactor)DBCCDBREINDEX(authors,'',70)DBCCDBREINDEX('pubs.dbo.authors',UPKCL_auidind,80)
DBCCPROCCACHE Thiscommandwillshowyouinformationabouttheprocedurecacheandhowmuchisbeingused.Spotlightwillalsoshowyouthissameinformation.
DBCCPROCCACHE
DBCCMEMORYSTATUS DisplayshowtheSQLServerbuffercacheisdividedup,includingbufferactivity. DBCCMEMORYSTATUS
DBCCSHOWCONTIG Thiscommandgivesyouinformationabouthowmuchspaceisusedforatableandindexes.Informationprovidedincludesnumberofpagesusedaswellashowfragmentedthedataisinthedatabase.
DBCCSHOWCONTIGDBCCSHOWCONTIGWITHALL_INDEXESDBCCSHOWCONTIGtablename
DBCCSHOW_STATISTICS Thiswillshowhowstatisticsarelaidoutforanindex.Youcanseehowdistributedthedataisandwhethertheindexisreallyagoodcandidateornot.
DBCCSHOW_STATISTICS(tablename,indexname)
DBCCSHRINKFILE Thiswillallowyoutoshrinkoneofthedatabasefiles.Thisisequivalenttodoingadatabaseshrink,butyoucanspecifywhatfileandthesizetoshrinkitto.Usethesp_helpdbcommandalongwiththedatabasenametoseetheactualfilenamesused.
MSSQLTipsadditionalinfo
DBCCSHRINKFILE(filename,sizeinMB)DBCCSHRINKFILE(DataFile,1000)
DBCCSQLPERF Thiscommandwillshowyoumuchofthetransactionlogsarebeingused. DBCC
SQLPERF(LOGSPACE)
DBCCTRACEON Thiscommandwillturnonatraceflagtocaptureeventsintheerrorlog.TraceFlag1204capturesDeadlockinformation.
DBCCTRACEON(traceflag)
DBCCTRACEOFF Thiscommandturnsoffatraceflag.DBCCTRACEOFF(traceflag)
NextSteps
GetfamiliarwiththesecommandlinefunctionsthatyoucanputtouseimmediatelyTaketimetolearnmoreaboutthesedifferentoptionsandwhenspecificcommandsshouldbeusedandhowtheyshouldbeusedLookforfuturetipsoneachofthesecommands
LastUpdate:7/28/2006
Abouttheauthor
Print Tweet 0 BecomeapaidauthorShare 0Like
-
5/14/2015 SQLServerCommandLineToolsToManageYourServer
http://www.mssqltips.com/sqlservertip/1029/sqlservercommandlinetoolstomanageyourserver/ 3/4
SQLServerSecurityEssentials
EnterEmailAddress Join
LearnMore
Postacommentorlettheauthorknowthistiphelpedyou.Allcommentsarereviewed,sostayonsubjectorwemaydeleteyourcomment.
*Name *Email Notifyforupdates
***NOTE***IfyouwanttoincludecodefromSQLServerManagementStudio(SSMS)inyourpost,pleasecopythecodefromSSMSandpastethecodeintoatexteditorlikeNotePadbeforecopyingthecodebelowtoremovetheSSMSformatting.
Note:youremailaddressisnotpublished.Requiredfieldsaremarkedwithanasterisk(*)
GetfreeSQLtips:
*EnterCode SaveComment
Tuesday,January28,20149:47:14PMSaritHod ReadTheTip
CanyoupleasementionSQLS*PlusthisisagreatfreecommandlinetoolforSQLServer
Saturday,November03,20122:26:33AMRon ReadTheTip
Thanks.
DoyouhaveupdatesforSS2008R2?
Wednesday,July18,20122:01:25PMJeremyKadlec ReadTheTip
Sandip,
Iwouldcheckoutthesetips:
http://www.mssqltips.com/sqlservertipcategory/25/maintenance/
http://www.mssqltips.com/sqlservertipcategory/91/maintenanceplans/
HTH.
Thankyou,JeremyKadlec
Wednesday,July18,20121:51:21AMsandipdeshmukh ReadTheTip
informationregardingSQLServerCommandLineToolsToManageYourServerisverygoodwithallimportantinformation.
thanks,
ifposibblepleasesendmethealldatabasescriptwhichicanuseforDatabasemaintanance.
thanks&Regards,
SandipDeshmukh
Paragraph
-
5/14/2015 SQLServerCommandLineToolsToManageYourServer
http://www.mssqltips.com/sqlservertip/1029/sqlservercommandlinetoolstomanageyourserver/ 4/4
SponsorInformation
Follow
GetFreeSQLTips
Twitter
LinkedIn
Google+
Facebook
Pinterest
RSS
Learning
DBAs
Developers
BIProfessionals
Careers
QandA
Today'sTip
Resources
Tutorials
Webcasts
Whitepapers
Tools
Search
TipCategories
SearchByTipID
TopTen
Authors
Community
FirstTimer?
Pictures
FreeTshirt
Contribute
Events
UserGroups
AuthoroftheYear
MoreInfo
Join
About
Copyright
Privacy
Disclaimer
Feedback
Advertise
Copyright(c)20062015EdgewoodSolutions,LLCAllrightsreservedSomenamesandproductslistedaretheregisteredtrademarksoftheirrespectiveowners.