SQL Server Database schema versioning and update

做~自己de王妃 提交于 2019-12-04 14:33:41

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
Murph

Stick a version table in, its simple, its effective, and for the past, erm, well its more than 10 years it has worked a treat for me.

I wrote this up in response to another question here

This depends on your version of SQL Server you're using.

I don't believe a database version is a built in property of a database, however you can probably use an extended property.

Personally, I'd create my own version table, as this will allow you to associate more metadata with it.

You can add a table which registers current version. Then run all upgrade scripts but scripts should be written in such way that they do not execute if current version is higher than version expected by the script.

In that way, it is irrelevant what is the current version of the database schema. Scripts will make only changes that were not already made to the schema.

Here you can find some stored procedures that significantly reduce effort writing upgrade scripts: How to Maintain SQL Server Database Schema Version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!