top of page

Search
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
4 views
0 comments
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
9 views
0 comments
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
14 views
0 comments
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
4 views
0 comments
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
8 views
0 comments
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
11 views
0 comments
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
10 views
0 comments
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
8 views
0 comments
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
4 views
0 comments
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
17 views
0 comments
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
8 views
0 comments
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
6 views
0 comments
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
11 views
0 comments
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
10 views
0 comments
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
6 views
0 comments
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
24 views
0 comments
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
8 views
0 comments
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
16 views
0 comments
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
4 views
0 comments
SQL Server object with most latch contention
SELECT TOP (5) a.database_id, so.object_id, so.name AS TableName, a.page_latch_wait_count , a.page_latch_wait_in_ms,...
Kunal Ranpura
Jul 28, 20191 min read
5 views
0 comments
bottom of page