SQL Server数据库架构版本控制和更新

问题描述:

对于我的应用程序,我必须支持更新方案,并且数据库可能会受到影响。

For my application I have to support update scenarios and the database might be affected.

我希望能够从旧版本更新到最新版本而无需安装中间版本。例如。假设我有A版本(最旧),B版本(中级)和C版本(新版本)。我希望能够将版本A直接更新为版本C。对于应用程序文件来说,这很简单,我只是用新文件替换了旧文件。但是,对于数据库,我不希望生成SQL脚本来将数据库模式从A直接更改为C,而是希望首先应用脚本将模式从A更改为B,然后从B更改为C。

I want to be able to update from an old version to the newest without installing intermediate versions. E.g. Suppose I have version A (the oldest), B (intermediate) and C (new version). I want to be able to update version A straight to version C. For the application files this is simple, I just replace the old with the new ones. However for the database I do not wish to generate a SQL Script to change the database schema from A straight to C, instead I want first apply a script to change the schema from A to B and from B to C.

如何存储SQL Server数据库的数据库版本?有什么我可以设置的特殊属性,而不是实现版本表?在我的代码(.NET)中,我想读取数据库版本,并据此以正确的顺序执行更新SQL脚本。

How can I store the database version for a SQL Server database? Is there any special property which I can set, instead of implementing a version table? In my code (.NET) I want to read the database version and accordingly to execute the update SQL scripts in the proper order.

我将同时使用SQL Server 2005和SQL Server 2008。

I will use both SQL Server 2005 and SQL Server 2008.

我使用数据库扩展属性,请参见版本控制和您的数据库

I use database extended properties, see Version Control and your Database:

SELECT [value] 
    from ::fn_listextendedproperty (
        'MyApplication DB Version', 
        default, default, default, default, default, default);

...

EXEC sp_updateextendedproperty 
    @name = N'MyApplication DB Version', @value = '1.2';
GO