SQL Server Scripts
open-menu closeme
Home
All SQLServer70 Scripts
Scripts & Commands
Links icon
SQL Server Documentation SQL Server Mgmnt Studio
About
Contact Us
Privacy Statement
rss
  • SQL Server Top Queries by CPU and IO: dm_exec_query_stats

    calendar Apr 4, 2026 / Apr 24, 2026 · 6 min read · sql server performance sql scripts sys.dm_exec_query_stats sys.dm_exec_sql_text sys.dm_exec_query_plan query tuning database administration monitoring execution plan  ·
    Share on: twitter facebook linkedin copy

    Find the Top CPU and IO Consuming Queries in SQL Server This script queries sys.dm_exec_query_stats to identify the most resource-intensive queries currently cached in the plan cache, showing logical reads, writes, CPU time, and elapsed time — with the full query text and execution plan for each. Purpose and Overview …


    Read More
  • SQL Server Index Fragmentation: dm_db_index_physical_stats

    calendar Apr 3, 2026 / Apr 24, 2026 · 6 min read · sql server index maintenance sql scripts sys.dm_db_index_physical_stats fragmentation database administration performance maintenance scripts indexes rebuild reorganize  ·
    Share on: twitter facebook linkedin copy

    Report Index Fragmentation Across All Tables in SQL Server This script queries sys.dm_db_index_physical_stats to report external and internal fragmentation for every index in the current database, filtering to indexes with significant fragmentation and enough pages to make maintenance worthwhile. Purpose and Overview …


    Read More
  • SQL Server Database Size Report for All Databases

    calendar Apr 2, 2026 / Apr 24, 2026 · 6 min read · sql server monitoring sql scripts sys.master_files sys.databases database administration capacity planning storage reporting maintenance scripts  ·
    Share on: twitter facebook linkedin copy

    Report Database Size in MB and GB for All SQL Server Databases This script queries sys.master_files and sys.databases to report the total allocated size in megabytes and gigabytes for every user database on the SQL Server instance, sorted by largest database first. Purpose and Overview Knowing how large each database …


    Read More
  • SQL Server Unused Indexes: sys.dm_db_index_usage_stats

    calendar Apr 1, 2026 / Apr 24, 2026 · 7 min read · sql server performance sql scripts sys.dm_db_index_usage_stats index maintenance database administration nonclustered indexes query tuning maintenance scripts indexes  ·
    Share on: twitter facebook linkedin copy

    Find Unused Nonclustered Indexes in SQL Server This script queries sys.dm_db_index_usage_stats to identify nonclustered indexes that have never been used by any read operation since the last SQL Server restart, yet still carry write overhead with every INSERT, UPDATE, and DELETE on the table. Purpose and Overview Every …


    Read More
  • SQL Server Blocking Detection: Find Blocked Sessions

    calendar Mar 1, 2026 / Apr 24, 2026 · 5 min read · sql server blocking performance dm exec requests dm exec sessions wait types dba scripts monitoring query tuning sys.databases sys.dm_exec_requests sys.dm_exec_sessions sys.dm_exec_sql_text sys.dm_tran_locks  ·
    Share on: twitter facebook linkedin copy

    Blocking in SQL Server occurs when one session holds a lock that another session needs, causing the second session to wait. This T-SQL script queries the dynamic management views to show all currently blocked sessions, the blocking session, wait type, wait duration, and the SQL text involved. Purpose and Overview When …


    Read More
  • SQL Server Missing Indexes Report: dm_db_missing_index

    calendar Feb 28, 2026 / Apr 24, 2026 · 6 min read · sql server missing indexes performance dm db missing index details dm db missing index group stats index tuning dba scripts query optimization sys.dm_db_index_usage_stats sys.dm_db_missing_index_details sys.dm_db_missing_index_group_stats sys.dm_db_missing_index_groups sys.index_columns sys.indexes  ·
    Share on: twitter facebook linkedin copy

    SQL Server tracks index recommendations automatically as queries execute, storing them in the missing index DMVs. This T-SQL script queries those views to produce a ranked report of missing indexes, ordered by the estimated improvement they would provide, along with a ready-to-run CREATE INDEX statement for each …


    Read More
  • SQL Server Wait Statistics Report: dm_os_wait_stats

    calendar Feb 27, 2026 / Apr 24, 2026 · 6 min read · sql server wait statistics performance dm os wait stats wait types bottleneck analysis dba scripts performance tuning sys.dm_os_wait_stats sys.dm_os_waiting_tasks  ·
    Share on: twitter facebook linkedin copy

    Wait statistics are one of the most reliable ways to identify performance bottlenecks in SQL Server. This T-SQL script queries sys.dm_os_wait_stats, filters out background and idle wait types that do not indicate real problems, and ranks the remaining waits by their percentage of total wait time. Purpose and Overview …


    Read More
  • SQL Server Primary Key Discovery Script: sp_pkeys Guide

    calendar Aug 9, 2025 / Apr 24, 2026 · 3 min read · sql server primary keys database administration scripts sysobjects sp_pkeys dynamic sql sysobjects sys.tables sys.key_constraints INFORMATION_SCHEMA.TABLE_CONSTRAINTS  ·
    Share on: twitter facebook linkedin copy

    SQL Server Primary Key Discovery Script Using sp_pkeys and sysobjects Purpose This SQL Server script generates dynamic SQL statements that can be executed to discover primary keys across all user tables in a database. It's a powerful administrative tool that helps database administrators quickly identify primary key …


    Read More
  • SQL Server: Find Tables with Clustered Indexes for Rebuild

    calendar Aug 9, 2025 / Apr 24, 2026 · 3 min read · sql server clustered indexes database maintenance index rebuilding system tables dba scripts performance tuning database administration sysobjects sysindexes sys.tables sys.indexes  ·
    Share on: twitter facebook linkedin copy

    SQL Server Query to Identify Tables with Clustered Indexes for Rebuilding Database administrators frequently need to perform maintenance operations on clustered indexes to optimize database performance. This SQL Server query provides a quick and efficient way to identify all user tables that contain clustered indexes, …


    Read More
  • SQL Server Object Permissions: Generate GRANT Statements

    calendar Aug 8, 2025 / Apr 24, 2026 · 5 min read · sql server database security permissions grant statements database administration sql scripts security database objects sysobjects sys.objects  ·
    Share on: twitter facebook linkedin copy

    SQL Server Object-Level Permissions Script: Generate GRANT Statements for Database Security Database security is a critical aspect of SQL Server administration, and managing permissions at the object level can be time-consuming when done manually. This SQL Server script automates the process of generating GRANT …


    Read More
    • ««
    • «
    • 1
    • 2
    • 3
    • 4
    • »
    • »»

SQLServer70.com

Your Source for SQL Server Scripts
Read More

Recent Posts

  • SQL Server Copy-Only Backup Script for Dev Restore
  • SQL Server: Find Databases With No Recent Backup
  • SQL Server Foreign Keys Without Indexes Script
  • SQL Server Backup Compression: Enable and Verify
  • SQL Server CPU Utilization History Report
  • SQL Server DBCC CHECKDB Last Run Date Report
  • SQL Server Find Orphan Users Script
  • SQL Server MAXDOP Recommendation Script

Categories

SCRIPTS 38 SQL SERVER ADMINISTRATION 7 SQL SERVER BACKUP RECOVERY 7 SQL SERVER MONITORING 6 SQL SERVER PERFORMANCE 6 SQL SERVER MAINTENANCE 5 SQL SERVER STRUCTURE 4 SQL SERVER SECURITY 3

Series

ADMIN-GUIDE 38

Tags

SQL SERVER 37 DATABASE ADMINISTRATION 27 SQL SCRIPTS 24 MAINTENANCE SCRIPTS 12 PERFORMANCE 12 SYSOBJECTS 10 DBA SCRIPTS 9 MSDB 8 SYS.TABLES 8 DATABASE MAINTENANCE 7 MONITORING 7 SYS.DATABASES 7 BACKUP RECOVERY 6 DBCC COMMANDS 5
All Tags
ACTIVE SESSIONS2 ADMINISTRATION2 AUTOMATION2 BACKUP1 BACKUP AUDIT1 BACKUP COMPRESSION1 BACKUP MONITORING2 BACKUP RECOVERY6 BACKUP VALIDATION1 BACKUPSET1 BLOCKING2 BOTTLENECK ANALYSIS1 CAPACITY PLANNING1 CLUSTERED INDEXES1 CONTENTION1 COPY ONLY BACKUP1 CPU CONFIGURATION1 CPU HISTORY1 CPU UTILIZATION1 CURSOR PROGRAMMING1 DATABASE1 DATABASE ADMINISTRATION27 DATABASE CONNECTIONS1 DATABASE INTEGRITY1 DATABASE MAINTENANCE7 DATABASE MANAGEMENT3 DATABASE MONITORING2 DATABASE OBJECTS1 DATABASE OPTIMIZATION1 DATABASE SCRIPTS1 DATABASE SECURITY1 DATABASE STRUCTURE2 DBA SCRIPTS9 DBA TOOLS1 DBCC1 DBCC CHECKDB1 DBCC CHECKIDENT1 DBCC COMMANDS5 DBCC DBINFO1 DBCC DBREINDEX2 DEV RESTORE1 DIAGNOSTICS1 DIFFERENTIAL BACKUP1 DM DB MISSING INDEX DETAILS1 DM DB MISSING INDEX GROUP STATS1 DM DB SESSION SPACE USAGE1 DM EXEC REQUESTS2 DM EXEC SESSIONS3 DM EXEC SQL TEXT1 DM OS WAIT STATS1 DYNAMIC SQL2 ERROR LOG1 EXECUTION PLAN1 FOREIGN KEYS1 FRAGMENTATION2 FULL BACKUP1 GRANT STATEMENTS1 HEAP TABLES1 IDENTITY COLUMNS1 INDEX MAINTENANCE2 INDEX OPTIMIZATION1 INDEX REBUILDING1 INDEX TUNING1 INDEXES3 INDEXING1 INFORMATION_SCHEMA.TABLE_CONSTRAINTS1 INFORMATION_SCHEMA.TABLES1 INTEGRITY CHECK1 JOB MONITORING1 KILL SPID1 LOGIN MANAGEMENT1 MAINTENANCE SCRIPTS12 MAXDOP1 MISSING INDEXES1 MONITORING7 MSDB8 MSDB.DBO.BACKUPMEDIAFAMILY1 MSDB.DBO.BACKUPSET1 NONCLUSTERED INDEXES1 NUMA1 OBJECT SEARCH1 OPEN TRANSACTIONS1 OPTIMIZATION2 ORPHAN USERS1 PERFORMANCE12 PERFORMANCE MONITORING1 PERFORMANCE TUNING5 PERMISSIONS2 POINT IN TIME RESTORE1 PRIMARY KEYS2 QUERY OPTIMIZATION2 QUERY TUNING3 REBUILD REORGANIZE1 RECOVERY1 REPORTING3 RESTORE1 RESTORE VERIFYONLY1 RING BUFFER1 ROLE MEMBERSHIPS1 SCHEMA AUDIT1 SCHEMA MANAGEMENT1 SCRIPTS3 SECURITY3 SECURITY AUDIT2 SERVER MONITORING1 SESSION MANAGEMENT1 SP_CHANGE_USERS_LOGIN1 SP_CONFIGURE2 SP_PKEYS1 SP_READERRORLOG1 SP_SPACEUSED1 SPACE MANAGEMENT1 SPACE USAGE1 SQL1 SQL SCRIPTS24 SQL SERVER37 SQL SERVER AGENT1 SQL SERVER MONITORING1 SQLSERVER PROCESS UTILIZATION1 STATISTICS1 STORAGE1 STORED PROCEDURES1 SYS.ALLOCATION_UNITS1 SYS.COLUMNS1 SYS.DATABASE_PERMISSIONS1 SYS.DATABASE_PRINCIPALS2 SYS.DATABASE_ROLE_MEMBERS1 SYS.DATABASES7 SYS.DM_DB_INDEX_PHYSICAL_STATS2 SYS.DM_DB_INDEX_USAGE_STATS2 SYS.DM_DB_MISSING_INDEX_DETAILS1 SYS.DM_DB_MISSING_INDEX_GROUP_STATS1 SYS.DM_DB_MISSING_INDEX_GROUPS1 SYS.DM_EXEC_QUERY_PLAN1 SYS.DM_EXEC_QUERY_STATS1 SYS.DM_EXEC_REQUESTS2 SYS.DM_EXEC_SESSIONS2 SYS.DM_EXEC_SQL_TEXT3 SYS.DM_OS_RING_BUFFERS1 SYS.DM_OS_WAIT_STATS1 SYS.DM_OS_WAITING_TASKS1 SYS.DM_TRAN_ACTIVE_TRANSACTIONS1 SYS.DM_TRAN_LOCKS1 SYS.FOREIGN_KEYS1 SYS.INDEX_COLUMNS1 SYS.INDEXES2 SYS.KEY_CONSTRAINTS1 SYS.MASTER_FILES1 SYS.OBJECTS4 SYS.PARTITIONS1 SYS.SERVER_PRINCIPALS1 SYS.SP_ENUMERRORLOGS1 SYS.SQL_MODULES1 SYS.TABLES8 SYSCOLUMNS1 SYSDATABASES1 SYSINDEXES2 SYSJOBHISTORY1 SYSJOBS1 SYSOBJECTS10 SYSTEM IDLE PROCESS1 SYSTEM TABLES3 T-SQL3 TABLE ANALYSIS1 TABLE STATISTICS1 TEMPDB1 TRANSACTION LOG1 TRANSACTION LOG BACKUP1 UPDATE STATISTICS1 VIEWS1 WAIT STATISTICS1 WAIT TYPES3 XP_READERRORLOG1
[A~Z][0~9]
SQLServer70.com

Copyright  SQLSERVER70.COM. All Rights Reserved

to-top