top of page

Search
SQL Server CPU MAXDOP Setting
Maxdop - 1, means no parallelism Maxdop - 0 (Default), Means SQL Server can aggressively use all the available processor to execute the...

Kunal Ranpura
Jul 29, 20191 min read
Â
Â
Â
Change DB_Owner to SA
/* The Code */ --If you want to get a list of current owners who aren't sa SELECT suser_sname(owner_sid) as DBOwner, Name as DBName FROM...

Kunal Ranpura
Jul 29, 20191 min read
Â
Â
Â
Script to find SQL Server Data and Log file Auto Growth Event
--Script to find autogrowth event from the default trace. DECLARE @filename NVARCHAR(1000); DECLARE @bc INT; DECLARE @ec INT; DECLARE...

Kunal Ranpura
Jul 29, 20191 min read
Â
Â
Â
Script to find No. of Virtual Log File Count (VLFs)
--Script to find number of VLF. SET NOCOUNT ON; /* declare variables required */ DECLARE @DatabaseId INT; DECLARE @TSQL varchar(MAX);...

Kunal Ranpura
Jul 29, 20192 min read
Â
Â
Â
Find Job History for all SQL Server Agent Jobs.
Use msdb go select distinct j.Name as "Job Name", --j.job_id, case j.enabled when 1 then 'Enable' when 0 then 'Disable' end as "Job...

Kunal Ranpura
Jul 29, 20191 min read
Â
Â
Â
Script to list table names short by total space used desc.
SELECT t.NAME AS TableName, s.Name AS SchemaName, p.rows AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, SUM(a.used_pages) * 8 AS...

Kunal Ranpura
Jul 29, 20191 min read
Â
Â
Â
Analysis for enabling compression at object level
--Collect all index stats if object_id('index_estimates') is not null drop table index_estimates go create table index_estimates (...

Kunal Ranpura
Jul 29, 20193 min read
Â
Â
Â
Script to compare data between two tables
-- Show data in table dbtest02 that do not exists in dbtest01 select * from dbtest02.dbo.article except select * from dbtest01.dbo.article

Kunal Ranpura
Jul 28, 20191 min read
Â
Â
Â
Script to Defrag Index Fragmented more than 10% in SQL 2000
/*Perform a 'USE <database name>' to select the database in which to run the script.*/ -- Declare variables SET NOCOUNT ON; DECLARE...

Kunal Ranpura
Jul 28, 20192 min read
Â
Â
Â
SQL Server Script to increase number of Errorlogs
--Below script will change the number of SQL Server errorslogs to 10 USE [master] GO EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE',...

Kunal Ranpura
Jul 28, 20191 min read
Â
Â
Â
SQL Server Agent Job to recycle error log
USE [msdb] GO /****** Object: Job [sp_cycle_errorlog] Script Date: 08/26/2014 10:44:11 ******/ BEGIN TRANSACTION DECLARE @ReturnCode...

Kunal Ranpura
Jul 28, 20191 min read
Â
Â
Â
Configure SQL Server Agent Job History
USE [msdb] GO EXEC msdb.dbo.sp_set_sqlagent_properties @jobhistory_max_rows=10000, @jobhistory_max_rows_per_job=1000

Kunal Ranpura
Jul 28, 20191 min read
Â
Â
Â
Rebuild Script with Sort in TempDB ON, FillFactor = 80 and ONLINE=ON
-- Ensure a USE <databasename> statement has been executed first. SET ANSI_NULLS ON; SET ARITHABORT ON; SET QUOTED_IDENTIFIER ON; SET...

Kunal Ranpura
Jul 28, 20192 min read
Â
Â
Â
Script to Rebuild Index with FillFactor of 80 and Rebuild Online=ON
-- Ensure a USE <databasename> statement has been executed first. SET ANSI_NULLS ON; SET ARITHABORT ON; SET QUOTED_IDENTIFIER ON; SET...

Kunal Ranpura
Jul 28, 20192 min read
Â
Â
Â
Script Rebuild Index with FillFactor of 80
-- Ensure a USE <databasename> statement has been executed first. SET ANSI_NULLS ON; SET ARITHABORT ON; SET QUOTED_IDENTIFIER ON; SET...

Kunal Ranpura
Jul 28, 20192 min read
Â
Â
Â
Script to Rebuild index with Sort in Tempdb ON
-- Ensure a USE <databasename> statement has been executed first. SET ANSI_NULLS ON; SET ARITHABORT ON; SET QUOTED_IDENTIFIER ON; SET...

Kunal Ranpura
Jul 28, 20192 min read
Â
Â
Â
Script Rebuild Index Depending on Fragmentation
The below script rebuild all the indexes that are fragmented higher than 30%. Reorg indexes that are fragmented between 10%-30% -- Ensure...

Kunal Ranpura
Jul 28, 20192 min read
Â
Â
Â
Buffer Pool Extension
--Buffer Pool Extension Alter server configuration set buffer pool extension on (filename ='D:\extrabuffer.bpe', size = 32GB) GO

Kunal Ranpura
Jul 28, 20191 min read
Â
Â
Â
Find Top 50 SQL statements and SP with highest workertime and execution count.
SELECT TOP (50) sp.database_id, dbname= DB_NAME (qt.dbid), so.name AS StoredProcName, sp.total_worker_time, sp.execution_count AS...

Kunal Ranpura
Jul 28, 20191 min read
Â
Â
Â
Query to find Storedprocedure with the highest total workertime in SQL Server
SELECT TOP (10) sp.database_id, so.name AS StoredProcName, sp.total_worker_time, sp.execution_count, sp.total_logical_reads,...

Kunal Ranpura
Jul 28, 20191 min read
Â
Â
Â
bottom of page





