如何版本控制SQL Server数据库? [英] How to version control SQL Server databases?

查看:185
本文介绍了如何版本控制SQL Server数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有SQL Server数据库,并在其中进行更改。一些数据库表具有记录,这些记录是我的应用程序需要运行的启动记录。我想对数据库和这些记录(行)进行版本控制。有可能做到这一点,并捆绑到SVN版本控制我有我的源代码或有其他解决方案吗?我想实现这一点,以便能够返回到以前版本的数据库和比较数据库修订之间的更改。如果工具是免费的,开源的或不是很昂贵,这将是很好的。

I have SQL Server databases and do changes in them. Some database tables have records that are starting records required my app to run. I would like to do version control over database and these records (rows). Is it possible to do this and bundle it to SVN version control I have for my source code or are there other solutions to this? I would like to accomplish this to be able to return to previous version of database and compare changes between database revisions. It would be nice if tools for this are free, open source or not very expensive.

我的环境是Visual C#Express,SQL Server 2008 Express和Tortoise SVN。 p>

My environment is Visual C# Express, SQL Server 2008 Express and Tortoise SVN.

推荐答案

我们刚刚开始对我们的一些项目进行以下操作,似乎运行得很好,表。

We've just started doing the following on some of our projects, and it seems to work quite well, for populating "static" tables.

我们的脚本遵循一个构造临时表的模式,然后填充我们想要的真实表相似的模式。我们只在这里放置人类可读的值(即我们不包括IDENTITY / GUID列)。脚本的其余部分使用临时表,并执行适当的INSERT / UPDATE / DELETE语句,使真实表类似于临时表。当我们必须更改这个静态数据时,我们必须更新的是临时表的总体。这意味着版本之间的DIFFing可以正常工作,而回滚脚本就像从源代码控制中获取以前的版本一样简单。

Our scripts follow a pattern where a temp table is constructed, and is then populated with what we want the real table to resemble. We only put human readable values here (i.e. we don't include IDENTITY/GUID columns). The remainder of the script takes the temp table and performs appropriate INSERT/UPDATE/DELETE statements to make the real table resemble the temp table. When we have to change this "static" data, all we have to update is the population of the temp table. This means that DIFFing between versions works as expected, and rollback scripts are as simple as getting a previous version from source control.

INSERT / UPDATE / DELETE只需要写一次。事实上,我们的脚本稍微复杂一点,并且在实际的DML语句之前有两组验证运行。一组验证临时表数据(即,我们不会通过尝试使数据库类似于临时表来违反任何约束)。其他的验证临时表和目标数据库(即外键是可用的)。

The INSERT/UPDATE/DELETEs only have to be written once. In fact, our scripts are slightly more complicated, and have two sets of validation run before the actual DML statements. One set validate the temp table data (i.e. that we're not going to violate any constraints by attempting to make the database resemble the temp table). The other validate the temp table and the target database (i.e. that foreign keys are available).

这篇关于如何版本控制SQL Server数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆