<p>I'm early in development on a web application built in VS2008. I have both a desktop PC (where most of the work gets done) and a laptop (for occasional portability) on which I use AnkhSVN to keep the project code synced. What's the best way to keep my development database (SQL Server Express) synced up as well?</p>

<p>I have a VS database project in SVN containing create scripts which I re-generate when the schema changes. The original idea was to recreate the DB whenever something changed, but it's quickly becoming a pain. Also, I'd lose all the sample rows I entered to make sure data is being displayed properly.</p>

<p>I'm considering putting the .MDF and .LDF files under source control, but I doubt SQL Server Express will handle it gracefully if I do an SVN Update and the files get yanked out from under it, replaced with newer copies. Sticking a couple big binary files into source control doesn't seem like an elegant solution either, even if it is just a throwaway development database. Any suggestions?</p>

[{'answer_id': 40963, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 2, 'selected': False, 'text': "<p>You can store backup (.bak file) of you database rather than .MDF &amp; .LDF files.<br>\nYou can restore your db easily using following script:  </p>\n\n<pre><code>use master\ngo\n\nif exists (select * from master.dbo.sysdatabases where name = 'your_db')\nbegin\n    alter database your_db set SINGLE_USER with rollback IMMEDIATE\n    drop database your_db\nend\n\nrestore database your_db\nfrom disk = 'path\\to\\your\\bak\\file'\nwith move 'Name of dat file' to 'path\\to\\mdf\\file',\n     move 'Name of log file'  to 'path\\to\\ldf\\file'\ngo\n</code></pre>\n\n<p>You can put above mentioned script in text file restore.sql and call it from batch file using following command:  </p>\n\n<pre><code>osql -E -i restore.sql\n</code></pre>\n\n<p>That way you can create script file to automate whole process:  </p>\n\n<ul>\n<li>Get latest db backup from SVN\nrepository or any suitable storage</li>\n<li>Restore current db using bak file</li>\n</ul>\n"}, {'answer_id': 41217, 'author': 'mattsmith321', 'author_id': 3262, 'author_profile': 'https://Stackoverflow.com/users/3262', 'pm_score': 3, 'selected': False, 'text': '<p>There are obviously a number of ways to approach this, so I am going to list a number of links that should provide a better foundation to build on. These are the links that I\'ve referenced in the past when trying to get others on the bandwagon.</p>\n\n<ul>\n<li><a href="https://web.archive.org/web/20210513230815/http://aspnet.4guysfromrolla.com/articles/071305-1.aspx" rel="nofollow noreferrer">Database Projects in Visual Studio .NET</a></li>\n<li><a href="http://www.ssw.com.au/SSW/Standards/Rules/DataSchemaStandard.aspx" rel="nofollow noreferrer">Data Schema - How Changes are to be Implemented</a></li>\n<li><a href="https://blog.codinghorror.com/is-your-database-under-version-control/" rel="nofollow noreferrer">Is Your Database Under Version Control?</a></li>\n<li><a href="https://blog.codinghorror.com/get-your-database-under-version-control/" rel="nofollow noreferrer">Get Your Database Under Version Control</a></li>\n<li>Also look for MSDN Webcast: Visual Studio 2005 Team Edition for Database Professionals (Part 4 of 4): Schema Source and Version Control</li>\n</ul>\n\n<p>However, with all of that said, if you don\'t think that you are committed enough to implement some type of version control (either manual or semi-automated), then I HIGHLY recommend you check out the following:</p>\n\n<ul>\n<li><a href="http://www.red-gate.com/products/SQL_Compare/index.htm" rel="nofollow noreferrer">Red Gate SQL Compare</a></li>\n<li><a href="http://www.red-gate.com/products/SQL_Data_Compare/index.htm" rel="nofollow noreferrer">Red Gate SQL Data Compare</a></li>\n</ul>\n\n<p>Holy cow! Talk about making life easy! I had a project get away from me and had multiple people in making schema changes and had to keep multiple environments in sync. It was trivial to point the Red Gate products at two databases and see the differences and then sync them up.</p>\n'}, {'answer_id': 41227, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 1, 'selected': False, 'text': '<p>We use a combo of, taking backups from higher environments down.<br>\nAs well as using ApexSql to handle initial setup of schema.<br>\nRecently been using Subsonic migrations, as a coded, source controlled, run through CI way to get change scripts in, there is also "tarantino" project developed by headspring out of texas.</p>\n\n<p>Most of these approaches especially the latter, are safe to use on top of most test data. I particularly like the automated last 2 because I can make a change, and next time someone gets latest, they just run the "updater" and they are ushered to latest.</p>\n'}, {'answer_id': 41229, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 3, 'selected': True, 'text': '<p>In addition to your database CREATE script, why don\'t you maintain a default data or sample data script as well? </p>\n\n<p>This is an approach that we\'ve taken for incremental versions of an application we have been maintaining for more than 2 years now, and it works very well. Having a default data script also allows your QA testers to be able to recreate bugs using the data that you also have?</p>\n\n<p>You might also want to take a look at a question I posted some time ago:</p>\n\n<p><a href="https://stackoverflow.com/questions/10688/best-tool-for-auto-generating-sql-change-scripts">Best tool for auto-generating SQL change scripts</a></p>\n'}]
['https://Stackoverflow.com/questions/40957', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4160/']