How to version control SQL Server databases?

后端 未结 10 1072
醉话见心
醉话见心 2020-12-28 19:04

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 ov

10条回答
  •  甜味超标
    2020-12-28 19:19

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

    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.

    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).

提交回复
热议问题