Alex Rivera | Logout

Should you store your SQL Stored Procedures in Source Control?

Asked 2009-02-19T22:00:40.870
13

When developing an application with lots of stored procedures, should you store them in some sort of source versioning system (such as source-safe, TFS, SVN)? If so, why? And is there a convenient front end way to do this with SQL Server Management Studio?

Edit
Report

4 Answers

7

Get your database under version control. Check the series of posts by Scott Allen.

When it comes to version control, the database is often a second or even third-class citizen. From what I've seen, teams that would never think of writing code without version control in a million years-- and rightly so-- can somehow be completely oblivious to the need for version control around the critical databases their applications rely on. I don't know how you can call yourself a software engineer and maintain a straight face when your database isn't under exactly the same rigorous level of source control as the rest of your code. Don't let this happen to you. Get your database under version control.

answered 2009-02-19T22:06:21.933
1

Absolutely. Positively.

A set of SPs is an interface, that is likely to be modified more frequently than structural changes. And because SPs contain business logic, changes should be stored in version control to track the modifications and adjustments to the logic.

Storing these in version control is a symptom of organizational maturity at a coding level, and is a best practice.

answered 2009-02-19T22:13:43.197
0

SPs and table schemas for that matter are all assets that should be under version control. In a perfect world the DB would be built from scripts, including the test data, as part of your CI process. Even if that's not the case, having a DB/developer is a good model to follow. In that way new ideas can be tried out in a local sandbox without impacting everyone, once the change is tested it can be checked in.

Management Studio can be linked to source control, although I don't have experience of doing this. We've always tracked our SP/schema as files. Management studio can automatically generate change scripts, which are very useful, as table drop/recreate can be too heavy handed for any table that has data.

answered 2009-02-19T22:04:11.737
0

There are methods in SMO to generate scripts if you prefer to code your own scripting tool.

http://www.sqlteam.com/article/scripting-database-objects-using-smo-updated

answered 2009-02-19T23:31:28.780

Your Answer