Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Powershell/SMO: Unload table schema, dri, perms & data.

By Gordon-265412,

Example:

.\Script_Table_to_File.ps1 FooServer BarDB 'Foo Table' 'X:\Foo Dir\'

Notes:

This was merely a personal exersize that got a little bit beyond that. :)

Tables and output paths that have spaces in them must be encapsulated in single-tick apostrophes on the command line call.

This script will produce two files in a datestamped subdirectory of the $outroot values (UNC paths will work as well). One script is the table schema, which includes DRI and permissions on the object. The second file is the actual data unloaded from the table in a pipe ("|") delimited format.

### NOTE ###: Once the table has been successfully scripted and unloaded it is dropped.

Currently this script only finds dbo owned objects. I suspect I'll need to re-write a good piece of it to find non-dbo objects....

This script will execute against any version of SQL server that I've tested (2000, 2005 & 2008).

Total article views: 939 | Views in the last 30 days: 1
 
Related Articles
FORUM

Scripting Objects Including Permissions

Scripting Objects Including Permissions

FORUM

SSIS script object

Script object Design Script does not open up script editor

FORUM

Generating Scripts for Database Objects

Creating Seperate Scripts Per Object

FORUM

Scripting objects in SSMS (2008)

Scripted objects are being wrapped in dynamic SQL

ARTICLE

How to Get the Scripts for SQL Server Objects

Using VB Script allows one to script out all the Sql Server objects in independent file.

Tags
powershell    
smo    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones