I have been wondering how to put all the stored procedures on a SQL 2000 under source control.
We are using Subversion for all our normal source code, so it would be great if there were a solution to the problem using Subversion.
Do you have any ideas?
Update 16-02-2009: This is the vbs script i used to export all the stored procedures:
Set con = CreateObject("ADODB.Connection")
con.ConnectionString = "*** Database connection string here ***"
con.Open
Set rs = CreateObject("ADODB.RecordSet")
rs.ActiveConnection = con
strSQL = "SELECT ROUTINE_NAME, ROUTINE_DEFINITION " & _
"FROM INFORMATION_SCHEMA.routines " & _
"WHERE ROUTINE_NAME NOT LIKE 'dt_%' " & _
"ORDER BY 1"
Set fso = CreateObject("Scripting.FileSystemObject")
rs.Open strSQL
While Not rs.Eof
filename = rs("ROUTINE_NAME") & ".sql"
routineSQL = rs("ROUTINE_DEFINITION")
Set tf = fso.CreateTextFile(filename, True)
tf.Write routineSQL
tf.Close
set tf = Nothing
rs.MoveNext
Wend
Set fso = Nothing
rs.Close
Set rs = Nothing
Stored procedures promote bad development practices, in particular they require you to violate DRY (Don't Repeat Yourself), since you have to type out the list of fields in your database table half a dozen times or more at least. This is a massive pain if you need to add a single column to your database table.
Usually you track the changes to SQL scripts in source control. For example, you have a checkin for your base schema for your database. Then you keep adding new SQL files for changes to your schema. That way you can deploy to an exact version for testing purposes. Then you can use build automation to automatically test some of your scripts by executing them against test databases with actual data in them.
There are lots of database diff tools around that can help you work out what's changed between versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With