在 Visual Studio 2010 数据库项目中生成种子数据
我在 Visual studio 2010 中有一个数据库和一个数据库项目。我成功推断了数据库项目中的架构,但我还需要以某种方式导入一些表(国家、州、用户类型等)中的数据,这些表是引用表,而不是真正的数据表。
有办法吗?
到目前为止,我发现的唯一方法是在 SQL Server Management Studio 中生成数据脚本,并将该脚本放置在数据库项目的部署后脚本文件中。
有更简单的办法吗?
I have a database and a database project in Visual studio 2010. I inferred the schema in the database project successfully but I also need to import somehow the data in a few tables (Country, State, UserType etc.) that are reference tables and not really data tables.
Is there a way?
The only way I found so far is generating data scripts in SQL Server Management Studio and placing this script in the post-deployment script file in the database project.
Any simpler way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我以前就是这么做的。
我只是确保脚本中的每个语句看起来像这样:
这意味着每次部署数据库时,您的核心参考数据都会被插入或更新(以最合适的为准),并且您可以修改这些脚本以创建新的参考数据对于较新版本的数据库。
您可以使用 T4 模板来生成这些脚本 - 我过去做过类似的事情。
this is pretty much how I've done it before.
I would just make sure that each statement in you script look something like:
This means that each time you deploy the database your core reference data will be inserted or updated, whichever is most appropriate, and you can modify these scripts to create new reference data for newer versions of the database.
You could use a T4 template to generate these scripts - I've done something similar in the past.
尝试使用 SQL Server 的静态数据脚本生成器。它以正确的格式自动为您执行这些部署后脚本。它是一个免费的 Google Code 托管项目,我们发现它对于编写静态数据脚本非常有用(也可以在现有数据之上进行更新)。
Try the Static Data Script Generator for SQL Server. It automates those Post-Deployment scripts for you in the correct format. It is a free Google Code hosted project and we have found it useful for scripting our static data (also over the top of existing data for updates as well).
您还可以使用
Merge INTO
语句将种子数据更新/删除/插入到部署后脚本中的表中。我已经尝试过了,它对我有用,这里是一个简单的示例:you can also use the
Merge INTO
statement for updating/deleting/inserting seed data into the table in your post deployment script.I have tried and its works for me here is the simple example:通过使用 postdeployment.script 并使用新表和种子数据完美执行,下面是脚本,之后我想添加新列并将数据插入其中,如何做到这一点
让我知道上面的脚本每次都会运行使用azure pipeline部署数据库。如何更新数据。
By Using postdeployment.script and its executed perfectly with new table and seed data into it below is the script,after that I want to add new column and insert data into it how i i can do this
Let me know above script will run every time when deploying database by using azure pipeline. how to update data.