本文翻译自:Versioning SQL Server database

I want to get my databases under version control. 我想让我的数据库受版本控制。 Does anyone have any advice or recommended articles to get me started? 有没有人有任何建议或推荐的文章让我开始?

I'll always want to have at least some data in there (as alumb mentions: user types and administrators). 我总是希望在那里至少有一些数据(如alumb提到的:用户类型和管理员)。 I'll also often want a large collection of generated test data for performance measurements. 我还经常需要大量生成的测试数据来进行性能测量。


#1楼

参考:https://stackoom.com/question/2n/版本化SQL-Server数据库


#2楼

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 : http://dbsourcetools.codeplex.com/ . 如果您使用的是SQL Server,那么我的解决方案就在这里: http : //dbsourcetools.codeplex.com/ 。 Have fun. 玩得开心。 - Nathan. - 内森


#3楼

In my experience the solution is twofold: 根据我的经验,解决方案有两个方面:

  1. You need to handle changes to the development database that are done by multiple developers during development. 您需要处理开发期间由多个开发人员完成的开发数据库更改。

  2. You need to handle database upgrades in customers sites. 您需要在客户站点中处理数据库升级。

In order to handle #1 you'll need a strong database diff/merge tool. 为了处理#1,您需要一个强大的数据库差异/合并工具。 The best tool should be able to perform automatic merge as much as possible while allowing you to resolve unhandled conflicts manually. 最好的工具应该能够尽可能多地执行自动合并,同时允许您手动解决未处理的冲突。

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. 完美的工具应该通过使用3向合并算法来处理合并操作,该算法考虑了相对于BASE数据库在THEIRS数据库和MINE数据库中所做的更改。

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. 我编写了一个商业工具,为SQLite数据库提供手动合并支持,我目前正在为SQLite添加对3向合并算法的支持。 Check it out at http://www.sqlitecompare.com 请访问http://www.sqlitecompare.com查看

In order to handle #2 you will need an upgrade framework in place. 为了处理#2,您需要一个升级框架。

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. 基本思想是开发一个自动升级框架,该框架知道如何从现有SQL模式升级到较新的SQL模式,并可以为每个现有数据库安装构建升级路径。

Check out my article on the subject in http://www.codeproject.com/KB/database/sqlite_upgrade.aspx to get a general idea of what I'm talking about. 在http://www.codeproject.com/KB/database/sqlite_upgrade.aspx上查看我关于这个主题的文章,以大致了解我在说什么。

Good Luck 祝好运

Liron Levi Liron Levi


#4楼

Because our app has to work across multiple RDBMSs, we store our schema definition in version control using the database-neutral Torque format (XML). 因为我们的应用程序必须跨多个RDBMS工作,所以我们使用数据库中立的Torque格式(XML)将我们的模式定义存储在版本控制中。 We also version-control the reference data for our database in XML format as follows (where "Relationship" is one of the reference tables): 我们还以XML格式对数据库的参考数据进行版本控制,如下所示(其中“Relationship”是参考表之一):

  <Relationship RelationshipID="1" InternalName="Manager"/><Relationship RelationshipID="2" InternalName="Delegate"/>etc.

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. 然后,我们使用自行开发的工具生成从数据库的X版本到版本X + 1所需的架构升级和参考数据升级脚本。


#5楼

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. 处理脚本应该是自动化的,这样您就不必进行手动操作。

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. 这样,开发人员可以独立于其他开发人员创建测试用例和开发阶段。

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. 自动化工具应该具有处理数据库元数据的方法,该方法告诉哪些数据库处于什么开发状态以及哪些表包含版本可控数据等等。


#6楼

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. 要使转储到更快一点的源代码控制系统,您可以使用sysobjects中的版本信息查看自上次以来哪些对象已更改。

Setup: 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. 如果要重新扫描整个数据结构,请清除此表。

IF ISNULL(OBJECT_ID('last_run_sysversions'), 0) <> 0 DROP TABLE last_run_sysversions
CREATE TABLE last_run_sysversions (name varchar(128), id int, base_schema_ver int,schema_ver int,type char(2)
)

Normal running mode: 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. 正常运行模式:您可以从此sql获取结果,并为您感兴趣的那些生成sql脚本,并将它们放入您选择的源代码控制中。

IF ISNULL(OBJECT_ID('tempdb.dbo.#tmp'), 0) <> 0 DROP TABLE #tmp
CREATE TABLE #tmp (name varchar(128), id int, base_schema_ver int,schema_ver int,type char(2)
)SET NOCOUNT ON-- Insert the values from the end of the last run into #tmp
INSERT #tmp (name, id, base_schema_ver, schema_ver, type)
SELECT name, id, base_schema_ver, schema_ver, type FROM last_run_sysversionsDELETE last_run_sysversions
INSERT last_run_sysversions (name, id, base_schema_ver, schema_ver, type)
SELECT name, id, base_schema_ver, schema_ver, type FROM sysobjects-- This next bit lists all differences to scripts.
SET NOCOUNT OFF--Renamed.
SELECT 'renamed' AS ChangeType, t.name, o.name AS extra_info, 1 AS Priority
FROM sysobjects o INNER JOIN #tmp t ON o.id = t.id
WHERE o.name <> t.name /*COLLATE*/
AND o.type IN ('TR', 'P' ,'U' ,'V')
UNION --Changed (using alter)
SELECT 'changed' AS ChangeType, o.name /*COLLATE*/, 'altered' AS extra_info, 2 AS Priority
FROM sysobjects o INNER JOIN #tmp t ON o.id = t.id
WHERE (o.base_schema_ver <> t.base_schema_ver
OR o.schema_ver      <> t.schema_ver
)
AND  o.type IN ('TR', 'P' ,'U' ,'V')
AND  o.name NOT IN ( SELECT oi.name FROM sysobjects oi INNER JOIN #tmp ti ON oi.id = ti.idWHERE oi.name <> ti.name /*COLLATE*/AND oi.type IN ('TR', 'P' ,'U' ,'V'))
UNION--Changed (actually dropped and recreated [but not renamed])
SELECT 'changed' AS ChangeType, t.name, 'dropped' AS extra_info, 2 AS Priority
FROM #tmp t
WHERE    t.name IN ( SELECT ti.name /*COLLATE*/ FROM #tmp tiWHERE NOT EXISTS (SELECT * FROM sysobjects oiWHERE oi.id = ti.id))
AND  t.name IN ( SELECT oi.name /*COLLATE*/ FROM sysobjects oiWHERE NOT EXISTS (SELECT * FROM #tmp tiWHERE oi.id = ti.id)AND   oi.type  IN ('TR', 'P' ,'U' ,'V'))
UNION--Deleted
SELECT 'deleted' AS ChangeType, t.name, '' AS extra_info, 0 AS Priority
FROM #tmp t
WHERE NOT EXISTS (SELECT * FROM sysobjects oWHERE o.id = t.id)
AND t.name NOT IN (  SELECT oi.name /*COLLATE*/ FROM sysobjects oiWHERE NOT EXISTS (SELECT * FROM #tmp tiWHERE oi.id = ti.id)AND   oi.type  IN ('TR', 'P' ,'U' ,'V'))
UNION--Added
SELECT 'added' AS ChangeType, o.name /*COLLATE*/, '' AS extra_info, 4 AS Priority
FROM sysobjects o
WHERE NOT EXISTS (SELECT * FROM #tmp tWHERE o.id = t.id)
AND      o.type  IN ('TR', 'P' ,'U' ,'V')
AND  o.name NOT IN ( SELECT ti.name /*COLLATE*/ FROM #tmp tiWHERE NOT EXISTS (SELECT * FROM sysobjects oiWHERE oi.id = ti.id))
ORDER BY Priority ASC

Note: If you use a non-standard collation in any of your databases, you will need to replace /* COLLATE */ with your database collation. 注意:如果在任何数据库中使用非标准排序规则,则需要将/* COLLATE */替换为数据库排序规则。 ie COLLATE Latin1_General_CI_AI COLLATE Latin1_General_CI_AI

版本化SQL Server数据库相关推荐

  1. Django连接使用SQL Server数据库(windows版)

    2019独角兽企业重金招聘Python工程师标准>>> 前言: 众所周知,Django 默认支持sqlite,mysql,oracle,postgresql数据库,不支持SQL Se ...

  2. Java连接sql server数据库实现简单版人力资源系统

    首先展示运行界面及功能(java.数据库代码在后头): 这篇文章中红色字体所代表的的是此人力资源系统的使用顺序. 主界面,选择身份. 先选择进入薪酬专员界面,因为要先定义薪酬标准,为后续人事专员录入员 ...

  3. 《转》VMware vSphere 5.1 学习系列之四:安装 SQL Server 数据库

    为什么80%的码农都做不了架构师?>>>    目 录 一.    vCenter Server数据库的配置要求    1 准备 vCenter Server 数据库    1 vC ...

  4. SQL Server数据库镜像部署 错误1418’处理及证书验证

    SQL Server数据库镜像部署 '数据库镜像'是SQLServer数据库功能最强的一种热备份方法,也是环境要求最高的一种.其配置环节比较麻烦,本人新手研究了三天,中途遇到了许多问题,希望其他第一次 ...

  5. Serverless 解惑——函数计算如何访问 SQL Server 数据库

    函数计算(Function Compute):函数计算 是事件驱动的全托管计算服务.使用函数计算,您无需采购与管理服务器等基础设施,只需编写并上传代码.函数计算为您准备好计算资源,弹性地可靠地运行任务 ...

  6. linux python连接oracle数据库_Linux下通过python访问MySQL、Oracle、SQL Server数据库的方法...

    本文档主要描述了Linux下python数据库驱动的安装和配置,用来实现在Linux平台下通过python访问MySQL.Oracle.SQL Server数据库. 其中包括以下几个软件的安装及配置: ...

  7. SQL Server 数据库构架

    Microsoft® SQL Server™ 2000 数据存储在数据库中.在数据库中,数据被组织到用户可以看见的逻辑组件中.数据库还可以按物理方式,在磁盘上作为两个或更多的文件实现. 使用数据库时使 ...

  8. sql server数据库的部署

    http://xiaorenwutest.blog.51cto.com               SQL Server数据库部署   概述:数据库在企业中现在是必不可少的存储工具,用来会员登录,网站 ...

  9. SQL Server数据库技术大全——08讲 PD的使用

    SQL Server数据库技术大全--08讲   PD的使用 讲解了使用PowerDesigner进行数据库建模,包括如何建立概念模型.如何通过概念模型生成物理模型以及如何通过物理模型生成数据库脚本的 ...

最新文章

  1. “智源论坛Live”报名 | 清华大学高天宇:实体关系抽取的现状和未来
  2. HDU - 6635 Nonsense Time (暴力LIS)
  3. 解析URI与URL之间的区别与联系
  4. python外卷(10)--取整
  5. MySQL数据库基础(mysql数据类型、数据表的操作)
  6. java面向对象跑马游戏_面向“对象”和“过程”
  7. PHP的学习--可变函数
  8. 东芝正式退出笔记本电脑业务!
  9. Blob URL 是什么?
  10. 解析docker中的环境变量使用和常见问题解决
  11. 【其他】使win7尽量少占用C盘空间
  12. 7大浏览器颜值代表,谁才是真正的浏览器颜值之王呢?
  13. 单元格下拉全选快捷键_excel下拉全选快捷键是什么
  14. tplink怎样设置虚拟服务器,tplink怎么设置虚拟服务器
  15. threejs使用tweenjs实现点击标签过渡到相应视角
  16. VirtualBox安装Ubuntu20.04 + 安装增强功能
  17. 查看oracle执行计划方法( 一)
  18. TabLayout的使用和自定义红点消息提示
  19. 大数据常见函数及案例实战
  20. 银屑病推荐益生菌摄入(持续更新中)

热门文章

  1. 继开源之后 红帽打算把它当成新增长点
  2. docker命令易错点整理
  3. CentOS 6.3 samba安装及配置
  4. form中的get和post方法
  5. springboot+dubbo
  6. svn 设置文件可执行权限
  7. EF Code First建库 增删改查
  8. 解决eclipse启动停在一个空白窗口的问题
  9. Python办公自动化(三)|批量合并PDF
  10. ELK-Metricbeat安装及使用