Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Scripting Inserts / Source Control

Author  Topic 

RyanSmith
Starting Member

8 Posts

Posted - 2007-01-25 : 12:54:31
Hello SQL Server Community.

I'm looking for a way to keep my database in Subversion so I can maintain it in source control.

Seems like the best way to do this would be to dump the database to a text script file. This works fine for creating the database structure and managing those change, however, that database structure is useless without the actual data in the tables.

Is there a good way to generate the inserts for the actual data? Why isn't this an option in the script wizard.

Also, does anyone have a better idea of source control of SQL Server databases in Subversion?

Thanks,
Ryan.

http://www.dynamicajax.com

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-01-25 : 14:07:54
SQLTeam member jezemine has created a scripting tool called ScriptDb that does that for you
http://www.elsasoft.org/tools.htm

Not sure that you want to put anything more than a pretty small database in Subversion though?! That's what backups are for
Go to Top of Page

RyanSmith
Starting Member

8 Posts

Posted - 2007-01-25 : 14:48:32
Thanks, for the link. That looks like exactly what I need. Hopefully it will all work out good.

I have heard that Visual Studio Team System Database Edition has a really nice tool for versioning databases, but unfortunately for a two man team there is no way I could justify the cost. Hopefully Microsoft makes this available in their Express editions or creates some sort of mechanism to handle database source control.

http://www.dynamicajax.com
Go to Top of Page

RyanSmith
Starting Member

8 Posts

Posted - 2007-01-25 : 15:18:32
That tool is great. Now the only problem that I have is I need a tool to easily recreate the database using those scripts.

Thanks again for the link.

http://www.dynamicajax.com
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-01-26 : 16:11:23
it would be easy to do with a bat file that traverses the directories and invokes sqlcmd.exe or osql.exe.

if you write one, let me know and I'll add it to the site. Or maybe I'll do it. but probabaly not. :)


www.elsasoft.org
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-01-26 : 16:14:54
quote:
Originally posted by snSQL
Not sure that you want to put anything more than a pretty small database in Subversion though?! That's what backups are for



keeping all the object definitions in source control is a very good idea. that way it's very easy to see the history of changes. it would be difficult to extract the history of how a sproc changed from a backup set. you'd have to restore multiple times, painful.

the data itself does NOT belong in source control however. that belongs in the backups.


www.elsasoft.org
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-01-26 : 17:09:11
Absolutely! I was referring to Ryan's reference to inserts when I said that storing the database in Subversion would not be a good idea. "Is there a good way to generate the inserts for the actual data?"
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-01-26 : 22:25:05
understood.

the only kind of row data I typically store in source control would be "seed" data that's necessary for a working build of a db. and even then I store it as csv exported with bcp, not as individual insert statements.

normally seed data would only be 10's or 100's of rows in any case, nothing huge.

EDIT: Forgot to mention that if you *do* need to generate insert statements, you can use this: http://vyaskn.tripod.com/code.htm (search for "Procedure to script your data" on that page)


www.elsasoft.org
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-02-03 : 17:42:01
quote:
Originally posted by jezemine

it would be easy to do with a bat file that traverses the directories and invokes sqlcmd.exe or osql.exe.

if you write one, let me know and I'll add it to the site. Or maybe I'll do it. but probabaly not. :)


www.elsasoft.org



Well, I finally got around do doing this. I added it to the zip here (look for a file named builddb.bat):

http://www.elsasoft.org/scriptdb.zip


www.elsasoft.org
Go to Top of Page
   

- Advertisement -