Giter Club home page Giter Club logo

get-staticdataproc's Introduction

Get-StaticDataProc

This PowerShell function is designed for source controlling static/reference data from a database.

The script generate a Stored Procedure script which will create a temp table, script the current data and insert it into the temp table. And then finally merge the results back to the table.

The stored procedure can then be deployed to the database and stored in source control to manage any future changes.

For SSDT project the procedure can be executed in the PostDeploy script to ensure the data is always consistant.

Examples

Set-Location $PSScriptRoot
Import-Module '..\src\StaticDataProc.psd1' -Force
Import-Module -Name SqlServer -Force   # This module is a dependancy, use Install-Module SQLServer -Force -AllowClobber if not available

$server = "SQL16"
$database = "WideWorldImportersDW"
$Schema = "Dimension"
$table = "Transaction Type"
$DeleteUnknownRecords = $true  # This param controls if the merge statement should delete not matched records

# Example 1 - Return a single table to the console output
Get-StaticDataProc -Server $Server -Database $Database -Schema $Schema -Table $Table -DeleteUnknown $DeleteUnknownRecords

# Example 2 - As above but results to text file
$outFile = "C:\Temp\script.txt"
Get-StaticDataProc -Server $Server -Database $Database -Schema $Schema -Table $Table -DeleteUnknown $DeleteUnknownRecords  | Out-File $outFile -Append

# Example 3 - Bunch of tables output to a file
$outFile = "C:\Temp\script.txt"
$tables = "Table1", "Table2", "Table3"
foreach ($table in $tables)
{
    Get-StaticDataProc -Server $Server -Database $Database -Schema $Schema -Table $Table -DeleteUnknown $DeleteUnknownRecords  | Out-File $outFile -Append
}

Known Limitations

Target table must have a Primary Key (required for the Merge join).
You must use NT Authentication to connect to the database.

get-staticdataproc's People

Watchers

James Cloos avatar Simon Sabin avatar Simon D'Morias avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.