简体   繁体   English

如何在 Visual Studio 2019 中将表和数据导入 SQL Server 数据库项目

[英]How to import Table and Data to SQL Server Database Project in Visual Studio 2019

So, I have a solution file which consists of a ASP.Net MVC Application and a SQL Server Database Project.所以,我有一个解决方案文件,它由一个 ASP.Net MVC 应用程序和一个 SQL Server 数据库项目组成。 Both are checked in to TFS.两者都已签入到 TFS。 I know how to import the database, table, views, functions and stored procedures, but I want to the tables to have data as well.我知道如何导入数据库、表、视图、函数和存储过程,但我希望表也有数据。 How can I import the table with data?如何导入包含数据的表?

You can define scripts to run as part of a sqlproj that will insert data into tables.您可以定义脚本作为将数据插入表的 sqlproj 的一部分运行。 I've seen it used for inserting basic configuration data.我见过它用于插入基本配置数据。

In the Solution Explorer, right click your project and go to Add, then Script.在解决方案资源管理器中,右键单击您的项目并转到添加,然后转到脚本。 Choose a Post Deployment Script or a Pre Deployment Script.选择部署后脚本或部署前脚本。 Doing so will add a .sql file to your project, and set the build action appropriately so that it will either run before or after your schema has been created.这样做会将 .sql 文件添加到您的项目,并适当地设置构建操作,以便它可以在创建架构之前或之后运行。 In this case since you want to add data, you need a Post Deployment Script.在这种情况下,由于您要添加数据,因此需要一个部署后脚本。 If you need to control the order in which data is added, you can add it all in the same file, or just add a single post deployment script and have it invoke other .sql files.如果您需要控制添加数据的顺序,您可以将其全部添加到同一个文件中,或者只添加一个部署后脚本并让它调用其他 .sql 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将数据导入Visual Studio 2012 Sql Server数据库项目 - How to import data into Visual Studio 2012 Sql Server Database Project Visual Studio 2019 中的 SQL Server 数据库项目功能 - SQL Server database project functionality In Visual Studio 2019 如何在Visual Studio(C#)中将ASP.NET项目与SQL Server数据库表连接 - How to connect ASP.NET project with SQL Server database table in Visual Studio (C#) 无法使用服务器资源管理器在 SQL Server 2019 和 Visual Studio 2019 之间添加数据连接 - Unable to add data connection between SQL Server 2019 and Visual Studio 2019 with Server Explorer Visual Studio 2019 缺少 SQL 服务器 - Visual Studio 2019 missing SQL Server SSIS Visual Studio 2019 用于 SQL 服务器 2008 - SSIS Visual Studio 2019 for SQL Server 2008 从 Visual Studio 2013 数据库项目中清理 SQL Server 数据库 - Clean SQL Server database from Visual Studio 2013 database project 使用 SQL Server 2019/Visual Studio 2019 创建 SSIS package - Create SSIS package with SQL Server 2019/Visual Studio 2019 如何在 SQL 服务器项目的 Visual Studio 中使用动态 SQL 中的数据库变量名称? - How to use a Database Variable Name in dynamic SQL with visual studio for a SQL Server Project? 尝试将sql数据导入Visual Studio Web表单数据库 - Trying to import sql data into visual studio web form database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM