This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
hadrc.cluster_name, | |
SERVERPROPERTY('MachineName') AS [ServerName], | |
SERVERPROPERTY('InstanceName') AS [Instance], | |
SERVERPROPERTY('Edition') AS [Edition], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#----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 |
NewerOlder