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
@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!
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
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 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
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
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 = ''
-- 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;