<p>I want to get my databases under version control.</p>
<p>I'll always want to have at least <em>some</em> data in there (as <a href="https://stackoverflow.com/users/80/alumb">alumb</a> mentions: user types and administrators). I'll also often want a large collection of generated test data for performance measurements.</p>
<p>How would I apply version control to my database?</p>

[{'answer_id': 195, 'author': 'alumb', 'author_id': 80, 'author_profile': 'https://Stackoverflow.com/users/80', 'pm_score': 5, 'selected': False, 'text': '<p>This is one of the "hard problems" surrounding development. As far as I know there are no perfect solutions. </p>\n\n<p>If you only need to store the database structure and not the data you can export the database as SQL queries. (in Enterprise Manager: Right click on database -> Generate SQL script. I recommend setting the "create one file per object" on the options tab) You can then commit these text files to svn and make use of svn\'s diff and logging functions. </p>\n\n<p>I have this tied together with a Batch script that takes a couple parameters and sets up the database. I also added some additional queries that enter default data like user types and the admin user. (If you want more info on this, post something and I can put the script somewhere accessible)</p>\n\n<p>If you need to keep all of the data as well, I recommend keeping a back up of the database and using Redgate (<a href="http://www.red-gate.com/" rel="noreferrer">http://www.red-gate.com/</a>) products to do the comparisons. They don\'t come cheap, but they are worth every penny.</p>\n'}, {'answer_id': 516, 'author': 'ESV', 'author_id': 150, 'author_profile': 'https://Stackoverflow.com/users/150', 'pm_score': 9, 'selected': True, 'text': '<p>Martin Fowler wrote my favorite article on the subject, <a href="http://martinfowler.com/articles/evodb.html" rel="noreferrer">http://martinfowler.com/articles/evodb.html</a>.  I choose not to put schema dumps in under version control as <em>alumb</em> and others suggest because I want an easy way to upgrade my production database.</p>\n\n<p>For a web application where I\'ll have a single production database instance, I use two techniques:</p>\n\n<h1>Database Upgrade Scripts</h1>\n\n<p>A sequence database upgrade scripts that contain the DDL necessary to move the schema from version N to N+1.  (These go in your version control system.)  A _version_history_ table, something like</p>\n\n<pre><code>create table VersionHistory (\n    Version int primary key,\n    UpgradeStart datetime not null,\n    UpgradeEnd datetime\n    );\n</code></pre>\n\n<p>gets a new entry every time an upgrade script runs which corresponds to the new version.</p>\n\n<p>This ensures that it\'s easy to see what version of the database schema exists and that database upgrade scripts are run only once.  Again, these are <strong>not</strong> database dumps.  Rather, each script represents the <strong>changes</strong> necessary to move from one version to the next.  They\'re the script that you apply to your production database to "upgrade" it.</p>\n\n<h1>Developer Sandbox Synchronization</h1>\n\n<ol>\n<li>A script to backup, sanitize, and shrink a production database.  Run this after each upgrade to the production DB.</li>\n<li>A script to restore (and tweak, if necessary) the backup on a developer\'s workstation.  Each developer runs this script after each upgrade to the production DB.</li>\n</ol>\n\n<p><em>A caveat: My automated tests run against a schema-correct but empty database, so this advice will not perfectly suit your needs.</em></p>\n'}, {'answer_id': 521, 'author': 'Matt', 'author_id': 154, 'author_profile': 'https://Stackoverflow.com/users/154', 'pm_score': 3, 'selected': False, 'text': '<p>You didn\'t mention any specifics about your target environment or constraints, so this may not be entirely applicable... but if you\'re looking for a way to effectively track an evolving DB schema and aren\'t adverse to the idea of using Ruby, ActiveRecord\'s migrations are right up your alley.</p>\n\n<p>Migrations programatically define database transformations using a Ruby DSL; each transformation can be applied or (usually) rolled back, allowing you to jump to a different version of your DB schema at any given point in time. The file defining these transformations can be checked into version control like any other piece of source code.</p>\n\n<p>Because migrations are a part of <a href="http://ar.rubyonrails.com/" rel="noreferrer">ActiveRecord</a>, they typically find use in full-stack Rails apps; however, you can use ActiveRecord independent of Rails with minimal effort. See <a href="http://rails.aizatto.com/2007/05/27/activerecord-migrations-without-rails/" rel="noreferrer">here</a> for a more detailed treatment of using AR\'s migrations outside of Rails.</p>\n'}, {'answer_id': 599, 'author': 'engtech', 'author_id': 175, 'author_profile': 'https://Stackoverflow.com/users/175', 'pm_score': 3, 'selected': False, 'text': "<p>The typical solution is to dump the database as necessary and backup those files.</p>\n\n<p>Depending on your development platform, there may be opensource plugins available. Rolling your own code to do it is usually fairly trivial.</p>\n\n<p>Note: You may want to backup the database dump instead of putting it into version control.  The files can get huge fast in version control, and cause your entire source control system to become slow (I'm recalling a CVS horror story at the moment).</p>\n"}, {'answer_id': 4088, 'author': 'Lance Fisher', 'author_id': 571, 'author_profile': 'https://Stackoverflow.com/users/571', 'pm_score': 4, 'selected': False, 'text': '<p>You could also look at a migrations solution.  These allow you to specify your database schema in C# code, and roll your database version up and down using MSBuild.</p>\n\n<p>I\'m currently using <a href="https://dbup.github.io/" rel="noreferrer">DbUp</a>, and it\'s been working well.</p>\n'}, {'answer_id': 4096, 'author': 'Chris Miller', 'author_id': 206, 'author_profile': 'https://Stackoverflow.com/users/206', 'pm_score': 3, 'selected': False, 'text': "<p>We don't store the database schema, we store the changes to the database.  What we do is store the schema changes so that we build a change script for any version of the database and apply it to our customer's databases.  I wrote an database utility app that gets distributed with our main application that can read that script and know which updates need to be applied.  It also has enough smarts to refresh views and stored procedures as needed.</p>\n"}, {'answer_id': 5322, 'author': 'Ray', 'author_id': 233, 'author_profile': 'https://Stackoverflow.com/users/233', 'pm_score': 4, 'selected': False, 'text': '<p>We use <a href="http://www.innovartis.co.uk/" rel="noreferrer">DBGhost</a> to manage our SQL database. Then you put your scripts to build a new database in your version control, and it\'ll either build a new database, or upgrade any existing database to the schema in version control. That way you don\'t have to worry about creating change scripts (although you can still do that, if for example you want to change the data type of a column and need to convert data).</p>\n'}, {'answer_id': 5336, 'author': 'Jon Galloway', 'author_id': 5, 'author_profile': 'https://Stackoverflow.com/users/5', 'pm_score': 3, 'selected': False, 'text': '<p>If you have a small database and you want to version the entire thing, <a href="http://weblogs.asp.net/jgalloway/archive/2006/10/28/Batch-files-to-check-SQL-2005-_2800_MDF_2900_-files-in-and-out-of-Subversion-source-control.aspx" rel="nofollow noreferrer">this batch script</a> might help. It detaches, compresses, and checks a MSSQL database MDF file in to Subversion.</p>\n<p>If you mostly want to version your schema and just have a small amount of reference data, you can possibly use <a href="http://web.archive.org/web/20120419154556/http://blog.wekeroad.com:80/blog/subsonic-using-migrations" rel="nofollow noreferrer">SubSonic Migrations</a> to handle that. The benefit there is that you can easily migrate up or down to any specific version.</p>\n'}, {'answer_id': 22917, 'author': 'TheEmirOfGroofunkistan', 'author_id': 1874, 'author_profile': 'https://Stackoverflow.com/users/1874', 'pm_score': 3, 'selected': False, 'text': '<p>We just started using Team Foundation Server.  If your database is medium sized, then visual studio has some nice project integrations with built in compare, data compare, database refactoring tools, database testing framework, and even data generation tools.</p>\n\n<p>But, that model doesn\'t fit very large or third party databases (that encrypt objects) very well.  So, what we\'ve done is to store only our customized objects.  Visual Studio / Team foundation server works very well for that.</p>\n\n<p><a href="http://blogs.msdn.com/gertd/" rel="noreferrer">TFS Database chief arch. blog</a></p>\n\n<p><a href="http://msdn.microsoft.com/en-us/tfs2008/default.aspx" rel="noreferrer">MS TFS site</a></p>\n'}, {'answer_id': 27508, 'author': 'Dane', 'author_id': 2929, 'author_profile': 'https://Stackoverflow.com/users/2929', 'pm_score': 6, 'selected': False, 'text': "<p>Red Gate's SQL Compare product not only allows you to do object-level comparisons, and generate change scripts from that, but it also allows you to export your database objects into a folder hierarchy organized by object type, with one [objectname].sql creation script per object in these directories.  The object-type hierarchy is like this:</p>\n\n<p>\\Functions<br>\n\\Security<br>\n\\Security\\Roles<br>\n\\Security\\Schemas<br>\n\\Security\\Users<br>\n\\Stored Procedures<br>\n\\Tables  </p>\n\n<p>If you dump your scripts to the same root directory after you make changes, you can use this to update your SVN repo, and keep a running history of each object individually.</p>\n"}, {'answer_id': 75083, 'author': 'Dave Jackson', 'author_id': 12328, 'author_profile': 'https://Stackoverflow.com/users/12328', 'pm_score': 3, 'selected': False, 'text': '<p>A while ago I found a VB bas module that used DMO and VSS objects to get an entire db scripted off and into VSS. I turned it into a VB Script and posted it <a href="http://glossopian.co.uk/pmwiki.php?n=Main.DBtoVSS" rel="nofollow noreferrer">here</a>. You can easily take out the VSS calls and use the DMO stuff to generate all the scripts, and then call SVN from the same batch file that calls the VBScript to check them in.</p>\n'}, {'answer_id': 75330, 'author': 'jeffjakub', 'author_id': 12600, 'author_profile': 'https://Stackoverflow.com/users/12600', 'pm_score': 5, 'selected': False, 'text': '<p>You might want to look at Liquibase (<a href="http://www.liquibase.org/" rel="noreferrer">http://www.liquibase.org/</a>). Even if you don\'t use the tool itself it handles the concepts of database change management or refactoring pretty well.</p>\n'}, {'answer_id': 125609, 'author': 'Andrew Swan', 'author_id': 10433, 'author_profile': 'https://Stackoverflow.com/users/10433', 'pm_score': 3, 'selected': False, 'text': '<p>Because our app has to work across multiple RDBMSs, we store our schema definition in version control using the database-neutral <a href="http://db.apache.org/torque/" rel="noreferrer">Torque</a> format (XML). We also version-control the reference data for our database in XML format as follows (where "Relationship" is one of the reference tables):</p>\n\n<pre><code>  &lt;Relationship RelationshipID="1" InternalName="Manager"/&gt;\n  &lt;Relationship RelationshipID="2" InternalName="Delegate"/&gt;\n  etc.\n</code></pre>\n\n<p>We then use home-grown tools to generate the schema upgrade and reference data upgrade scripts that are required to go from version X of the database to version X + 1.</p>\n'}, {'answer_id': 125655, 'author': 'Silvercode', 'author_id': 16663, 'author_profile': 'https://Stackoverflow.com/users/16663', 'pm_score': 4, 'selected': False, 'text': "<p>It is a good approach to save database scripts into version control with change scripts so that you can upgrade any one database you have. Also you might want to save schemas for different versions so that you can create a full database without having to apply all the change scripts. Handling the scripts should be automated so that you don't have to do manual work.</p>\n\n<p>I think its important to have a separate database for every developer and not use a shared database. That way the developers can create test cases and development phases independently from other developers.</p>\n\n<p>The automating tool should have means for handling database metadata, which tells what databases are in what state of development and which tables contain version controllable data and so on.</p>\n"}, {'answer_id': 126936, 'author': 'Jonathan', 'author_id': 6910, 'author_profile': 'https://Stackoverflow.com/users/6910', 'pm_score': 3, 'selected': False, 'text': "<p>To make the dump to a source code control system that little bit faster, you can see which objects have changed since last time by using the version information in sysobjects.</p>\n\n<p><strong>Setup:</strong> Create a table in each database you want to check incrementally to hold the version information from the last time you checked it (empty on the first run). Clear this table if you want to re-scan your whole data structure.</p>\n\n<pre><code>IF ISNULL(OBJECT_ID('last_run_sysversions'), 0) &lt;&gt; 0 DROP TABLE last_run_sysversions\nCREATE TABLE last_run_sysversions (\n    name varchar(128), \n    id int, base_schema_ver int,\n    schema_ver int,\n    type char(2)\n)\n</code></pre>\n\n<p><strong>Normal running mode:</strong> You can take the results from this sql, and generate sql scripts for just the ones you're interested in, and put them into a source control of your choice.</p>\n\n<pre><code>IF ISNULL(OBJECT_ID('tempdb.dbo.#tmp'), 0) &lt;&gt; 0 DROP TABLE #tmp\nCREATE TABLE #tmp (\n    name varchar(128), \n    id int, base_schema_ver int,\n    schema_ver int,\n    type char(2)\n)\n\nSET NOCOUNT ON\n\n-- Insert the values from the end of the last run into #tmp\nINSERT #tmp (name, id, base_schema_ver, schema_ver, type) \nSELECT name, id, base_schema_ver, schema_ver, type FROM last_run_sysversions\n\nDELETE last_run_sysversions\nINSERT last_run_sysversions (name, id, base_schema_ver, schema_ver, type)\nSELECT name, id, base_schema_ver, schema_ver, type FROM sysobjects\n\n-- This next bit lists all differences to scripts.\nSET NOCOUNT OFF\n\n--Renamed.\nSELECT 'renamed' AS ChangeType, t.name, o.name AS extra_info, 1 AS Priority\nFROM sysobjects o INNER JOIN #tmp t ON o.id = t.id\nWHERE o.name &lt;&gt; t.name /*COLLATE*/\nAND o.type IN ('TR', 'P' ,'U' ,'V')\nUNION \n\n--Changed (using alter)\nSELECT 'changed' AS ChangeType, o.name /*COLLATE*/, \n       'altered' AS extra_info, 2 AS Priority\nFROM sysobjects o INNER JOIN #tmp t ON o.id = t.id \nWHERE (\n   o.base_schema_ver &lt;&gt; t.base_schema_ver\nOR o.schema_ver      &lt;&gt; t.schema_ver\n)\nAND  o.type IN ('TR', 'P' ,'U' ,'V')\nAND  o.name NOT IN ( SELECT oi.name \n         FROM sysobjects oi INNER JOIN #tmp ti ON oi.id = ti.id\n         WHERE oi.name &lt;&gt; ti.name /*COLLATE*/\n         AND oi.type IN ('TR', 'P' ,'U' ,'V')) \nUNION\n\n--Changed (actually dropped and recreated [but not renamed])\nSELECT 'changed' AS ChangeType, t.name, 'dropped' AS extra_info, 2 AS Priority\nFROM #tmp t\nWHERE    t.name IN ( SELECT ti.name /*COLLATE*/ FROM #tmp ti\n         WHERE NOT EXISTS (SELECT * FROM sysobjects oi\n                           WHERE oi.id = ti.id))\nAND  t.name IN ( SELECT oi.name /*COLLATE*/ FROM sysobjects oi\n         WHERE NOT EXISTS (SELECT * FROM #tmp ti\n                           WHERE oi.id = ti.id)\n         AND   oi.type  IN ('TR', 'P' ,'U' ,'V'))\nUNION\n\n--Deleted\nSELECT 'deleted' AS ChangeType, t.name, '' AS extra_info, 0 AS Priority\nFROM #tmp t\nWHERE NOT EXISTS (SELECT * FROM sysobjects o\n                  WHERE o.id = t.id)\nAND t.name NOT IN (  SELECT oi.name /*COLLATE*/ FROM sysobjects oi\n         WHERE NOT EXISTS (SELECT * FROM #tmp ti\n                           WHERE oi.id = ti.id)\n         AND   oi.type  IN ('TR', 'P' ,'U' ,'V'))\nUNION\n\n--Added\nSELECT 'added' AS ChangeType, o.name /*COLLATE*/, '' AS extra_info, 4 AS Priority\nFROM sysobjects o\nWHERE NOT EXISTS (SELECT * FROM #tmp t\n                  WHERE o.id = t.id)\nAND      o.type  IN ('TR', 'P' ,'U' ,'V')\nAND  o.name NOT IN ( SELECT ti.name /*COLLATE*/ FROM #tmp ti\n         WHERE NOT EXISTS (SELECT * FROM sysobjects oi\n                           WHERE oi.id = ti.id))\nORDER BY Priority ASC\n</code></pre>\n\n<p><strong>Note:</strong> If you use a non-standard collation in any of your databases, you will need to replace <code>/* COLLATE */</code> with your database collation. i.e. <code>COLLATE Latin1_General_CI_AI</code></p>\n"}, {'answer_id': 187617, 'author': 'Christopher Klein', 'author_id': 17632, 'author_profile': 'https://Stackoverflow.com/users/17632', 'pm_score': 3, 'selected': False, 'text': '<p>We needed to version our SQL database after we migrated to an x64 platform and our old version broke with the migration.  We wrote a C# application which used SQLDMO to map out all of the SQL objects to a folder:</p>\n<pre>\n                Root\n                    ServerName\n                       DatabaseName\n                          Schema Objects\n                             Database Triggers*\n                                .ddltrigger.sql\n                             Functions\n                                ..function.sql\n                             Security\n                                Roles\n                                   Application Roles\n                                      .approle.sql\n                                   Database Roles\n                                      .role.sql\n                                Schemas*\n                                   .schema.sql\n                                Users\n                                   .user.sql\n                             Storage\n                                Full Text Catalogs*\n                                   .fulltext.sql\n                             Stored Procedures\n                                ..proc.sql\n                             Synonyms*\n                                .synonym.sql\n                             Tables\n                                ..table.sql\n                                Constraints\n                                   ...chkconst.sql\n                                   ...defconst.sql\n                                Indexes\n                                   ...index.sql\n                                Keys\n                                   ...fkey.sql\n                                   ...pkey.sql\n                                   ...ukey.sql\n                                Triggers\n                                   ...trigger.sql\n                             Types\n                                User-defined Data Types\n                                   ..uddt.sql\n                                XML Schema Collections*\n                                   ..xmlschema.sql\n                             Views\n                                ..view.sql\n                                Indexes\n                                   ...index.sql\n                                Triggers\n                                   ...trigger.sql\n</pre>\n<p>The application would then compare the newly written version with the version stored in SVN, and if there were differences it would update SVN.\nWe determined that running the process once a night was sufficient since we did not make that many changes to SQL. It allows us to track changes to all the objects we care about plus it allows us to rebuild our full schema in the event of a serious problem.</p>\n'}, {'answer_id': 204180, 'author': 'alexis.kennedy', 'author_id': 6725, 'author_profile': 'https://Stackoverflow.com/users/6725', 'pm_score': 4, 'selected': False, 'text': "<p>+1 for everyone who's recommended the RedGate tools, with an additional recommendation and a caveat.</p>\n\n<p>SqlCompare also has a decently documented API: so you can, for instance, write a console app which syncs your source controlled scripts folder with a CI integration testing database on checkin, so that when someone checks in a change to the schema from their scripts folder it's automatically deployed along with the matching application code change. This helps close the gap with developers who are forgetful about propagating changes in their local db up to a shared development DB (about half of us, I think :) ).</p>\n\n<p>A caveat is that with a scripted solution or otherwise, the RedGate tools are sufficiently smooth that it's easy to forget about SQL realities underlying the abstraction. If you rename all the columns in a table, SqlCompare has no way to map the old columns to the new columns and will drop all the data in the table. It will generate warnings but I've seen people click past that. There's a general point here worth making, I think, that you can only automate DB versioning and upgrade so far - the abstractions are very leaky.</p>\n"}, {'answer_id': 870412, 'author': 'Remus Rusanu', 'author_id': 105929, 'author_profile': 'https://Stackoverflow.com/users/105929', 'pm_score': 3, 'selected': False, 'text': '<p>I\'m also using a version in the database stored via the database extended properties family of procedures. My application has scripts for each version step (ie. move from 1.1 to 1.2). When deployed, it looks at the current version and then runs the scripts one by one until it reaches the last app version. There is no script that has the straight \'final\' version, even deploy on a clean DB does the deploy via a series of upgrade steps.</p>\n\n<p>Now what I like to add is that I\'ve seen two days ago a presentation on the MS campus about the new and upcoming VS DB edition. The presentation was focused specifically on this topic and I was blown out of the water. You should definitely check it out, the new facilities are focused on keeping schema definition in T-SQL scripts (CREATEs), a runtime delta engine to compare deployment schema with defined schema and doing the delta ALTERs and integration with source code integration, up to and including MSBUILD continuous integration for automated build drops. The drop will contain a new file type, the .dbschema files, that can be taken to the deployment site and a command line tool can do the actual \'deltas\' and run the deployment.\nI have a blog entry on this topic with links to the VSDE downloads, you should check them out: <a href="http://rusanu.com/2009/05/15/version-control-and-your-database/" rel="noreferrer">http://rusanu.com/2009/05/15/version-control-and-your-database/</a></p>\n'}, {'answer_id': 872240, 'author': 'dariol', 'author_id': 3644960, 'author_profile': 'https://Stackoverflow.com/users/3644960', 'pm_score': 3, 'selected': False, 'text': "<p>It's simple.</p>\n\n<ol>\n<li><p>When the base project is ready then you must create full database script. This script is commited to SVN. It is first version.</p></li>\n<li><p>After that all developers creates change scripts (ALTER..., new tables, sprocs, etc).</p></li>\n<li><p>When you need current version then you should execute all new change scripts.</p></li>\n<li><p>When app is released to production then you go back to 1 (but then it will be successive version of course).</p></li>\n</ol>\n\n<p>Nant will help you to execute those change scripts. :)</p>\n\n<p>And remember. Everything works fine when there is discipline. Every time when database change is commited then corresponding functions in code are commited too.</p>\n"}, {'answer_id': 1092187, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Every database should be under source-code control.  What is lacking is a tool to automatically script all database objects - and "configuration data" - to file, which then can be added to any source control system.  If you are using SQL Server, then my solution is here : <a href="http://dbsourcetools.codeplex.com/" rel="noreferrer">http://dbsourcetools.codeplex.com/</a> .  Have fun.\n- Nathan.</p>\n'}, {'answer_id': 1238100, 'author': 'Liron Levi', 'author_id': 145606, 'author_profile': 'https://Stackoverflow.com/users/145606', 'pm_score': 2, 'selected': False, 'text': '<p>In my experience the solution is twofold:</p>\n\n<ol>\n<li><p>You need to handle changes to the development database that are done by multiple developers during development.</p></li>\n<li><p>You need to handle database upgrades in customers sites.</p></li>\n</ol>\n\n<p>In order to handle #1 you\'ll need a strong database diff/merge tool. The best tool should be able to perform automatic merge as much as possible while allowing you to resolve unhandled conflicts manually. </p>\n\n<p>The perfect tool should handle merge operations by using a 3-way merge algorithm that brings into account the changes that were made in the THEIRS database and the MINE database, relative to the BASE database.</p>\n\n<p>I wrote a commercial tool that provides manual merge support for SQLite databases and I\'m currently adding support for 3-way merge algorithm for SQLite. Check it out at <a href="http://www.sqlitecompare.com" rel="nofollow noreferrer">http://www.sqlitecompare.com</a></p>\n\n<p>In order to handle #2 you will need an upgrade framework in place. </p>\n\n<p>The basic idea is to develop an automatic upgrade framework that knows how to upgrade from an existing SQL schema to the newer SQL schema and can build an upgrade path for every existing DB installation. </p>\n\n<p>Check out my article on the subject in <a href="http://www.codeproject.com/KB/database/sqlite_upgrade.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/database/sqlite_upgrade.aspx</a> to get a general idea of what I\'m talking about. </p>\n\n<p>Good Luck</p>\n\n<p>Liron Levi</p>\n'}, {'answer_id': 1664083, 'author': 'Kuberchaun', 'author_id': 102388, 'author_profile': 'https://Stackoverflow.com/users/102388', 'pm_score': 2, 'selected': False, 'text': '<p>Check out DBGhost <a href="http://www.innovartis.co.uk/" rel="nofollow noreferrer">http://www.innovartis.co.uk/</a>. I have used in an automated fashion for 2 years now and it works great. It allows our DB builds to happen much like a Java or C build happens, except for the database. You know what I mean.</p>\n'}, {'answer_id': 3156406, 'author': 'David Atkinson', 'author_id': 167364, 'author_profile': 'https://Stackoverflow.com/users/167364', 'pm_score': 5, 'selected': False, 'text': '<p>Here at Red Gate we offer a tool, <a href="http://www.red-gate.com/products/SQL_Source_Control/index.htm" rel="nofollow noreferrer">SQL Source Control</a>, which uses SQL Compare technology to link your database with a TFS or SVN repository. This tool integrates into SSMS and lets you work as you would normally, except it now lets you commit the objects.</p>\n\n<p>For a migrations-based approach (more suited for automated deployments), we offer <a href="http://www.red-gate.com/products/sql-development/readyroll/" rel="nofollow noreferrer">SQL Change Automation</a> (formerly called ReadyRoll), which creates and manages a set of incremental scripts as a Visual Studio project.</p>\n\n<p>In SQL Source Control it is possible to specify static data tables. These are stored in source control as INSERT statements.</p>\n\n<p>If you\'re talking about test data, we\'d recommend that you either generate test data with a tool or via a post-deployment script you define, or you simply restore a production backup to the dev environment.</p>\n'}, {'answer_id': 3775063, 'author': 'ScaleOvenStove', 'author_id': 12268, 'author_profile': 'https://Stackoverflow.com/users/12268', 'pm_score': 3, 'selected': False, 'text': '<p>I wrote this app a while ago, <a href="http://sqlschemasourcectrl.codeplex.com/" rel="noreferrer">http://sqlschemasourcectrl.codeplex.com/</a> which will scan your MSFT SQL db\'s as often as you want and automatically dump your objects (tables, views, procs, functions, sql settings) into SVN. Works like a charm. I use it with Unfuddle (which allows me to get alerts on checkins)</p>\n'}, {'answer_id': 5108862, 'author': 'Rolf Wessels', 'author_id': 327825, 'author_profile': 'https://Stackoverflow.com/users/327825', 'pm_score': 3, 'selected': False, 'text': '<p>I agree with ESV answer and for that exact reason I started a little project a while back to help maintain database updates in a very simple file which could then be maintained a long side out source code. It allows easy updates to developers as well as UAT and Production. The tool works on SQL Server and MySQL.</p>\n<p>Some project features:</p>\n<ul>\n<li>Allows schema changes</li>\n<li>Allows value tree population</li>\n<li>Allows separate test data inserts for eg. UAT</li>\n<li>Allows option for rollback (not automated)</li>\n<li>Maintains support for SQL server and MySQL</li>\n<li>Has the ability to import your existing database into version control with one simple command (SQL server only ... still working on MySQL)</li>\n</ul>\n<p>Please check out the <a href="http://code.google.com/p/databaseversioncontrol/" rel="nofollow noreferrer">code</a> for some more information.</p>\n'}, {'answer_id': 5122171, 'author': 'roman m', 'author_id': 3661, 'author_profile': 'https://Stackoverflow.com/users/3661', 'pm_score': 4, 'selected': False, 'text': "<p>With VS 2010, use the Database project.</p>\n\n<ol>\n<li>Script out your database </li>\n<li>Make changes to scripts or directly on\nyour db server </li>\n<li>Sync up using Data >\n    Schema Compare</li>\n</ol>\n\n<p>Makes a perfect DB versioning solution, and makes syncing DB's a breeze. </p>\n"}, {'answer_id': 31001490, 'author': 'Srivathsa Harish Venkataramana', 'author_id': 1301703, 'author_profile': 'https://Stackoverflow.com/users/1301703', 'pm_score': 3, 'selected': False, 'text': "<p>It's a very old question, however, many people are trying to solve this even now. All they have to do is to research about Visual Studio Database Projects. Without this, any database development looks very feeble. From code organization to deployment to versioning, it simplifies everything.</p>\n"}, {'answer_id': 31024342, 'author': 'McRobert', 'author_id': 4870511, 'author_profile': 'https://Stackoverflow.com/users/4870511', 'pm_score': 5, 'selected': False, 'text': '<p>First, you must choose the version control system that is right for you: </p>\n\n<ul>\n<li><p>Centralized Version Control system - a standard system where users check out/check in before/after they work on files, and the files are being kept in a single central server</p></li>\n<li><p>Distributed Version Control system - a system where the repository is being cloned, and each clone is actually the full backup of the repository, so if any server crashes, then any cloned repository can be used to restore it\nAfter choosing the right system for your needs, you\'ll need to setup the repository which is the core of every version control system\nAll this is explained in the following article: <a href="http://solutioncenter.apexsql.com/sql-server-source-control-part-i-understanding-source-control-basics/" rel="noreferrer">http://solutioncenter.apexsql.com/sql-server-source-control-part-i-understanding-source-control-basics/</a></p></li>\n</ul>\n\n<p>After setting up a repository, and in case of a central version control system a working folder, you can read <a href="http://solutioncenter.apexsql.com/sql-server-source-control-part-ii-integration/" rel="noreferrer" title="this article">this article</a>. It shows how to setup source control in a development environment using: </p>\n\n<ul>\n<li><p>SQL Server Management Studio via the MSSCCI provider, </p></li>\n<li><p>Visual Studio and SQL Server Data Tools</p></li>\n<li>A 3rd party tool ApexSQL Source Control</li>\n</ul>\n'}, {'answer_id': 41573374, 'author': 'Endi Zhupani', 'author_id': 4464567, 'author_profile': 'https://Stackoverflow.com/users/4464567', 'pm_score': 2, 'selected': False, 'text': '<p>I would suggest using comparison tools to improvise a version control system for your database. Two good alternatives are <a href="http://www.xsql.com/products/sql_server_schema_compare/?utm_source=pragmatic&amp;utm_medium=articles&amp;utm_campaign=xsql" rel="nofollow noreferrer">xSQL Schema Compare</a> and <a href="http://www.xsql.com/products/sql_server_data_compare/?utm_source=pragmatic&amp;utm_medium=articles&amp;utm_campaign=xsql" rel="nofollow noreferrer">xSQL Data Compare</a>.</p>\n<p>Now, if your goal is to have only the database\'s schema under version control you can simply use xSQL Schema Compare to generate xSQL Snapshots of the schema and add these files in your version control. Then, to revert or update to a specific version, just compare the current version of the database with the snapshot for the destination version.</p>\n<p>Also, if you want to have the data under version control as well, you can use xSQL Data Compare to generate change scripts for you database and add the .sql files in your version control. You could then execute these scripts to revert / update to any version you want. Keep in mind that for the \'revert\' functionality you need to generate change scripts that, when executed, will make Version 3 the same as Version 2 and for the \'update\' functionality, you need to generate change scripts that do the opposite.</p>\n<p>Lastly, with some basic batch programming skills you can automate the whole process by using the command line versions of xSQL Schema Compare and xSQL Data Compare</p>\n<p>Disclaimer: I\'m affiliated to xSQL.</p>\n'}, {'answer_id': 74309858, 'author': 'Zach Musgrave', 'author_id': 1733179, 'author_profile': 'https://Stackoverflow.com/users/1733179', 'pm_score': 0, 'selected': False, 'text': '<p>An alternative to version controlling your database is to use a version-controlled database, of which there are now several.</p>\n<p><a href="https://www.dolthub.com/blog/2021-09-17-database-version-control/" rel="nofollow noreferrer">https://www.dolthub.com/blog/2021-09-17-database-version-control/</a></p>\n<p>These products don\'t apply version control on top of another type of database -- they are their own database engines that support version control operations. So you need to migrate to them or start building on them in the first place.</p>\n<p>I write one of them, DoltDB, which combines the interfaces of MySQL and Git. Check it out here:</p>\n<p><a href="https://github.com/dolthub/dolt" rel="nofollow noreferrer">https://github.com/dolthub/dolt</a></p>\n'}]
['https://Stackoverflow.com/questions/173', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/83/']