Source Control Scripting in SC ver3

mdgravesmdgraves Posts: 53
When I first link to a new database in SC ver3, and add my dbase to Source Control, the program scripts out the objects. How can I control the script template?

Example.
I want each object script to have pre-steps to test/DROP...CREATE

IF OBJECT_ID('<<###>>') IS NOT NULL
DROP PROCEDURE <<###>>
GO
CREATE PROCEDURE <<###>>

Comments

  • Thanks for your post. Unfortunately, there isn't any way to perform this sort of task on an object by object basis.

    You could however, if you wanted to create a migrations script that performed a DROP IF EXISTS etc. on the entire DB.

    HTH!

    Pete
    Peter Peart
    Red Gate Software Ltd
    +44 (0)870 160 0037 ext. 8569
    1 866 RED GATE ext. 8569
  • Can I ask why you want the object definition script to also include a drop statement?

    These creation scripts are saved in source control for the sole purpose of defining the state of the schema. These scripts are not designed to be executed.

    If you want to deploy from these scripts, you should use SQL Compare Pro to generate the script. This has an option to add a drop/create to the deployment script.

    David Atkinson
    Product Manager
    Red Gate
    David Atkinson
    Product Manager
    Redgate Software
  • David,
    I was under impression Source Control scripts were OK for execution, and I have tested it as link to get scripts for all of my schema and objects into TFS source control, and as interface between TFS and SSMS.

    Our standard is to use DROP & CREATE statement combinations, as opposed to ALTER. This factors into 'creation date' and system auditing. On the DBA team, when development (who owns the user databases) sends us a case to promote, we use the scripts that hopefully they are managing in TFS..

    Will the Source Control tool be a stand along product, or a bolt-on for SQL Compare Pro?

    - Regards,
    Martin Graves
    Database Technical Lead
    Georgia-Pacific Building Products LLC
  • They are okay for execution but aren't designed to be executed.

    Please explain the logic behind the creation date and system auditing. I'd be interested to understand this further.

    Both SQL Source Control and SQL Compare Pro are standalone tools, but they complement each other a lot when used together. SQL Compare Pro is the supported mechanism to deploy from source controlled scripts. This is recommended over executing the CREATE statements.

    David
    David Atkinson
    Product Manager
    Redgate Software
  • "creation date and system auditing"

    In the past, queries on the "sysobjects" table for the "creation" date have been utilized by auditors to track when objects changed in user database, then in turn look for change documentation for that object and date. No other date column in table works correctly (per MS). The ALTER by-passes this date field, therefore creating an untrackable event.

    I haven't checked this fact using the newer 'system views' (sys.objects), but willing to be it is same.
  • You might want to consider using DDL triggers to log schema changes, rather than relying on the creation date. That way you'll be sure to catch all modifications.

    David
    David Atkinson
    Product Manager
    Redgate Software
  • Thanks for suggestion.
Sign In or Register to comment.