This file contains hidden or 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
-- | |
-- Profile connections using Event Notification and AUDIT_LOGIN events | |
-- to create a summary of number of logins by database, application, login and hostname | |
-- additionally tracking domain name and user | |
-- | |
USE DBPerfmon; | |
GO | |
-- Prerequisites | |
ALTER DATABASE DBPerfmon SET ENABLE_BROKER; |
This file contains hidden or 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
-- | |
-- Group index optimize total size from logged data by https://ola.hallengren.com | |
-- | |
WITH cte AS | |
( | |
SELECT | |
DatabaseName | |
, StartTime | |
, ExtendedInfo.value('(/ExtendedInfo/PageCount)[1]', 'bigint') AS pages | |
FROM CommandLog |
This file contains hidden or 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
CREATE EVENT SESSION [audit_getdate_usage] ON SERVER | |
ADD EVENT sqlserver.sql_batch_starting(SET collect_batch_text=(1) | |
ACTION(sqlserver.database_name) | |
WHERE ([sqlserver].[like_i_sql_unicode_string]([batch_text],N'%getdate%'))) | |
ADD TARGET package0.event_file(SET filename=N'c:\temp\audit_getdate_usage') | |
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF) | |
GO |
This file contains hidden or 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
$ReplacementFile = "C:\Temp\newfile.txt" | |
$SearchDir = "c:\Temp\root" | |
dir $SearchDir -File (Split-Path $ReplacementFile -Leaf) -Recurse | | |
% { Copy-Item $ReplacementFile $_.FullName -Force} |
This file contains hidden or 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
$PortToFind = "6012"; | |
$SleepIntervalMs = 200; | |
while ($true) | |
{ | |
$nstat = (netstat -nab); | |
if ($nstat -like "*$PortToFind*") | |
{ | |
$nstat -like "*$PortToFind*"; | |
break; |
This file contains hidden or 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
-- | |
-- Trace date function usage (batch completed) for Amazon RDS compliancy | |
-- | |
-- Create a Queue | |
declare @rc int | |
declare @TraceID int | |
declare @maxfilesize bigint | |
declare @DateTime datetime |
This file contains hidden or 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
# Operating system error %.*ls on file "%.*ls" during %ls. | |
cls; | |
$DirPattern = "D:\SQLServer\MSSQL12.MSSQLSERVER\MSSQL\Log\ERRORLOG*"; | |
$OutputDir = "D:\Temp"; | |
$CSVDelimiter = ";"; | |
$SearchLogFiles = [regex] "(?<Date>\d{4}-\d{2}-\d{2}) (?<Time>\d{2}:\d{2}:\d{2}\.\d{2}) (?<Source>.*?)\s{4}(?<FullFileName>.*?): Operating system error (?<OSErrorNumber>\d*) \((?<OSErrorText>.*?)\) encountered."; | |
This file contains hidden or 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
WITH cte AS | |
( | |
SELECT | |
YEAR(CONVERT(DATETIME, CAST(C1.CounterDateTime AS VARCHAR(19))) ) AS sample_year | |
, MONTH(CONVERT(DATETIME, CAST(CounterDateTime AS VARCHAR(19)))) AS sample_month | |
, DAY(CONVERT(DATETIME, CAST(CounterDateTime AS VARCHAR(19)))) AS sample_day | |
, DATEPART(HH,CONVERT(DATETIME, CAST(CounterDateTime AS VARCHAR(19)))) AS sample_hour | |
, DATEPART(mi,CONVERT(DATETIME, CAST(CounterDateTime AS VARCHAR(19)))) AS sample_minute | |
, REPLACE(C2.MachineName, '\\', '') AS machine_name | |
, CASE |
This file contains hidden or 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
-- | |
-- generates T-SQL commands for full and log backups | |
-- | |
DECLARE @BackupPath sysname = N'\\192.168.1.2\SyncMirror\'; | |
WITH cte AS | |
( | |
-- use databases already configured for mirroring | |
SELECT DB_NAME(database_id) AS database_name | |
FROM sys.database_mirroring |
This file contains hidden or 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
WITH cte AS | |
( | |
SELECT DB_NAME(t.[dbid]) AS [Database Name], | |
qs.total_worker_time AS [Total Worker Time], | |
qs.min_worker_time AS [Min Worker Time], | |
qs.total_worker_time/qs.execution_count AS [Avg Worker Time], | |
qs.execution_count AS [Execution Count]--, | |
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK) | |
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS t | |
) |