Skip to content

Instantly share code, notes, and snippets.

/*
https://www.mssqltips.com/sqlservertip/4772/refactor-sql-server-scalar-udf-to-inline-tvf-to-improve-performance/
https://dba.stackexchange.com/questions/204545/creating-a-persisted-computed-column-with-a-function
*/
CREATE SCHEMA etl;
GO
CREATE SCHEMA staging;
GO
CREATE SCHEMA store;
@dataGriff
dataGriff / Deploy-SQLAgentJob.ps1
Last active March 10, 2019 19:29
Code to deploy sql agent job using powershell
###############################################################################################################
###############################################################################################################
function Update-SQLAgentJobProperty(
[string]$serverName,
[string]$jobName,
[string]$property,
[string]$propertyValue
){
@dataGriff
dataGriff / sqlpackagestuff.ps1
Last active March 31, 2019 11:54
creating localdb and using sqlpackage
$localinstance = "grifftest"
SqlLocalDB.exe create "grifftest"
SqlLocalDB.exe start "grifftest"
## https://docs.microsoft.com/en-us/sql/tools/sqllocaldb-utility?view=sql-server-2017
$dacpacpath = "E:\Documents\Projects\Demo_DatabaseDevOps\AdventureWorks\AdventureWorks\bin\Debug\AdventureWorks.dacpac"
$profilepath = "E:\Documents\Projects\Demo_DatabaseDevOps\AdventureWorks\AdventureWorks\AdventureWorks.publish.xml"
$outputpath = "E:\Documents\Projects\Demo_DatabaseDevOps\AdventureWorks\AdventureWorks\"
$scriptpath = "$outputpath\script.sql"
@dataGriff
dataGriff / Configuration.biml
Last active February 3, 2019 13:00
Adds SQL properties to biml. (1) Add all four biml files below to your SSIS project. (2). Amend configuration.biml file to be your environment. (3) Open Deploy_Metadata.biml file and see biml expansion generated!
<#
//Amend the values below to represent your environment
string connectionName = "Datawarehouse";
string serverName = "localhost";
string databaseName = "AdventureWorksDW";
string schemaName = "dbo";
var includedSchemas = new List<string>{schemaName};
Column1 Column2
@dataGriff
dataGriff / Test-SQLCoverage.tests.ps1
Last active November 25, 2018 18:57
Code coverage test example for SQL using pester
## Test Azure Resource Exists
clear-host
Write-Host "Test-SQL Starting..."
$serverName = "test-griff.database.windows.net"
$databaseName = "AdventureWorksLT"
$password = ConvertTo-SecureString "5up3r53cr3t!" -AsPlainText -Force #need to convert to key vault get
@dataGriff
dataGriff / RunPester.ps1
Last active November 25, 2018 19:10
Code to run pester
param(
[string]$testScript,
[string]$resourceGroupName
)
## $testScript = .\AzureTest\Test-AzureResourceExists.tests.ps1
Write-Host "Executing Pester tests..."
$outputPath = $testScript.replace("Tests.ps1","xml");
@dataGriff
dataGriff / Test-AzureResourceExists.Tests.ps1
Last active February 23, 2019 14:01
Azure pester example
## Test Azure Resource Exists
clear-host
Write-Host "Test-AzureResourceExists Starting..."
if ([string]::IsNullOrEmpty($(Get-AzureRmContext).Account)) {Login-AzureRmAccount}
$resourceGroupName = "test-rg"
$resourceNames = @("test1", "test2")
$resourceExists = 0
if (-Not(Get-AzureRmResourceGroup | where {$_.ResourceGroupName -eq $resourceGroupName } | Select Name)) {
Write-Host "Resource group does not exist!" -ForegroundColor Red
##break
@dataGriff
dataGriff / Update-StorageAccountTableSharedAccessPolicyWithSignature.ps1
Last active November 25, 2018 17:11
Update-StorageAccountTableSharedAccessPolicyWithSignature
$resourceGroupName = "datagriff-rg"
$location = "north europe"
$storageAccountName = "datagriffsa123456"
$tableName = "mytable"
$storagePolicyName = “readpolicy”
$expiryTime = (Get-Date).AddDays(7)
$permission = "r" ##r,w,l,d
$requestSaS = 1
function Update-StorageAccountTableSharedAccessPolicyWithSignature {
@dataGriff
dataGriff / DeployResourceGroupAndKeyVault.ps1D
Last active February 26, 2019 20:08
Deploys resource group and key vault
#
# Install-Module -Force AzureRM #run as administrator
# run all below as administrator!!!
# may get errors if done one bit as admin and one bit not, remove and start again in new window
# remember if using in releases to wrap passwords in double quotes in release! e.g. ""$(Password)""
$failoverGroup = $true
$passwordOverride = $true
$adminPasswordOverride = $true
$secretOverride = $false