Skip to content

Instantly share code, notes, and snippets.

View tcartwright's full-sized avatar

Tim Cartwright tcartwright

  • Houston, Texas
View GitHub Profile
@tcartwright
tcartwright / FindColumnsWithDiffTypes.md
Last active January 13, 2023 00:18
SQL SERVER: Find columns with the same names but different types or sizes
@tcartwright
tcartwright / ClearSingleUsePlansFromCache.sql
Created July 6, 2017 17:59
SQL SERVER: Clear single use plans from cache
DECLARE @Sql VARCHAR(MAX) = (
SELECT 'DBCC FREEPROCCACHE (0x' + CONVERT( VARCHAR(MAX), [ecp].[plan_handle], 2) + ') WITH NO_INFOMSGS; ' + CHAR(10)
FROM [sys].[dm_exec_cached_plans] [ecp]
WHERE [ecp].[usecounts] = 1
AND [ecp].[objtype] IN('Adhoc', 'Prepared')
FOR XML PATH('')
);
SELECT @sql
--EXEC (@sql)
@rem resources
@rem http://www.brentozar.com/archive/2008/09/finding-your-san-bottlenecks-with-sqlio/
@rem http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=20163
@rem START MODIFICATION AREA START
@rem change the drive letter to match the desired drive to test
@set testfile=c:\testfile.dat
@rem change the number to the number of gb's to test with, this should be roughly the same size as your db
@set size=20
@rem the number of threads to use for the test
@echo on
@setlocal EnableDelayedExpansion
@set ps=%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile
%ps% -File "%~dp0Get Local DB Info.ps1"
@echo.
@pause
@tcartwright
tcartwright / Get Installed DotNet Frameworks.bat
Last active June 16, 2021 18:45
Get Installed DotNet Frameworks
@echo OFF
@setlocal ENABLEEXTENSIONS
@REM Author: Tim Cartwright
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP"
@rem https://msdn.microsoft.com/en-us/library/hh925568%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396#net_d
@echo.
@tcartwright
tcartwright / Generate Security.bat
Last active April 29, 2020 14:42
SQL SERVER: Generate Grants for a Database, and role memberships for a database. Can be run before a backup to store security and then applied post backup.
@rem bat file to ease use of the split script
@%~d0
@cd "%~dp0"
powershell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -file "%~dp0Generate Security.ps1" -OutPutFile "%~dp0Security.sql"
@echo Done.
@pause
@tcartwright
tcartwright / ScriptDatabase.md
Last active January 3, 2023 16:28
SQL SERVER: Powershell Script to script a database including its grants