240 likes | 318 Views
Learn about creating directories, checking file existence, managing registry values, error logs, tracing, and database internals in SQL Server.
E N D
Do as I Say, Not as I Do Robert L Davis
Who am I? No one of consequence.
Time is short!Please hold all questions until the next person’s session.
Exec xp_createsubdir'c:\bak'; • Creates the specified directory path • Doesn’t overwrite existing directories or files • No error if directories already exist • Error only returned if insufficient permissions
Exec xp_fileexist'c:\bak';Exec xp_fileexist'c:\bak\db.bak'; • Checks for existence of file or folder • File Exists = 1 if a file and exists • File is a Directory = 1 if a folder and exists
xp_instance_regread;xp_instance_regenumvalues;xp_instance_regenumkeys;xp_instance_regread;xp_instance_regenumvalues;xp_instance_regenumkeys;
xp_instance_regremovemultistring;xp_instance_regdeletevalue;xp_instance_regdeletekey;xp_instance_regremovemultistring;xp_instance_regdeletevalue;xp_instance_regdeletekey;
Declare @BakDirnvarchar(4000), @DefBakDirnvarchar(4000);Set @Instance =IsNull('\'+Cast(ServerProperty('InstanceName')assysname),'');Set @DefBakDir ='E:\mssql\bak'+ @Instance;-- Check default backup locationExecxp_instance_regreadN'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\MSSQLServer',N'BackupDirectory', @BakDiroutput,'no_output‘;-- If default setting null or <> to desired path, setIfIsNull(@BakDir,'')<> @DefBakDirBeginExecxp_instance_regwriteN'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\MSSQLServer',N'BackupDirectory', REG_SZ, @DefBakDir;End-- Make sure path exists (DUH!)Execxp_create_subdir@BakDir;
xp_enumerrorlogsxp_readerrorlogs [#]xp_dirtree'c:'xp_subdirs'c:\bak'xp_fixeddrives
DBCC TraceOn(3604); • Redirects output from the error log to the console • Use with DBCC PAGE
DBCC Ind ('DB','Table',Index ID); • Returns internal info about an index • DBCCInd • ('AdventureWorksDW2008R2', • 'DimAccount', • 1);
DBCC Page ('DB', File #,Page #,Option #); • Returns internal info about a page • Use with trace flag 3604 • Use with DBCC Ind • PageFID = File number • PagePID = Page # • DBCCPage • ('AdventureWorksDW2008R2', 1, 3458, 3);
DBCC Page ('DB', File #,Page #,Option #); DBCCTraceOn(3604); -- PageFID = File Number, PagePID= Page Number DBCC Page('AdventureWorksDW2008R2', 1, 3458, 3) ;
Do as I Say, Not as I Do Thank You! • The PowerPoint slide-deck will be available on my website: • http://www.sqlsoldier.com