Tuesday, September 23, 2014

0 SQL Server PowerShell–> script menthod

SQLPS provide very powerful method that can get the DDL out of database object very easily.

From SQLPS

(get-item TestDB ).script()

image

From SMO

$server = 'SGC3,8001'
[System.Reflection.Assembly]::LoadwithPartialName("Microsoft.sqlserver.smo");
$conn = New-Object Microsoft.sqlserver.management.smo.server "$server"
$conn
$conn.Databases['TestDB'].script()

image

This is going to be very useful, if I want to get all the DDL for all tables

Get-ChildItem .\Tables | %{$_.script()} |more

image

Very useful .

0 comments:

Post a Comment

 

SQL Panda Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates