Skip to content

Instantly share code, notes, and snippets.

View ConstantineK's full-sized avatar
🤖
keeping it real

Constantine ConstantineK

🤖
keeping it real
View GitHub Profile
-- THIS SCRIPT IS FOR NON-PRODUCTIONR RESTORES ONLY, RUN THIS IN PRODUCTION MAY BE A BAD IDEA, RUN AT YOUR OWN RISK
-- ERRORS MAY OCCUR WHEN RUNNING THIS SCRIPT, CONSIDER RUNNING THE RESTORE ON A NEW VERSION OF SQL SERVER OR VERIFYING YOUR BACKUP MEDIA
SET NOCOUNT ON;
DECLARE
@backup_filepath NVARCHAR(MAX)
, @new_db_name NVARCHAR(MAX)
, @restore_location NVARCHAR(MAX)
, @restore_with_recovery BIT= 1;
DECLARE @databaseName sysname
DECLARE @backupStartDate datetime
DECLARE @backup_set_id_start INT
DECLARE @backup_set_id_end INT
, @backup_set_id_diff INT
, @filenamereplace nvarchar(max) = '' -- Replace the unc filename with whatever file path you have copied things to
-- set database to be used
SET @databaseName = ''
query 1
Table 'Table1'. Scan count 0, logical reads 3, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table2'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table2'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table1'. Scan count 0, logical reads 3, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table2'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table2'. Scan count 0, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
query 2
Table 'Table1'. Scan count 0, logical reads 3, physical reads 0, read-ahead reads 0, lob logical
function Set-SqlTempDbConfiguration
{
<#
.SYNOPSIS
Sets tempdb data and log files according to best practices.
.DESCRIPTION
Function to calculate tempdb size and file configurations based on passed parameters, calculated values, and Microsoft
best practices. User must declare SQL Server to be configured and total data file size as mandatory values. Function will
then calculate number of data files based on logical cores on the target host and create evenly sized data files based
select n [id], SUSER_NAME(n) [user_name]
from (
select top 10000 row_number() over(order by t1.number) as N
from master..spt_values t1
cross join master..spt_values t2
) a
where SUSER_NAME(n) is not null
function Format-TrelloUriToJson {
param ($url)
Write-Debug "Formatting $url"
$prefix = "https://trello.com/b/"
$url = $url -replace $prefix,""
$identifier = "$($url.Split("/")[0])"
$name = "$($url.Split("/")[1])"
$url = $prefix + $identifier + ".json"
Write-Debug "Returning $url"
return $url, $name
@ConstantineK
ConstantineK / DataArchDemo.ps1
Created August 11, 2017 04:24
PASS Data Architecture Virtual Group demo
break # Prevent everything from running at once.
$SqlServer = "SQL2016"
Import-Module dbatools
# Stop the current command if it throws an error or exception.
$ErrorActionPreference = "Stop"
# Multiple assignment, woo!
# Give us more information about what is going on behind the scenes!
#
Set-StrictMode -Version 2
$ErrorActionPreference = "Stop"
function Convert-StringToMarkdownTableOfContents {
param ([string]$MarkdownDocument)
$nl = [System.Environment]::NewLine
$TOC = "## Table Of Contents$nl$nl"
@ConstantineK
ConstantineK / DoesntWorkFully.ps1
Last active November 16, 2017 20:55
first crack at changing collations automatically in sql server
Import-Module dbatools
Set-StrictMode -Version 2
function Get-InsecureCredential {
param ($Username, $Password)
Write-Debug "Get-InsecureCredential."
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($Username, $SecurePassword)
return $Credential
}
@ConstantineK
ConstantineK / mask_string.sql
Created January 9, 2019 00:27
support index based masking strings in TSQL
-- You can either pass a format string, or you could store it in a table per row
-- If you want to support additional cases, just modify the last CROSS APPLY
DECLARE @format_string nvarchar(500) = 'X###XXX###'
SELECT STRING_AGG(result.chars,'') AS strings
FROM sys.objects AS m
CROSS APPLY
(
SELECT