Skip to content

Commit 7b1e9ae

Browse files
authored
SQL projects feature (#36892)
1 parent 914252b commit 7b1e9ae

24 files changed

Lines changed: 561 additions & 177 deletions

docs/tools/sql-database-projects/concepts/database-references.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: Database References Overview
33
description: Extend a SQL project with references to additional database components.
4-
author: dzsquared
5-
ms.author: drskwier
6-
ms.reviewer: maghan, randolphwest
7-
ms.date: 02/06/2026
4+
author: rwestMSFT
5+
ms.author: randolphwest
6+
ms.reviewer: drskwier
7+
ms.date: 03/11/2026
88
ms.service: sql
99
ms.subservice: sql-database-projects
1010
ms.topic: concept-article
@@ -161,6 +161,33 @@ The extension also prompts to select from the following reference locations:
161161

162162
::: zone-end
163163

164+
:::zone pivot="sq1-sql-server-management-studio"
165+
166+
To add a project reference to a SQL project, add an `<ItemGroup>` item to the `.sqlproj` file with an appropriate reference item for each database reference. For example, the following project reference is added to a SQL project to reference the `WorldWideImporters` project in a different database on a different server:
167+
168+
```xml
169+
<ItemGroup>
170+
<ProjectReference Include="..\Contoso\WorldWideImporters.sqlproj">
171+
<Name>WorldWideImporters</Name>
172+
<Project>{d703fc7a-bc47-4aef-9dc5-cf01094ddb37}</Project>
173+
<SuppressMissingDependenciesErrors>False</SuppressMissingDependenciesErrors>
174+
<ServerSqlCmdVariable>WWIServer</ServerSqlCmdVariable>
175+
<DatabaseSqlCmdVariable>WorldWideImporters</DatabaseSqlCmdVariable>
176+
</ProjectReference>
177+
</ItemGroup>
178+
```
179+
180+
The project reference is used in a sample view definition in the SQL project:
181+
182+
```sql
183+
CREATE VIEW dbo.WorldWide_Products
184+
AS
185+
SELECT ProductID, ProductName, SupplierID
186+
FROM [$(WWIServer)].[$(WorldWideImporters)].[Purchasing].[Suppliers]
187+
```
188+
189+
:::zone-end
190+
164191
::: zone pivot="sq1-command-line"
165192

166193
To add a project reference to a SQL project, add an `<ItemGroup>` item to the `.sqlproj` file with an appropriate reference item for each database reference. For example, the following project reference is added to a SQL project to reference the `WorldWideImporters` project in a different database on a different server:

docs/tools/sql-database-projects/concepts/package-references.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
title: SQL Projects Package References
33
description: Reference database objects with package references.
4-
author: dzsquared
5-
ms.author: drskwier
6-
ms.reviewer: maghan, randolphwest
7-
ms.date: 10/10/2025
4+
author: rwestMSFT
5+
ms.author: randolphwest
6+
ms.reviewer: drskwier
7+
ms.date: 03/11/2026
88
ms.service: sql
99
ms.subservice: sql-database-projects
1010
ms.topic: concept-article
1111
ms.collection:
1212
- data-tools
1313
ms.custom:
1414
- ignite-2024
15-
zone_pivot_groups: sq1-sql-projects-tools
1615
---
1716

1817
# SQL projects package references
@@ -66,7 +65,8 @@ The following example includes a package reference to the `Contoso.AdventureWork
6665
In this example, the AdventureWorks `.dacpac` file is published as a package `Contoso.AdventureWorks` version `1.1.0` to a NuGet feed. The `<DatabaseSqlCmdVariable>` element specifies the name of the database on the same server where the objects in the package are located and would be used to indicate this reference in three-part naming. The [SQLCMD variable](sqlcmd-variables.md) `AdventureDB` is used to set the database name at deployment time and is used in the project similarly to this example query:
6766

6867
```sql
69-
SELECT * FROM [$(AdventureDB)].dbo.Customers;
68+
SELECT *
69+
FROM [$(AdventureDB)].dbo.Customers;
7070
```
7171

7272
The `<DacpacName>` element specifies the name of the `.dacpac` file for the package reference, without the file extension or path. The `<DacpacName>` element is optional and is only required when the name of the `.dacpac` file is different from the name of the package.

docs/tools/sql-database-projects/concepts/pre-post-deployment-scripts.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: Pre-Deployment and Post-Deployment Scripts
3-
description: "Add custom scripts for pre/post-deployment execution."
4-
author: dzsquared
5-
ms.author: drskwier
6-
ms.reviewer: maghan, randolphwest
7-
ms.date: 01/29/2026
3+
description: Add custom scripts for pre-deployment and post-deployment execution.
4+
author: rwestMSFT
5+
ms.author: randolphwest
6+
ms.reviewer: drskwier
7+
ms.date: 03/11/2026
88
ms.service: sql
99
ms.subservice: sql-database-projects
1010
ms.topic: concept-article
@@ -106,6 +106,14 @@ The script file is added to the project and opened in the query editor, where yo
106106

107107
::: zone-end
108108

109+
:::zone pivot="sq1-sql-server-management-studio"
110+
111+
In **Solution Explorer**, right-click the project node and select **Add** > **New Item**. The **Add New Item** dialog appears, select **Show All Templates** > **Table**, then select **Pre-Deployment Script** or **Post-Deployment Script**.
112+
113+
The script file is added to the project and opened in the query editor, where you can complete the script. This script will be executed before or after the deployment plan is executed, every time the project is deployed.
114+
115+
:::zone-end
116+
109117
::: zone pivot="sq1-command-line"
110118

111119
Edit the `.sqlproj` file directly to add pre-deployment or post-deployment scripts. Add a `<PreDeploy>` or `<PostDeploy>` item to the `<ItemGroup>` section of the `.sqlproj` file.

docs/tools/sql-database-projects/concepts/schema-comparison.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: Schema Comparison Overview
33
description: Visualize the difference in database models with schema compare.
4-
author: dzsquared
5-
ms.author: drskwier
6-
ms.reviewer: maghan, randolphwest, tsiddique
7-
ms.date: 02/06/2026
4+
author: rwestMSFT
5+
ms.author: randolphwest
6+
ms.reviewer: drskwier, tsiddique
7+
ms.date: 03/11/2026
88
ms.service: sql
99
ms.subservice: sql-database-projects
1010
ms.topic: overview
@@ -201,9 +201,15 @@ To update the schema of the target, you have two options. You can update the tar
201201

202202
::: zone-end
203203

204+
:::zone pivot="sq1-sql-server-management-studio"
205+
206+
[!INCLUDE [schema-compare-where-found](../includes/schema-compare-where-found.md)]
207+
208+
:::zone-end
209+
204210
::: zone pivot="sq1-command-line"
205211

206-
[!INCLUDE [schema-compare-command-line](../includes/schema-compare-command-line.md)]
212+
[!INCLUDE [schema-compare-where-found](../includes/schema-compare-where-found.md)]
207213

208214
::: zone-end
209215

docs/tools/sql-database-projects/concepts/sql-code-analysis/sql-code-analysis.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: "SQL Code Analysis"
3-
description: "Analyzing Database Code to Improve Code Quality"
4-
author: dzsquared
5-
ms.author: drskwier
6-
ms.reviewer: maghan, randolphwest
7-
ms.date: 03/11/2025
2+
title: SQL Code Analysis
3+
description: Analyze database code to improve code quality.
4+
author: rwestMSFT
5+
ms.author: randolphwest
6+
ms.reviewer: drskwier
7+
ms.date: 03/11/2026
88
ms.service: sql
99
ms.subservice: sql-database-projects
1010
ms.topic: concept-article
@@ -82,7 +82,7 @@ A file `StaticCodeAnalysis.SuppressMessages.xml` can be added to the project to
8282

8383
## Provided rules
8484

85-
### T-SQL Design Issues
85+
### T-SQL design issues
8686

8787
When you analyze the T-SQL code in your database project, one or more warnings might be categorized as design issues. You should address design issues to avoid the following situations:
8888

@@ -118,7 +118,7 @@ The provided rules identify the following design issues:
118118
- [SR0012: Avoid using reserved words for type names](./t-sql-naming-issues.md#sr0012-avoid-using-reserved-words-for-type-names)
119119
- [SR0016: Avoid using sp_ as a prefix for stored procedures](./t-sql-naming-issues.md#sr0016-avoid-using-sp_-as-a-prefix-for-stored-procedures)
120120

121-
### T-SQL Performance Issues
121+
### T-SQL performance issues
122122

123123
When you analyze the T-SQL code in your database project, one or more warnings might be categorized as performance issues. You should address a performance issue to avoid the following situation:
124124

@@ -160,6 +160,14 @@ From the text editor, add an element `<RunSqlCodeAnalysis>True</RunSqlCodeAnalys
160160

161161
::: zone-end
162162

163+
:::zone pivot="sq1-sql-server-management-studio"
164+
165+
To enable or disable SQL code analysis in SQL Server Management Studio (SSMS), right-click the project in **Solution Explorer** and select **Properties**. In the **Code Analysis** tab of the properties window, select the desired code analysis settings.
166+
167+
To disable a specific rule or to change the severity of a rule, select the corresponding option from the dropdown list for that rule from the rule list.
168+
169+
:::zone-end
170+
163171
::: zone pivot="sq1-command-line"
164172

165173
To override the code analysis settings in the project file, you can use the `/p:RunSqlCodeAnalysis` and `/p:SqlCodeAnalysisRules` properties with the `dotnet build` command. For example, to build with code analysis disabled:

docs/tools/sql-database-projects/concepts/sqlcmd-variables.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
22
title: SQLCMD Variables in SQL Projects
3-
description: "Dynamically set values in a SQL project at deployment."
4-
author: dzsquared
5-
ms.author: drskwier
6-
ms.reviewer: maghan, randolphwest
7-
ms.date: 08/30/2024
3+
description: Dynamically set values in a SQL project at deployment.
4+
author: rwestMSFT
5+
ms.author: randolphwest
6+
ms.reviewer: drskwier
7+
ms.date: 03/11/2026
88
ms.service: sql
99
ms.subservice: sql-database-projects
1010
ms.topic: concept-article
1111
ms.collection:
1212
- data-tools
13-
zone_pivot_groups: sq1-sql-projects-tools
1413
ms.custom:
1514
- ignite-2024
1615
- sfi-ropc-nochange
16+
zone_pivot_groups: sq1-sql-projects-tools
1717
---
1818

1919
# SQLCMD variables overview
@@ -92,6 +92,16 @@ When you publish the project from the SQL Database Projects extension, SQLCMD va
9292

9393
::: zone-end
9494

95+
:::zone pivot="sq1-sql-server-management-studio"
96+
97+
To add a SQLCMD variable to a SQL project in SQL Server Management Studio (SSMS), right-click the project in **Solution Explorer** and select **Properties**. In the **SQLCMD Variables** section of the properties window, specify the variable name and optionally a default value.
98+
99+
Once the variable is defined, it can be used in SQL scripts by wrapping the variable name in `$(variableName)` syntax.
100+
101+
When you publish the project from SSMS, SQLCMD variables are set in the publish dialog.
102+
103+
:::zone-end
104+
95105
::: zone pivot="sq1-command-line"
96106

97107
To add a SQLCMD variable to a SQL project, add an `<ItemGroup>` item to the `.sqlproj` file with a `<SqlCmdVariable>` item for each variable. The `<SqlCmdVariable>` item includes the variable name, a default value, and a value that can be set at deployment time.

docs/tools/sql-database-projects/concepts/target-platform.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: SQL Projects Target Platform
3-
description: "Specify SQL version compatibility for SQL database projects."
4-
author: dzsquared
5-
ms.author: drskwier
6-
ms.reviewer: maghan, randolphwest
7-
ms.date: 03/11/2025
3+
description: Specify SQL version compatibility for SQL database projects.
4+
author: rwestMSFT
5+
ms.author: randolphwest
6+
ms.reviewer: drskwier
7+
ms.date: 03/11/2026
88
ms.service: sql
99
ms.subservice: sql-database-projects
1010
ms.topic: concept-article
@@ -73,6 +73,12 @@ Alternatively, you can edit the `.sqlproj` file directly to change the target pl
7373

7474
::: zone-end
7575

76+
:::zone pivot="sq1-sql-server-management-studio"
77+
78+
To change the target platform of a SQL project in SQL Server Management Studio (SSMS), right-click the project in **Solution Explorer** and select **Properties**. In the **Project Settings** tab of the properties window, select the desired target platform from the **Target platform** dropdown list.
79+
80+
:::zone-end
81+
7682
::: zone pivot="sq1-command-line"
7783

7884
To build a SQL project for a target platform different than the target platform specified in the `.sqlproj` file, use the `/p:DSP=` command line argument. For example, to build a SQL project for SQL Server 2019 compatibility:

docs/tools/sql-database-projects/get-started.md

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: Get Started with SQL Database Projects
33
description: A SQL database project is a local representation of SQL objects that comprise the schema for a single database, such as tables, stored procedures, or functions.
4-
author: dzsquared
5-
ms.author: drskwier
6-
ms.reviewer: maghan, randolphwest
7-
ms.date: 01/29/2026
4+
author: rwestMSFT
5+
ms.author: randolphwest
6+
ms.reviewer: drskwier
7+
ms.date: 03/11/2026
88
ms.service: sql
99
ms.subservice: sql-database-projects
1010
ms.topic: get-started
@@ -33,31 +33,39 @@ This article steps through creating a new SQL project, adding objects to the pro
3333

3434
::: zone pivot="sq1-visual-studio"
3535

36-
- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
36+
- [.NET SDK](https://dotnet.microsoft.com/download/dotnet/10.0)
3737
- [Visual Studio 2022 Community, Professional, or Enterprise](https://visualstudio.microsoft.com/downloads/)
3838
- [Install SQL Server Data Tools (SSDT) for Visual Studio](../../ssdt/download-sql-server-data-tools-ssdt.md)
3939

4040
::: zone-end
4141

4242
::: zone pivot="sq1-visual-studio-sdk"
4343

44-
- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
44+
- [.NET SDK](https://dotnet.microsoft.com/download/dotnet/10.0)
4545
- [Visual Studio 2022 Community, Professional, or Enterprise](https://visualstudio.microsoft.com/downloads/)
46-
- [SQL Server Data Tools, SDK-style (preview) installed in Visual Studio](../../ssdt/sql-server-data-tools-sdk-style.md)
46+
- [SQL Server Data Tools, SDK-style (preview)](../../ssdt/sql-server-data-tools-sdk-style.md)
4747

4848
::: zone-end
4949

5050
::: zone pivot="sq1-visual-studio-code"
5151

52-
- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
52+
- [.NET SDK](https://dotnet.microsoft.com/download/dotnet/10.0)
5353
- [VS Code](https://code.visualstudio.com/Download)
5454
- [SQL Database Projects extension](../visual-studio-code-extensions/sql-database-projects/sql-database-projects-extension.md)
5555

5656
::: zone-end
5757

58+
:::zone pivot="sq1-sql-server-management-studio"
59+
60+
- [.NET SDK](https://dotnet.microsoft.com/download/dotnet/10.0)
61+
- [SQL Server Management Studio (SSMS)](/ssms/install/install)
62+
- [Database DevOps workload installed in SSMS](/ssms/database-devops)
63+
64+
:::zone-end
65+
5866
::: zone pivot="sq1-command-line"
5967

60-
- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
68+
- [.NET SDK](https://dotnet.microsoft.com/download/dotnet/10.0)
6169
- [SqlPackage CLI](../sqlpackage/sqlpackage-download.md)
6270
- [Microsoft.Build.Sql.Templates .NET templates](https://www.nuget.org/packages/Microsoft.Build.Sql.Templates/)
6371

@@ -124,6 +132,20 @@ Once completed, the empty project is opened and visible in the **Database Projec
124132

125133
::: zone-end
126134

135+
:::zone pivot="sq1-sql-server-management-studio"
136+
137+
Select **File**, **New**, then **Project**.
138+
139+
In the **New Project** dialog box, use the term **SQL Server** in the search box. The top result should be **SQL Server Database Project**.
140+
141+
:::image type="content" source="media/getting-started/new-project-dialog-ssms.png" alt-text="Screenshot of New project dialog." lightbox="media/getting-started/new-project-dialog-ssms.png":::
142+
143+
Select **Next** to proceed to the next step. Provide a project name, which doesn't need to match a database name. Verify and modify the project location as needed.
144+
145+
Select **Create** to create the project. The empty project is opened and visible in the **Solution Explorer** for editing.
146+
147+
:::zone-end
148+
127149
::: zone pivot="sq1-command-line"
128150

129151
With the .NET templates for Microsoft.Build.Sql projects installed, you can create a new SQL database project from the command line. The `-n` option specifies the name of the project, and the `-tp` option specifies the project target platform.
@@ -169,6 +191,16 @@ More database objects can be added through the context menu on the project node,
169191

170192
::: zone-end
171193

194+
::: zone pivot="sq1-sql-server-management-studio"
195+
196+
In **Solution Explorer**, right-click the project node and select **Add**, then **New Item**. The **Add New Item** dialog appears, select **Show All Templates** and then **Table**. Specify the table name as the file name and select **Add** to create the table in the SQL project.
197+
198+
The table is opened in the SSMS query editor with the template table definition, where you can add columns, indexes, and other table properties. Save the file when you're done making the initial edits.
199+
200+
More database objects can be added through the **Add New Item** dialog, such as views, stored procedures, and functions. Access the dialog by right-clicking the project node in **Solution Explorer** and selecting **Add**, then the desired object type after **Show All Templates**. Files in the project can be organized into folders through the **New Folder** option under **Add**.
201+
202+
::: zone-end
203+
172204
::: zone pivot="sq1-command-line"
173205

174206
Files can be added to the project by creating them in the project directory or nested folders. The file extension should be `.sql` and organization by object type or schema and object type is recommended.
@@ -212,6 +244,14 @@ The output window automatically opens to display the build process. If there are
212244

213245
::: zone-end
214246

247+
::: zone pivot="sq1-sql-server-management-studio"
248+
249+
In **Solution Explorer**, right-click the project node and select **Build**.
250+
251+
The output window automatically opens to display the build process. If there are errors or warnings, they're displayed in the output window. On a successful build, the build artifact (`.dacpac` file) is created its location is included in the build output (default is `bin\Debug\projectname.dacpac`).
252+
253+
::: zone-end
254+
215255
::: zone pivot="sq1-command-line"
216256

217257
SQL database projects can be built from the command line using the `dotnet build` command.
@@ -266,6 +306,16 @@ After the connection is configured, the deployment process will begin. You can c
266306

267307
::: zone-end
268308

309+
::: zone pivot="sq1-sql-server-management-studio"
310+
311+
In **Solution Explorer**, right-click the project node and select **Publish...**.
312+
313+
The publish dialog opens, where you establish the **target database connection**. If you don't have an existing SQL instance for deployment, LocalDB (`(localdb)\MSSQLLocalDB`) is installed with Visual Studio and can be used for testing and development.
314+
315+
Specify a database name and select **Publish** to deploy the project to the target database or **Generate Script** to generate a script to review before executing.
316+
317+
::: zone-end
318+
269319
::: zone pivot="sq1-command-line"
270320

271321
The SqlPackage CLI is used to deploy a `.dacpac` file to a target database with the [publish action](../sqlpackage/sqlpackage-publish.md).

0 commit comments

Comments
 (0)