Introducing SMOscript

SQL Server 2000 provides a tool called scptxfr which generates DROP and CREATE scripts for all objects in a database. Unfortunately it is not included in SQL Server 2005.

In the batch files I described in my posts about automating the build process, I also call it to generate a script for all database objects which is then used in version control.

Since it is not included in the latest SQL Server versions, I developed a replacement for scptxfr which uses the .Net SMO libraries for script generation called SMOscript:

smoscript 0.10.3169.17676 (c) by devio.at 2008

    list and script databases and database objects.

    usage: smoscript [options] [command]

    options: (leading '-' or '/')

    -s server       server name
    -d database     database name
    -u username     username (default: integrated authentication)
    -p password     password (if -u is missing, password for sa)

    -r              generate DROP statements
    -i              include IF NOT EXISTS statements

    -f filename     output to file
    -F directory    output to directory

    -A              current ANSI codepage
    -O              ASCII
    -T              Unicode
    -U              UTF8

    commands:

    l               list
    s               script object/s

    list databases on server (implied by -s)
    list objects in database (implied by -s -d)
    script object (implied by -s -d -o)
    script all objects (implied by -s -d -F/-f)

The SMOscript utility implements the following functions:

  • list all databases on a server
  • list all objects in a database
  • script CREATE or DROP statements for each object in database

Resulting script are either written to a single file, or to a separate file for each object.

Command line switches were selected to be compatible with scptxfr, but support both “-” and “/” as switch marker.

SMOscript is available for download here.

About these ads

3 Responses to Introducing SMOscript

  1. [...] Scripting database objects using SMO I created SMOscript a couple of months ago with the intention to make it a replacement for the SQL Server 2000 tool called [...]

  2. Uwe says:

    Best tool ever! Thank you very much.

  3. Rick says:

    I there a place I can get the source code?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 66 other followers

%d bloggers like this: