問題描述
有沒有辦法在VS 2010的數(shù)據(jù)庫項目中使用數(shù)據(jù)生成計劃來創(chuàng)建一組默認數(shù)據(jù)?或者我是在吠錯樹,即數(shù)據(jù)生成計劃最適合創(chuàng)建虛擬示例數(shù)據(jù)嗎?
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?
我們有一堆數(shù)據(jù)(默認設置、默認用戶等)需要為每個數(shù)據(jù)庫部署創(chuàng)建.如果有工具可以幫助我們解決這個問題,那就太好了,這樣就可以進行源代碼控制和更好的管理.
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.
我猜可能有第三方替代品,但我希望有一個內(nèi)置的 Visual-Studio-Way 做事方式,因此它可以與 TFS 等很好地集成.
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.
推薦答案
可能有不同的方法來做到這一點,但基本的是:
There are probably different ways to do this, but the basics are to:
- 創(chuàng)建一個插入默認數(shù)據(jù)的腳本
- 編輯 Script.PostDeployment.sql 腳本以使用您的腳本插入默認值
例如,我在項目的 Scripts->Post-Deployment 文件夾下創(chuàng)建了一個新文件夾 DefaultData,并在此處添加了用于插入默認數(shù)據(jù)的腳本 InsertDefaultData.sql.然后,我將以下行添加到 Script.PostDeployment.sql ":r ..\DefaultData\InsertDefaultData.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".
這篇關(guān)于在 Visual Studio 數(shù)據(jù)庫項目/SQL Server 中創(chuàng)建默認數(shù)據(jù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!