Skip to content

Instantly share code, notes, and snippets.

View LetsGoRafting's full-sized avatar
💭
Checking log files...

Dirk Klein LetsGoRafting

💭
Checking log files...
  • Auckland, NZ
View GitHub Profile
@LetsGoRafting
LetsGoRafting / gist:cb302869068ed789e497ac7780690ddd
Created April 17, 2024 01:19
find text in procedures functions views triggers
SELECT [Schema] = schema_name(o.schema_id), o.Name, o.type
FROM sys.sql_modules m
INNER JOIN sys.objects o ON o.object_id = m.object_id
WHERE m.definition like '%mytexttofind%'
GO
@LetsGoRafting
LetsGoRafting / disable-enable-all-foreign-keys.sql
Created February 13, 2024 21:53
Disable and enable all foreign keys when refreshing tables from DEV, UAT etc
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
select 'delete from ' + name
from sys.objects
where type = 'U'
and name like 'blah-di-blah%'
order by name
-- SSIS that shizzle in there and flip them on again
@LetsGoRafting
LetsGoRafting / audit-find-all-users-permissions-all-databases
Created July 25, 2023 22:33
audit all databases all users permissions
/**
Script: list all Usernames, Roles for all the databases.
Author: Shiva Challa (http://challa.info)
and the database Roles that the user belongs to in all the databases.
Also, you can use this script to get the roles of one user in all the databases.
Directions of Use:
For All Users list: You can directly run this script in SQL Server Management studio
For a specific user:
1. Find this code and u.name like ''tester''
@LetsGoRafting
LetsGoRafting / find invalid active directory logins
Created December 13, 2022 00:47
find invalid active directory logins queries
declare @user sysname
declare @domain varchar(100)
set @domain = 'mydomain'
declare recscan cursor for
select name from sys.server_principals
where type = 'U' and name like @domain+'%'
open recscan
@LetsGoRafting
LetsGoRafting / get objects changed from default trace
Created August 24, 2022 02:26
read default trace get changed objects
DECLARE @file varchar(255);
SELECT @file = path FROM sys.traces WHERE is_default = 1;
WITH TraceCTE AS (
SELECT DatabaseID,
DatabaseName,
LoginName,
HostName,
ApplicationName,
SPID,
StartTime,
@LetsGoRafting
LetsGoRafting / SSIS Job Step commands
Created June 8, 2022 00:24
SSIS Job Step commands
use msdb
select [job]=j.name, [step]=s.step_name, s.command
from dbo.sysjobsteps s
inner join dbo.sysjobs j
on s.job_id = j.job_id
and s.subsystem ='SSIS'
go
@LetsGoRafting
LetsGoRafting / CMS query all availability groups status
Created June 8, 2022 00:20
CMS query all availability groups status
select
hadrc.cluster_name,
SERVERPROPERTY('MachineName') AS [ServerName],
SERVERPROPERTY('InstanceName') AS [Instance],
SERVERPROPERTY('Edition') AS [Edition],
@LetsGoRafting
LetsGoRafting / wait-stats-performance.sql
Created February 16, 2022 22:27
wait stats of performance
-- Last updated October 1, 2021
WITH [Waits] AS
(SELECT
[wait_type],
[wait_time_ms] / 1000.0 AS [WaitS],
([wait_time_ms] - [signal_wait_time_ms]) / 1000.0 AS [ResourceS],
[signal_wait_time_ms] / 1000.0 AS [SignalS],
[waiting_tasks_count] AS [WaitCount],
100.0 * [wait_time_ms] / SUM ([wait_time_ms]) OVER() AS [Percentage],
ROW_NUMBER() OVER(ORDER BY [wait_time_ms] DESC) AS [RowNum]
@LetsGoRafting
LetsGoRafting / best-fix-logins-for-all-dbs-after-restore-or-move.sql
Created February 16, 2022 22:26
BEST fix logins all databases after restore or move
DECLARE @DatabaseName nvarchar(255)
DECLARE @UserName nvarchar(255)
DECLARE @Command nvarchar(1000)
DECLARE @SqlStatement nvarchar(4000)
IF OBJECT_ID( 'tempdb..#temp') IS NOT NULL
DROP TABLE tempdb..#temp
CREATE TABLE tempdb..#temp (name VARCHAR(100))
@LetsGoRafting
LetsGoRafting / delete-files-with-powershell-agent-jobstep.ps1
Created October 14, 2021 01:45
delete files with powershell step in agent job
#----enter path---#
$targetpath = "C:\drive\"
#----enter the days---#
$days = 5
#----extension of the file to delete---#
$Extension = "*.trn"
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
#----- get files based on lastwrite filter in the specified folder ---#
$Files = Get-Childitem $targetpath -Include $Extension -Recurse | Where