Skip to content
This repository

SQL Server DBA Code and Helpful Scripts

branch: master
README.md

SQL Salt

SQL Server Database Administration Code and Helpful Scripts


AdminMisc

DAC

AdminMisc_DAC_ConnectToDAC.txt
AdminMisc_DAC_EnableRemoteDAC.sql
AdminMisc_DAC_GetDACPort.sql

Misc

AdminMisc_Misc_ConnectToLockedOutInstance.txt
AdminMisc_Misc_ReadErrorLogToTempTable.sql
AdminMisc_Misc_TraceFlags.txt

CentralManagementServers

ServerGroups

CMS_ServerGroups_CreateNewServerGroup.sql

Servers

CMS_Servers_RegisterServer.sql

Database

Accessibility

Database_Accessibility_MultiUserSingleUserRestrictedUser.sql
Database_Accessibility_OnlineOfflineEmergency.sql
Database_Accessibility_ReadOnlyReadWrite.sql
Database_Accessibility_StateForAllDBs.sql

FileStream

Database_FileStream_EnableFileStream.sql

Objects

Database_Objects_ChangeOwnership.sql
Database_Objects_CreateTableVar.sql
Database_Objects_CreateTempTable.sql
Database_Objects_GetObjectOwnership.sql
Database_Objects_GetPartitionDetails.sql
Database_Objects_SparseColumnCreate.sql

Storage

Database_Storage_DbFileSpaceUsageStats.sql
Database_Storage_MoveDatabaseFile.sql
Database_Storage_RecordAndErrorLowDiskSpace.sql
TableSpace_GetSpaceAndPagesByUserTable.sql
TableSpace_GetSpaceAndPagesForAllUserTables.sql

DBMail

Setup

DBMail_Setup_GmailForDBMail.txt

DML

Delete

DML_Delete_DeleteLargeDataByBatches.sql

Indexes

Heaps

Indexes_Heaps_GetAllHeapsForDb.sql

Physical

Indexes_GetIndexesByTable.sql
Indexes_Physical_GetFragmentationBasedOnPageCount.sql
Indexes_Physical_GetRowsAndSpacePerIndex.sql
Indexes_Physical_IndexFragmentationSummary.sql
Indexes_Physical_RebuildReorganize.sql
Indexes_Structure_GetIndexedColsForAllTables.sql
IndexFragmentationThreshold.sql

Usage

Indexes_Usage_GetIndexUsageStats.sql
Indexes_Usage_GetUnusedIndexes.sql

Instance

Connectivity

Instance_Connectivity_CurrentConnectionEndPoints.sql
Instance_Connectivity_CurrentConnectionInfoWithSqlText.sql

Databases

Instance_Databases_GetLogFileConsumptionForAllDBs.sql
RecoveryModel_GetNonFullRecoveryModelDBs.sql

GeneralConfig

Instance_GeneralConfig_GetMaxErrorLogCount.sql
Instance_GeneralConfig_ServiceAccounts.sql

LocksLatches

Instance_Locks_DeadlockInfoToErrorLog.sql
Instance_Locks_InstanceLocksSummary.sql
Instance_Locks_LockEscalationDisable.sql

Storage

BufferPool_DataCache_TotalSizeOfDataPages.sql
BufferPool_PlanCache_ClearAdHocPlans.sql
BufferPool_PlanCache_ClearCache.sql
BufferPool_PlanCache_CountsByObjType.sql
BufferPool_PlanCache_RecompileProc.sql
BufferPool_PlanCache_StoredProcsForDB.sql
BufferPool_PlanCache_StoredProcsLastCompiled.sql
BufferPool_Storage_PlanCacheDataCacheSizeByDB.sql

Waits

Instance_Waits_BenignWaits_Pre2012.txt
Instance_Waits_CurrentBlockedRequests.sql
Instance_Waits_CurrentUserWaits.sql
WaitStatsExplained_1_CreateTable.sql
WaitStatsExplained_2_CreateProc.sql

IO

Performance

IO_Performance_DatabaseFilesStallDurationsBytesReadWritten.sql

PBM

Conditions

PBM_Conditions_GetUserCreatedConditions.sql

Facets

PBM_Facets_PossibleEvaluationModesPerFacet.sql

UsefulPolicies

PBM_UsefulPolicies_AutoCloseOff.sql

PowerShell

Databases

PowerShell_Databases_GetDbOwner.ps1
PowerShell_Databases_ScriptGenerator.ps1

EventLog

PowerShell_EventLog_GetSQLErrors.ps1

Hardware

PowerShell_Hardware_GetNumberOfCPUCores.ps1

Modules

PowerShell_Modules_GetAvailableModules.ps1
PowerShell_Modules_ProfileImportModule.txt

PerfMonStarter

PerfMonStarter.ps1

Processes

PowerShell_Processes_GetTopMemoryConsumingProcesses.ps1

Services

PowerShell_Services_GetNonAutomaticSQLServices.ps1
PowerShell_Services_GetStoppedSQLServices.ps1

Recoverability

AttachDetach

Recoverability_AttachDetach_AttachDbWithNoLogFile.sql

BackupRestore

BackupRestore_TestBackupDatabaseFromBackupFile.sql
Recoverability_BackupRestore_BackupDatabase.sql
Recoverability_BackupRestore_RestoreDatabase.sql

Corruption

Recoverability_Corruption_CorruptCI_FOR_TESTING_ONLY.sql
Recoverability_Corruption_CorruptNCI_FOR_TESTING_ONLY.sql

Snapshots

Recoverability_Snapshots_CreateSnapshot.sql
Recoverability_Snapshots_RevertToSnapshot.sql

RI

FK

RI_FK_GetFkReferences.sql

Security

Certificates

Security_Certificates_CreateCertEncryptWithPassword.sql

Principals

Security_Principals_CreateLoginlessUser.sql
Security_Principals_DatabaseAddRoleMember_2012.sql
Security_Principals_DatabaseAddRoleMember_Pre2012.sql
Security_Principals_GetInstanceLogins.sql

Triggers

LogonTrigger_1_CreateLoginAdmissionTable.sql
LogonTrigger_2_CreateAddLoginPermittedTimeStoredProcedure.sql
LogonTrigger_3_CreateLogonTrigger.sql

ServerMonitoring

Instance

ServerMonitoring_Instance_CreateDatabaseObjects.sql
ServerMonitoring_Instance_CreateServerObjects.sql
ServerMonitoring_Instance_GetServerDetails.ps1

JobScripts

ServerMonitoring_JobScripts_FreeFileSpace.sql

Logging

ServerMonitoring_Logging_CreateErrorObjects.sql

SQLServerAgent

Alerts

SQLServerAgent_Alerts_CreateAlertsSeverError.sql
SQLServerAgent_Alerts_GetRecentTriggeredAlerts.sql

Operators

SQLServerAgent_Operators_CreateOperatorWithEmail.sql

XE

Misc

XE_Misc_ReadXELogFile.sql

Performance

XE_Performance_SlowSQLStmts.sql

Something went wrong with that request. Please try again.