SDK-Style SQL Database Projects
This lesson explains declarative database development, SDK-style projects and how the build validates the model.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish between declarative projects and migration scripts.
- Describe the SDK-style project format and its tooling.
- Explain what the build validates, including the target platform.
Declarative database development
In a SQL database project, each object, such as a table, view, procedure or role, is defined once with a CREATE statement in its own .sql file. To change an object, the developer edits that definition, for example adding a column to the CREATE TABLE statement, rather than writing an ALTER script. Building the project produces a .dacpac (data-tier application package), a model of the whole schema. At deployment, tools compare the dacpac with the target database and generate the ALTER statements needed, in dependency order. This differs from migration-based tools, which store a sequence of change scripts; the declarative model always shows the intended final state.
Declarative or migration-based?
SDK-style projects
SDK-style projects use the Microsoft.Build.Sql project SDK. They build on .NET 8 or later on Windows, Linux and macOS with dotnet build, include all .sql files in the folder by default, and support NuGet package references for database references. They are the format used by the SQL Database Projects extension in VS Code and by SQL database in Fabric's source control integration, and Microsoft recommends them for new development. The original format requires .NET Framework and Visual Studio's SQL Server Data Tools.
<Project Sdk="Microsoft.Build.Sql/1.0.0">
<PropertyGroup>
<Name>Inventory</Name>
<DSP>Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider</DSP>
<ModelCollation>1033, CI</ModelCollation>
<RunSqlCodeAnalysis>True</RunSqlCodeAnalysis>
</PropertyGroup>
<ItemGroup>
<PostDeploy Include="Scripts\Script.PostDeployment.sql" />
</ItemGroup>
</Project>A project is created with dotnet new sqlproj after installing the Microsoft.Build.Sql.Templates package, from the VS Code extension, or by creating a project from an existing database, which generates one file per object.
SDK-style projects
Build validation
Building is the first quality gate. The target platform (the DSP property, such as Azure SQL Database or SQL Server 2025) determines which syntax and features are valid, so using a feature the platform lacks fails the build. The build also resolves every reference: a view that selects a column that does not exist, or a procedure that calls a missing procedure, is an error. Objects in other databases or system objects are resolved through database references (dacpac or package references, such as the master database package). Code analysis rules, enabled with RunSqlCodeAnalysis, add warnings for design and performance issues such as SELECT * or non-SARGable predicates, and selected rules can be treated as errors.
dotnet new install Microsoft.Build.Sql.Templates
dotnet new sqlproj -n Inventory
dotnet build Inventory/Inventory.sqlproj # produces bin/Debug/Inventory.dacpacWhat the build catches
Catching a broken view before deployment
A developer renames the Customer.Phone column to MobilePhone directly in the test database, and a view that references Phone breaks only when users open a report a week later. The team wants such errors found before any deployment. What should the team adopt?
Manage the schema in an SDK-style SQL database project and build it in a pull request pipeline. When the column is renamed in the table's file, the build fails because the view still references Phone, so the developer must fix the view in the same change. Running ad hoc ALTER scripts against test databases does not validate dependent objects, and code analysis alone does not replace building the full model.
What is the build output of a SQL database project?
Show answer
A .dacpac file, a model of the schema that tools deploy to databases.
Exam Tips
Remember for the exam
- SDK-style projects: Microsoft.Build.Sql, dotnet build, cross-platform; recommended for new work.
- Build output: a .dacpac model of the schema.
- Target platform (DSP) validates syntax against the right SQL version.
- Broken references fail the build; code analysis adds warnings.