I had an interesting problem. I have to do a compare between our development database server and source control for all stored procedures and if needed sync them. So the way I was going to do it was to script out all stored procs and use WinDiff to compare the folder I dumped to from SQL Server and our Source Control folder. Problem was how do I script like 2000 ( yes two thousand ) stored procedures to individual files !? I am pretty sure that in Enterprise Manager you could just right click the whole selection and say script to files or something of the sort. In 2005 that functionality seems to be missing. Well it’s not… It just got moved. After some Googling ( yeah, that’s a verb now ), I found this blog :
This shows how to script the database entirely, triggers, constraints, etc. I just wanted the procs. So what to do?? Well if you look through his tutorial, you don’t want all the objects in the database so where he tells you to check this box:
Don’t … Leave that blank since you don’t want all the objects.
The next screen will have a whole bunch of properties, I didn’t really touch those… least I don’t think I did. Just hit Next and you will arrive at this screen where you want to select Stored Procedures :
Hit Next to go to the following screen where you will see all of your stored procs. I chose Select All since that is what I needed but you can pick and choose here.
Once you have chosen which procs to script out you can hit Next. You will arrive at the last screen. This is where you specify a folder to script the stuff out to:
On this screen you want to specify that you want to Script to file, you want one File per object, and then the File name or in our case the directory. If you are doing file per object just put in something like C:\SQLDump\ . That will dump all your stored procs to that folder.
That’s it… just get ready to wait if you have a lot of procs. The server I did this on had a few thousand so that took like 5 minutes.
Two responses before the comments get posted
1. I took the screens off of our Dev server so thats why I blanked out some of the information.
2. If this seems painfully obvious to you I am sorry… I searched for how to do this and all I found was a lot of people complaining that they can’t script stuff out anymore and how SQL Server 2005 is a step back.
Anyway, if you want to compare what you scripted out with another source, just use WinDiff to compare directories. I had to use this Bulk Rename Utility to name the scripted files the same as the source files.
PS: Big thanks to Pinal Dave for the initial post on how to script that DB out that got me on the right track!!