|
| 1 | +--- |
| 2 | +title: Publish SQL Database Projects from Visual Studio Code |
| 3 | +description: Learn how to publish SQL database projects from Visual Studio Code using the Publish dialog. |
| 4 | +author: rwestMSFT |
| 5 | +ms.author: randolphwest |
| 6 | +ms.reviewer: iqrashaikh, drskwier |
| 7 | +ms.date: 02/04/2026 |
| 8 | +ms.service: sql |
| 9 | +ms.subservice: sql-database-projects |
| 10 | +ms.topic: how-to |
| 11 | +ms.collection: |
| 12 | + - data-tools |
| 13 | +--- |
| 14 | +# Publish SQL database projects from Visual Studio Code |
| 15 | + |
| 16 | +Use the SQL Database Projects extension for Visual Studio Code to deploy database schema changes directly from a SQL project. |
| 17 | + |
| 18 | +A SQL project deployment takes the schema you define in the project, compares it to the target database, and applies only the necessary changes to bring the database into the desired state through a dynamically generated plan. |
| 19 | + |
| 20 | +You can review changes, generate a deployment script, and publish updates to a target database without leaving the editor. |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +Before you begin, make sure you have: |
| 25 | + |
| 26 | +- Visual Studio Code installed |
| 27 | +- The MSSQL extension for Visual Studio Code |
| 28 | +- The SQL Database Projects extension |
| 29 | +- An existing SQL database project (`.sqlproj`) |
| 30 | +- Access to a SQL Server or Azure SQL Database target |
| 31 | + |
| 32 | +## Open the Publish dialog |
| 33 | + |
| 34 | +You can open the Publish dialog from the **Database Projects** view. |
| 35 | + |
| 36 | +1. Open the **Database Projects** view. |
| 37 | +1. Right-click your SQL project. |
| 38 | +1. Select **Publish**. |
| 39 | + |
| 40 | +The Publish dialog opens in a new editor tab. |
| 41 | + |
| 42 | +:::image type="content" source="media/publish-database-project/publish-dialog.png" alt-text="Screenshot of Publish Project dialog showing publish target, server, and database fields." |
| 43 | + |
| 44 | +## Configure the publish target |
| 45 | + |
| 46 | +Use the Publish dialog to select where to deploy the project. |
| 47 | + |
| 48 | +1. Select a **Publish target**, such as SQL Server or Azure SQL. |
| 49 | + |
| 50 | +1. Select a **Server** connection. |
| 51 | + |
| 52 | + - If you're not connected, the connection dialog opens. |
| 53 | + - You can select an existing connection or create a new one. |
| 54 | + |
| 55 | +1. Select the target **Database**. |
| 56 | + |
| 57 | +After you establish a connection, the dialog shows more actions. |
| 58 | + |
| 59 | +> [!NOTE] |
| 60 | +> Make sure that the database type you're publishing to matches the project's **Target platform** setting. If they don't match, either change the project's target platform to align with the database, or, if you're confident that the project is compatible, use the advanced option in the Publish dialog that allows publishing to an incompatible platform. |
| 61 | +
|
| 62 | +## Generate a deployment script |
| 63 | + |
| 64 | +Before publishing, you can generate a deployment script to review the changes that the process makes to the database. |
| 65 | + |
| 66 | +1. In the Publish dialog, select **Generate Script**. |
| 67 | +1. Wait for the script to generate. |
| 68 | + |
| 69 | +The editor opens the generated script for review. |
| 70 | + |
| 71 | +> [!NOTE] |
| 72 | +> The deployment script includes SQLCMD variables for the connection and other deployment settings. Make sure SQLCMD mode is enabled in the editor, so that the variables resolve correctly when you run the script as a query. |
| 73 | +
|
| 74 | +:::image type="content" source="media/publish-database-project/deployment-script.png" alt-text="Screenshot of generated deployment script opened for review in the editor."::: |
| 75 | + |
| 76 | +## Publish changes |
| 77 | + |
| 78 | +After reviewing the deployment script, publish the changes. |
| 79 | + |
| 80 | +1. Go back to the Publish dialog. |
| 81 | +1. Select **Publish**. |
| 82 | +1. If prompted, confirm or select a database connection. |
| 83 | + |
| 84 | +The project is deployed to the selected target database. |
| 85 | + |
| 86 | +## Related content |
| 87 | + |
| 88 | +- [What are SQL database projects?](../../sql-database-projects/sql-database-projects.md) |
| 89 | +- [Get started with the SQL Database Projects extension](getting-started-sql-database-projects-extension.md) |
| 90 | +- [Tutorial: Create and deploy a SQL project](../../sql-database-projects/tutorials/create-deploy-sql-project.md) |
| 91 | +- [What is the MSSQL extension for Visual Studio Code?](../mssql/mssql-extension-visual-studio-code.md) |
0 commit comments