SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

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

By Gordon-265412, 2008/06/10

Total article views: 625 | Views in the last 30 days: 27

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).

By Gordon-265412, 2008/06/10

Total article views: 625 | Views in the last 30 days: 27
Your response
 
 
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

Free registration required...

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Login (existing users)

Login

Email:   Password:   Remember me: Forgotten your password?

Register (new users)

Register

Email:   Password:
Confirm:

Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

Steve Jones
Editor, SQLServerCentral.com