在Visual Studio数据库项目/ SQL Server中创建默认数据

时间:2022-04-01 10:08:00

Are there way to using data generation plans in VS 2010's database projects to create a set of default data? Or am I barking up the wrong tree i.e. are data generation plans best suited to create dummy example data?

有没有办法在VS 2010的数据库项目中使用数据生成计划来创建一组默认数据?或者我咆哮错误的树,即最适合创建虚拟示例数据的数据生成计划?

We have a bunch of data (default settings, default users etc etc) that needs to be created for each database deployment. It would be nice to have tooling to help us with this, so it can be source controlled and better managed.

我们有一堆数据(默认设置,默认用户等)需要为每个数据库部署创建。有工具来帮助我们这样做会很好,所以它可以是源代码控制和更好的管理。

I'm guessing that there are probably third party alternatives, but I'm hoping there is a built-in Visual-Studio-Way of doing things, so it can integrate nicely with TFS etc.

我猜测可能有第三方替代方案,但我希望有一个内置的Visual-Studio-Way方式,所以它可以很好地与TFS等集成。

1 个解决方案

#1


5  

There are probably different ways to do this, but the basics are to:

可能有不同的方法,但基本要点是:

  1. create a script that inserts your default data
  2. 创建一个插入默认数据的脚本

  3. Edit the Script.PostDeployment.sql script to use your script for inserting the default values
  4. 编辑Script.PostDeployment.sql脚本以使用您的脚本插入默认值

For example, I created a new folder, DefaultData, under the Scripts->Post-Deployment folder of my project and added my script for inserting the default data here, InsertDefaultData.sql. Then, I added the following line to Script.PostDeployment.sql ":r ..\DefaultData\InsertDefaultData.sql".

例如,我在项目的Scripts-> Post-Deployment文件夹下创建了一个新文件夹DefaultData,并添加了我在此处插入默认数据的脚本InsertDefaultData.sql。然后,我将以下行添加到Script.PostDeployment.sql“:r .. \ DefaultData \ InsertDefaultData.sql”。

#1


5  

There are probably different ways to do this, but the basics are to:

可能有不同的方法,但基本要点是:

  1. create a script that inserts your default data
  2. 创建一个插入默认数据的脚本

  3. Edit the Script.PostDeployment.sql script to use your script for inserting the default values
  4. 编辑Script.PostDeployment.sql脚本以使用您的脚本插入默认值

For example, I created a new folder, DefaultData, under the Scripts->Post-Deployment folder of my project and added my script for inserting the default data here, InsertDefaultData.sql. Then, I added the following line to Script.PostDeployment.sql ":r ..\DefaultData\InsertDefaultData.sql".

例如,我在项目的Scripts-> Post-Deployment文件夹下创建了一个新文件夹DefaultData,并添加了我在此处插入默认数据的脚本InsertDefaultData.sql。然后,我将以下行添加到Script.PostDeployment.sql“:r .. \ DefaultData \ InsertDefaultData.sql”。