Stored Procedure Versioning - sql-server

How do you manage revisions of stored procedures?
We have a BI solution on SQL Server 2005 with hundreds of stored procedures.
What would be a good way to get these into Subversion? What are your recommended tools to script stored procedures to files?

There are doubtless a bunch of off-the-shelf products you could buy (I think a few RedGate tools might come in handy here), as well as Visual Studio Team Suite - Database Edition.
In light of purchasing something, why not consider using SQL Management Objects (SMO)?
I've written a couple of utilities which generate T-SQL scripts (using the Scripter class) which produces the same scripts you get from generating scripts through the SQL Server Management Studio (it uses the same functionality).
You could integrate such a utility into a build script/build process which would allow you to generate scripts and then version & check them into a source repository. Plus, you can batch the scripts into a single file (if desired) which beats maintaining hundreds of individual files.
I wrote a blog entry about this approach a while back.
Check out more on the SMO class Scripter
Here's a few more entries which might be useful:
http://www.sqlteam.com/article/scripting-database-objects-using-smo-updated
http://sqlblog.com/blogs/ben_miller/archive/2007/10/03/table-scripting-with-smo-part-1.aspx

See here and here for a start.

Please check out here What is the best way to version control my SQL server stored procedures?. Might help you identify couple of solutions to this issue.

I have previously used a Visual Studio Database Project to manage create table scripts, stored procedure scripts etc. I'm fairly sure you could then use subversion to manage these files in the same way as any Visual Studio project.
I used the built in functionality for scripting the procs, but i'm sure Redgate would have some tasty tools for that.

Related

How can I store my Microsoft SQL Database_Diagram inside SSDT project?

I'm using microsoft SQL Server Data Tools (SSDT), in my projects to try to keep everything in order.
I was wondering if anyone know how to store the Database Diagram into SSDT Project, in order to don't lose any work and keep this model updated with my team?
I tryed to compare it using schema, but it didn't exists.
I also couldn't find any Database Diagram in Visual studio 2013.
Am I wrong to try to use this model type? Are there better ways to do it?
Also, Is it possible to create Jobs throught SSDT?
Thank you very much,
The database diagrams are stored in internal tables so you could add their definitions and include the data in a post deploy script but you would end up deploying to all your environments which is unusual (I don't know your circumstance so I won't say wrong!).
Unless you particularly needed the diagrams in ssms I would look to something else, redgate have a database diagramming tool, I prefer to keep a copy of Visio 2010 pro to generate them, the vsd files can then be added to the project and shared between the team.
I assume it is to help document your databases but If you wanted the editing and designer support from diagrams you get that other ways with ssdt.
Re: jobs, there is no native object but you can create them in pre/post deploy scripts.

Will Visual Studio 2010 Deploy SQL DB Schema Updates?

I have, admittedly, done very little searching on my own, so feel free to insult and/or harass me.
I have two databases that I use, one for development and one for production. In Visual Studio 2010, I have simple overrides that change the connection string based on whether I'm building for Debug or for Release.
Right now, I manually change the database schemas when needed. I've thought about creating scripts, but I'm wondering if there is a better way? Can I create a DB in Visual Studio on my local computer, migrate those changes to the development SQL and then, finally, migrate up to Production so that the schema version matches the release?
Thanks in advance!
.NET 4 | Visual Studio 2010 | MS SQL Server 2008
Are you familiar with Visual Studio Database Edition? It's reason for being is to help you with what you just described. Not only does it allow you to version control your database schema, it allows you to build deployment T-SQL scripts to update a database from one version to another. It has built in schema compare and data compare. I highly recommend it. We use it to version control our database schema and to do deployments. I would never attempt to update database schemas by creating manual scripts anymore.
This used to be a pain in the ass for me. Then I bought this: http://www.red-gate.com/products/sql-development/sql-source-control/
Which, providing your're using a compatible Source-Control solution (such as SVN), you can make changes in one database, commit them, and then update other databases with the same structure.
As Randy mentions, the Database Edition of VS.NET will do this.
I use SQL Delta. It's a third party tool and very well priced for what it does. I've used it for a number of years on extremely large projects (that is the database has hundreds of tables and thousands of stored procedures) and it has never failed us in what it does.
The way I used it is this.
I get it ot produce a blank database
schema as per the development
database.
Move this database over to
the production server
Sync the production database with this database
You can also produce scripts and run the scripts and all of this can be automated.

Any script document browser addin for SQL Management Studio?

I am often making changes to some large sql script files containing hundreds of stored procs, and navigating through those is not an easy task. Is there an (free or cheap) addin for Management Studio that would allow me to easily navigate between statements in a script? Something like a list of CREATE TABLE/CREATE PROC statements, etc...
I use at work Notepad++ with the Function List plugin for editing SQL and works fine (although it has an occasional crash since the plugin is a beta version). I use it regularly with the script of a whole database and helps a lot when looking for a particular definition.
The default configuration for SQL only lists functions and procedures, but since the plugin rules (regex) are configurable I adapted it a bit for the SQL Server syntax and added more rules, so it shows by category tables, views, functions, procedures, indexes, etc..
PS: If you are willing to try it, I could share the XML file that stores the regex rules.
You could try the Summarize Script feature in the upcoming SQL Prompt 5 to navigate a large script.
As this isn't yet released, you can use the EA version in the meantime. For more information, visit http://www.red-gate.com/MessageBoard/viewtopic.php?t=11846
SQL Enlight worked for me
I don't know of any add-ons for SSMS, but you could always create a database project in Visual Studios (database projects aren't included with BIDS i believe) to manage all of your scripts for your databases.

Versioning SQL Server DDL code

I'd like to have all DB DDL code under CVS.
We are using Subversion for our .NET code but all database code remains still unversioned.
All we know is how important DB logic can be. I've googled but I've found only few (expensive tools). I believe there exists other (cheaper) solution(s).
What approach do you advise to follow? What tools are most appropriate?
SQL Server 2005, VS 2008 TS, TSVN
UPDATE
Our coding scenario is that developers cannot access to PROD DB directly. It is changed only by scripts (so this is not a problem)
I'm mostly interested in the DEV environment where all of developers have full access.
So it happens that a developer overwrite USP previously changed by another.
I'd like to have the possibility to restore lost version / compare USPs revisions etc.
UPDATE-2
To create deployment script we are using Red-Gate SQL Compare.
Works perfectly - so deployment scripts are not a case.
If you haven't already read it, Martin Fowler's article Evolutionary Database Design is a great place to start.
The article is hard to summarize, but it describes how his team dealt with database versioning in a rapidly changing development process. They created their own tools to facilitate things: scripts to bring users up to the current master, to copy any version of the schema so users could debug one another's working copies, etc..
For a solid low-tech solution, I've found it helpful to keep two kinds of DDL scripts in source control:
A master version that can create the database objects from scratch.
'Version upgrade' scripts for each development iteration.
They're redundant to a degree, but extremely useful (particularly when it comes to deployment).
If you haven't already looked at the Visual Studio Database Edition GDR (a.k.a. "Data Dude"), you should definitely download it and try it out:
http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&displaylang=en
Among other things, the GDR will facilitate team development by making it easy for each developer to maintain their own local copy of a database, version scripts, create deployment scripts to move a database schema to a new version, and even support database rollback.
It's free if you are using team system developer edition. Check it out.
If you are using Visual Studio Team Suite or Visual Studio Developer Edition, you are entitled to a copy of Visual Studio Database Professional. This is designed to do exactly what you describe, and much more. We use it to manage our database schema (code).
Randy
We use Subversion for all our database code as well. Since nothing is allowed to go to Prod unless it is in a script, there seems to be no porblem with getting people to put all the scripts into subversion. We tend to write alter table scripts to change tables with existing data and then recreate the whole table structure in case we need to create a new database from scratch (we often have the same database structure on multiple servers as some of our clients are very large and do not want their data accidentally available to the competition and so pay for separate servers and therefore may need to create the whole database again with no data.) For objects that don't directly store data we drop the orginal object and recreate it with a create statement. Each project has it's own home inthe repository and each database does too, so the script may be in more than one place to facilitate deployment.
But the real key is that no one can load to Prod without a script. We don't give our devs direct rights to prod, so they have no problem doing things in scripts as opposed to using SSMS.
I wrote SMOscript which generates a CREATE script for each object in a database.
Use this tool to generate into a directory covered by CVS, and update your repository.
Finally I found this tool and approach extremely useful and very easy to introduce
(at least at the beginning - where no versioning solution on the place):
http://www.codeproject.com/KB/database/SQLScripter.aspx
You can run it out of the box.
For final solution I'd incline to GDR.
This also sounds interesting:
Freeware:
http://dbsourcetools.codeplex.com/
http://www.codeproject.com/KB/database/ScriptDB4Svn.aspx
http://www.codeproject.com/KB/database/SQLScripter.aspx
http://blog.boxedbits.com/archives/133
Commercial:
http://www.nobhillsoft.com/Randolph.aspx
You should use Management Studio (SSMS) and place the .sql under source control, possibly separate schema objects under folders.
Hope this helps
See if Wizardby fits your needs.

Tools to generate SQL DDL and Content from an existing database

Does anyone know of a reasonably priced tool that will create DDL statements to create a SQL Server database and appropriate Insert statements to recreate the data? I use the Red Gate tools to do database compares (including content compares) and this comes close (I could always compare with an empty schema) but I was wondering if there was a tool that others found useful that did this in one step.
Late answer... hopefully someone will find it useful…
There is a tool from Red Gate called SQL Multi Script that can do scripting for what you need. Not sure if it existed when the question was asked though :)
Another good piece is SQL build tool from ApexSQL which can also do all kind of insert and other scripts…
Disclaimer: I’m not affiliated with any of the companies mentioned above.
Have you had a look at SQL Publishing Wizard? It will create all the DDL statements you require for all database elements (tables, views, SPs, users etc).
If you're using SQL 2008, it comes built into the management studio. More info on 2008.
SQL Publishing Wizard
Saw Austin Solonen post this tool in a somewhat related thread. Express editions appearantly don't hove Import and Export.
The database publishing wizard that is included in Visual Studio 2008 performs this function.
It is also available via CodePlex as an add-on for prior versions of Visual Studio.

Resources