A comprehensive collection of SQL Server administration scripts organized by purpose for easy navigation and maintenance.
This repository contains 83 SQL scripts organized into 11 main categories with 24 specialized subcategories, providing maximum granularity for finding the right script for any DBA task.
SQL Agent management and job monitoring scripts
agentjob_running_time.sql- Monitor SQL Agent job execution timessqljob_average_runtime.sql- Calculate average runtime for SQL jobsagent_job_status_update.sql- Update SQL Agent job status
High availability, Always On, and HADR management scripts
alwayson_connection_details.sql- Always On connection monitoringalwayson_diagnostics.sql- Always On diagnostic utilitiesalwayson_extendedevent_details.sql- Extended event monitoringhadr_automatic_seeding.sql- Automatic seeding configurationmirroring_alwayson_endpoint.sql- Endpoint management
Backup operations and utilities
backup_eta_query.sql- Backup completion time estimationbackup_frequency_query.sql- Backup frequency analysisbackup_history_query.sql- Backup history reportingbackup_last_details.sql- Last backup detailsbackup_utilities.sql- General backup utilitiesemail_backup_history.sql- Email backup notifications
Database restore operations and recovery
restore_history.sql- Restore history trackingrestore_suspect_database.sql- Suspect database recovery
Storage and drive management scripts
DriveSpace_ps.sql- PowerShell-based drive space monitoringdrive_space_details.sql- Detailed drive space analysisdb_disk_space.sql- Database disk space monitoringdb_log_file_space.sql- Database log file space monitoring
Server and database configuration scripts
alerts/ (2 files)
configure_alerts.sql- SQL Server Agent alert configurationconfigure_serverside_trace.sql- Server-side trace setup
mail/ (1 file)
configure_dbmail.sql- Database Mail configuration
growth/ (4 files)
autogrowth_settings.sql- Database autogrowth configurationconfigure_data_movement.sql- Data movement settingsconfigure_restrict_io.sql- I/O restriction configurationdatabase_growth_settings.sql- Database growth management
credentials/ (1 file)
create_sas_backup_credential.sql- SAS backup credential creation
Database monitoring and health checks
transactions/ (1 file)
monitor_transactions.sql- Transaction monitoring and analysis
blocking/ (1 file)
head_blocker.sql- Head blocker analysis and resolution
database_health/ (3 files)
database_size_monitor.sql- Database size monitoringdatabase_state_monitor.sql- Database state monitoringlog_reuse_wait_monitor.sql- Log reuse wait analysis
progress/ (1 file)
monitor_progress.sql- Operation progress tracking
Root level (2 files)
alwayson_status_monitor.sql- Always On status monitoringcpu_scheduler_monitor.sql- CPU scheduler monitoring
Performance tuning and resource monitoring
memory/ (4 files)
memory_calculator.sql- Max server memory calculatorcheck_memory_settings.sql- Memory configuration validationsql05_virtualmemory.sql- SQL 2005 virtual memory analysisworker_threads.sql- Worker thread monitoring
cpu/ (2 files)
cpu_consuming_queries.sql- CPU-intensive query identificationrecent_expensive_queries.sql- Expensive query analysis
queries/ (1 file)
redundant_queries.sql- Redundant query detection
connections/ (1 file)
connections_details.sql- Connection monitoring and analysis
features/ (2 files)
enterprise_features_query.sql- Enterprise features monitoringazure_tde_keyvault_details.sql- Azure TDE and KeyVault details
resource_governor/ (1 file)
resource_governor_throttle_io.sql- Resource Governor I/O throttling
Security management and access control
cleanup_logins.sql- Invalid login cleanupdatabase_permissions_query.sql- Database permissions analysisdatabase_permissions_usp.sql- Permissions stored proceduredatabase_orphaned_users.sql- Orphaned user detectiongenerate_dbo_authorization.sql- DBO authorization generationsp_help_revlogin.sql- Login transfer between servers
Diagnostic and repair utilities
check_sql_backup.sql- SQL backup validationextended_events_failing_queries.sql- Extended events for failing querieskill_connections.sql- Connection termination utilityms_errorlog_syshealth.sql- Error log and system health analysisread_errorlog.sql- Error log reading utilitiesrepair_suspect_database.sql- Suspect database repairspn_check.sql- SPN validation
General utility scripts and helpers
scripts/ (6 files)
generate_credproxy.sql- Credential proxy generationgenerate_database_growth.sql- Database growth script generationgenerate_index_script.sql- Index script generationgenerate_registered_servers.sql- Registered servers scriptgenerate_schema_transfer.sql- Schema transfer scriptgenerate_shrink_log.sql- Log shrink script generation
examples/ (2 files)
simple_cursor.sql- Simple cursor examplewhile_loop_example.sql- While loop example
diagnostics/ (3 files)
dbcc_lastknowngood.sql- DBCC last known gooddefault_trace_cursor.sql- Default trace cursor utilitiesdefault_trace_details.sql- Default trace details
system/ (3 files)
datetime_cheat_sheet.sql- DateTime functions referencemachine_powerplan.sql- Power plan configurationmap_network_drive.sql- Network drive mapping
file_operations/ (9 files)
fileobject_modified_time.sql- File modification time trackingforwardedrecord_details.sql- Forwarded record analysisfulltextstatus_details.sql- Full-text status monitoringmsdtc_activity_details.sql- MSDTC activity monitoringorphaned_datalog_files.sql- Orphaned data log file detectionreplication_immediate_sync.sql- Replication immediate syncstoredproc_search.sql- Stored procedure searchstoredproc_search_query.sql- Stored procedure query searchxp_delete_file.sql- File deletion utility
-
Backup/Restore Operations:
- Use
backup/for backup-related tasks - Use
restore/for recovery operations
- Use
-
Performance Issues:
performance/memory/for memory-related problemsperformance/cpu/for CPU-intensive queriesperformance/queries/for query optimizationdrive/for storage capacity issues
-
Monitoring:
monitoring/transactions/for transaction issuesmonitoring/blocking/for blocking problemsmonitoring/database_health/for general health checks
-
Security Tasks:
security/for all login, permission, and user management
-
Configuration:
configuration/alerts/for alert setupconfiguration/mail/for email configurationconfiguration/growth/for autogrowth settings
-
Troubleshooting:
troubleshooting/for diagnostic and repair utilities
-
Script Generation:
utilities/scripts/for automated script generationutilities/examples/for learning and reference
All files follow standardized naming conventions:
- Use lowercase with underscores
- Descriptive names indicating purpose
- Category prefixes for easy identification
- Version suffixes for multiple versions (e.g.,
_v2,_v3)
- Total Scripts: 83 files
- Main Categories: 11 folders
- Specialized Subcategories: 24 folders
- Largest Category: utilities/ (23 files)
- Most Granular: performance/ (6 subcategories)
- Branch:
main - Latest Commit:
fec2e9f - Organization Date: April 10, 2026
- Script Execution: Always test scripts in non-production environments first
- Permissions: Ensure appropriate permissions before running administrative scripts
- Backups: Take backups before running configuration or repair scripts
- Documentation: Review script comments for specific usage instructions
- Version Compatibility: Check SQL Server version compatibility for each script
When adding new scripts:
- Place in the appropriate category/subcategory
- Follow the naming conventions
- Include descriptive comments
- Update this README if new categories are created
This README provides comprehensive navigation for the DBA SQL Scripts Collection while preserving the original DBA resources and links. For specific script usage, refer to individual file comments and documentation.