Options

API to layout SQL scripts?

kevinukevinu Posts: 2
edited March 4, 2008 6:19AM in SQL Toolkit Previous Versions
Our SQL scripts are initially generated from SQL compare and checked into version control. There is also a need to quickly generate a new script for a single object. For that we are currently using SMO. This of course can result in inconsistent formatting in the scripts producing source control differences when none were intended.

We would like to use the RedGate engine to do all of the formatting. There are 2 ways that we can think of to accomplish this.

1. Is there a way to call a RedGate API that will quickly script out a single object, without having to register and compare the entire database? If so, we would use this instead of SMO.

2. Or, is there a RedGate API that will take an input script and generate a formatted output script, similar to the Layout function of SQL Refactor?

Thanks!

Kevin
Sage Software

Comments

  • Options
    Michelle TMichelle T Posts: 566 Gold 1
    You have to register the entire database in order to script out an object, but you don't have to compare it to anything.

    Once you have registered the database, create a new Work object (constructor has no parameters) and call Work.ScriptObject on the single object you want to script out (you can find the relevant IDatabaseObject by navigating through the Database object you get from registering the database).

    Partial database registration is on our list of things to do but realistically we're not going to get around to it for some time because normally just registering the entire database is fast enough.
    Software Developer
    Redgate Software
Sign In or Register to comment.