SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

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

By Gordon, 2008/06/10

Total article views: 355 | Views in the last 30 days: 40

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, 2008/06/10

Total article views: 355 | Views in the last 30 days: 40
Your response
 
 
Related tags

powershell    
SMO    
 
Like this? Try these...

When sp_depends fails

By Jano Petras | Category: Administration
(not yet rated) | 570 reads
Already registered?  

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.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. 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.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com