Skip to content

Instantly share code, notes, and snippets.

View PartTimeLegend's full-sized avatar

Antony Bailey PartTimeLegend

View GitHub Profile
DECLARE @Database VARCHAR(255)
DECLARE @Table VARCHAR(255)
DECLARE @cmd NVARCHAR(500)
DECLARE @fillfactor INT
SET @fillfactor = 90
DECLARE DatabaseCursor CURSOR FOR
SELECT name FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','msdb','tempdb','model','distribution')
print '-- query and plan hash capture --'
print '-- query and plan hash capture --'
print '-- top 10 CPU by query_hash --'
select getdate() as runtime, * --into tbl_QueryHashByCPU
from
create function [dbo].[udf_ContainsNonASCIIChars](@string nvarchar(4000),@checkExtendedCharset bit )returns bit asbegin declare @pos int = 0; declare @char varchar(1); declare @return bit = 0; while @pos < len(@string) begin select @char = substring(@string, @pos, 1) if ascii(@char) < 32 or ascii(@char) > 126 begin if @checkExtendedCharset = 1 begin if ascii(@char) not in (9,124,130,138,142,146,150,154,158,160,170,176,180,181,183,184,185,186,192,193,194,195,196,197,199,200,201,202,203,204,205,206,207,209,210,211,212,213,214,216,217,218,219,220,221,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,248,249,250,251,252,253,254,255) begin select @return = 1; select @pos = (len(@string) + 1) end else begin select @pos = @pos + 1 end end else begin select @return = 1; select @pos = (len(@string) + 1) end end else begin select @pos = @pos + 1 end end return @return; end
DECLARE @backupPath nvarchar(400);DECLARE @sourceDb nvarchar(50);DECLARE @sourceDb_log nvarchar(50);DECLARE @destDb nvarchar(50);DECLARE @destMdf nvarchar(100);DECLARE @destLdf nvarchar(100);DECLARE @sqlServerDbFolder nvarchar(100); SET @sourceDb = 'db1'SET @sourceDb_log = @sourceDb + '_log'SET @backupPath = 'E:\tmp\' + sourceDb + '.bak' --ATTENTION: file must already exist and SQL Server must have access to it SET @sqlServerDbFolder = 'E:\DB SQL\MSSQL11.MSSQLSERVER\MSSQL\DATA\' SET @destDb = 'db2' SET @destMdf = @sqlServerDbFolder + @destDb + '.mdf' SET @destLdf = @sqlServerDbFolder + @destDb + '_log' + '.ldf' BACKUP DATABASE @sourceDb TO DISK = @backupPath RESTORE DATABASE @destDb FROM DISK = @backupPath WITH REPLACE, MOVE @sourceDb TO @destMdf, MOVE @sourceDb_log TO @destLdf
SELECT 'ALTER TABLE ' + isnull(schema_name (syo. id), 'dbo') + '.' + syo .name
+ ' ALTER COLUMN ' + syc.name + ' NVARCHAR(' + case syc. length when -1 then 'MAX'
ELSE convert (nvarchar( 10),syc .length) end + ');'
FROM sysobjects syo
JOIN syscolumns syc ON
syc .id = syo.id
JOIN systypes syt ON
syt .xtype = syc.xtype
WHERE
syt .name = 'varchar'
All public gists https://gist.github.com/parttimelegend
Copyright 2016, Antony Bailey
MIT License, http://www.opensource.org/licenses/mit-license.php
# Hacky AF
sudo gem update `gem list | cut -d ' ' -f 1`
Function IIf($If, $IfTrue, $IfFalse) {
If ($If) {If ($IfTrue -is "ScriptBlock") {&$IfTrue} Else {$IfTrue}}
Else {If ($IfFalse -is "ScriptBlock") {&$IfFalse} Else {$IfFalse}}
}
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs;
exit
}
Get-EC2Instance | Where-Object {!$_.RunningInstance.StateReason.Code} | Stop-EC2Instance