Source Control Scripting in SC ver3

A SQL Server Management Studio add-in to source control your database in Subversion or Team Foundation Server.

Moderators: Chris Auckland, David Atkinson, sherr, PhilScrace

Source Control Scripting in SC ver3

Postby mdgraves » Thu Dec 15, 2011 9:54 pm

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 <<###>>
mdgraves
 
Posts: 42
Joined: Fri Sep 21, 2007 7:56 pm

Postby peter.peart » Mon Dec 19, 2011 2:56 pm

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
peter.peart
Site Admin
 
Posts: 362
Joined: Tue Sep 02, 2008 9:58 am
Location: Top floor, RG towers with the cool kids

Postby David Atkinson » Mon Dec 19, 2011 4:46 pm

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
 
Posts: 1124
Joined: Mon Dec 05, 2005 4:54 pm
Location: Twitter: @dtabase

DROP STATEMENT

Postby mdgraves » Wed Dec 28, 2011 5:48 pm

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
mdgraves
 
Posts: 42
Joined: Fri Sep 21, 2007 7:56 pm

Postby David Atkinson » Wed Dec 28, 2011 6:23 pm

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
 
Posts: 1124
Joined: Mon Dec 05, 2005 4:54 pm
Location: Twitter: @dtabase

creation date and system auditing

Postby mdgraves » Wed Dec 28, 2011 9:01 pm

"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.
mdgraves
 
Posts: 42
Joined: Fri Sep 21, 2007 7:56 pm

Postby David Atkinson » Thu Dec 29, 2011 1:43 pm

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
 
Posts: 1124
Joined: Mon Dec 05, 2005 4:54 pm
Location: Twitter: @dtabase

auditing

Postby mdgraves » Thu Dec 29, 2011 3:31 pm

Thanks for suggestion.
mdgraves
 
Posts: 42
Joined: Fri Sep 21, 2007 7:56 pm


Return to SQL Source Control 2

Who is online

Users browsing this forum: No registered users and 0 guests