SQL Database Projects and AI: A Match Made in Heaven A developer argues that SQL Database projects, which keep a database schema as declarative .sql files in source control, pair well with AI coding tools because the build step validates every referenced object and target-platform syntax before deployment. The project builds into a .dacpac artifact that SqlPackage diffs against an existing database to generate only the needed ALTER statements, catching AI-generated queries that reference nonexistent columns or unsupported functions. Hey lovely readers, If you have ever asked an AI tool to write some SQL for you, you have probably seen this happen. You ask for a query, you get something that looks great, and then you run it and find out it uses a column that does not exist. Or a function your SQL Server version does not support. Or it quietly drops something you really wanted to keep. I wrote before about how AI tools are confident even when they are wrong https://dev.to/lovelacecoding/ai-is-making-english-a-must-have-skill-for-developers-29e . That is annoying in C , but at least the compiler yells at you. With databases, there often is no compiler. There is just you, a script, and a database that is about to find out. That is exactly why I think SQL Database projects and AI are a match made in heaven. Let's talk about why. If you have worked with SQL Database projects before, feel free to skip to "Why AI and SQL projects get along so well". If you have never heard of them, don't worry, we will start from the beginning. A SQL Database project is a local representation of your database schema. Your tables, views, stored procedures, and functions all live in .sql files inside a project on your machine, right next to your application code and in the same Git repository. If you are a .NET developer, you can think of it as a .csproj , but for your database. You write files, you build the project, and you get an output you can deploy. Here is what a table looks like in a SQL project: CREATE TABLE dbo . Customers Id INT NOT NULL PRIMARY KEY, Name NVARCHAR 100 NOT NULL, Email NVARCHAR 256 NOT NULL ; Nothing special, right? The special part is what happens when you want to change it. Most of us learned to change databases step by step. First you create the table. Then, a bit later, you write a script that adds a column. Then another script that changes a data type. After a year, you have a folder with 80 scripts that need to run in exactly the right order. SQL projects work differently. They are declarative, which means you describe what the database should look like, not how to get there. Each object is declared once, in one file. Want to add a phone number to your customers? You do not write an ALTER TABLE script. You just edit the same file: CREATE TABLE dbo . Customers Id INT NOT NULL PRIMARY KEY, Name NVARCHAR 100 NOT NULL, Email NVARCHAR 256 NOT NULL, PhoneNumber NVARCHAR 20 NULL ; Think of it like a blueprint of a house. You do not hand the builder a list of "knock down this wall, then add a window here". You hand them the blueprint of what the house should look like, and they figure out what needs to change. When you build a SQL project with dotnet build , two things happen. First, the project gets validated. The build checks that every object you reference actually exists. A view can't use a table or column that is not in your project. The build also checks your syntax against a target platform, which is the SQL version you are targeting. For example, if your project targets SQL Server 2017, you can't use JSON functions that were added in SQL Server 2022. Second, you get a .dacpac file. That is the build artifact, a package that contains your whole schema. To deploy it, you use a tool like SqlPackage. When you publish a .dacpac to a new database, it creates everything in the right order, so a table with a foreign key is created after the table it points to. When you publish to an existing database, it compares your .dacpac to that database and only generates the changes that are needed. Missing two columns? You get an ALTER TABLE . Changed a stored procedure? You get an ALTER PROCEDURE . So the blueprint is yours, and the builder is SqlPackage. If you worked with SQL projects years ago, you probably remember the original format, based on .NET Framework and mostly tied to Visual Studio on Windows. The newer format is SDK-style, using the Microsoft.Build.Sql SDK. It runs on modern .NET, works cross-platform, supports NuGet package references for database references, and automatically includes all .sql files in your project folder. Microsoft recommends it for new development, and it is the format that will be supported in the future. Tooling support is different per IDE, so here is where things stand right now. SDK-style projects are generally available in the SQL Database Projects extension for VS Code. JetBrains Rider supports them since version 2025.2 through a bundled plugin, with project templates, importing from an existing database, schema compare, and publishing. In Visual Studio 2022, they are available as a preview component. Visual Studio 2026 only supports the original format for now, so if Visual Studio is your IDE of choice, keep that in mind when picking your tools. Getting started with the SDK-style format looks like this: dotnet new install Microsoft.Build.Sql.Templates dotnet new sqlproj -n MyDatabase dotnet build Now for the fun part. Here is why I think this combination works so well. AI tools are only as good as the context you give them. If your schema lives only inside a running database, the AI either has to guess what your tables look like, or you have to give it a connection to your database. Please do NOT give an AI agent a connection string to production. With a SQL project, your entire schema is plain text in your repository. One object per file, easy to search, easy to read. An AI agent in your editor can open Tables/Customers.sql and see exactly what columns exist, what the types are, and what the foreign keys point to. No guessing, no database access needed. And if you already have a database without a SQL project, you can extract one. You can do this from VS Code, or from the command line: sqlpackage /Action:Extract /SourceConnectionString:"