Using Claude Code with SQL Server and Azure SQL DB
Let’s start with a 7-minute demo video – I didn’t edit this down because I want you to be able to see what happens in real time. In this video, I point the desktop version of Claude Code at a Github issue for the First Responder Kit and tell it to do the needful:
That’s certainly not the most complex Github issue in the world, but the idea in that short video was to show you how easy the overall workflow is, and why you and your coworkers might find it attractive.
Now, let’s zoom out and talk big picture.
The rest of this blog post is not for people who already use Claude Code. I don’t wanna hear Code users complaining in the comments about how I didn’t cover X feature or Y scenario. This is a high-level ~2,000-word overview of what it is, why you’d want it, what you’ll need to talk to your team about, and where to go to learn more.
I should also mention that I use a ton of bullet points in my regular writing. As with all of my posts, none of this is written with AI, period, full stop. These words come directly from my booze-addled brain, written as of March 2026, and this stuff will undoubtedly drift out of correctness over time.
What’s Claude Code?
Think of it as an app (either desktop or command line) that can call other apps including:
- sqlcmd – Microsoft’s command-line utility for running queries. You’re used to using SSMS because it’s much prettier and more powerful, but sqlcmd is fine if all you need to do is run queries and get results, and that’s all Claude Code needs to get started. As you get more advanced, you can use something called an MCP that gives Claude Code an easier way to chat with the database.
- Git / Github – so that it can get the latest versions of your app code (or DBA scripts, or in this case, the First Responder Kit) from source control, make changes, and submit pull requests for you to review. For the purposes of this post, I’m just gonna use the term Github, but if your company uses a different source control method, the same principles apply.
That means it has access to:
- Your Github issues and pull requests – which may present confidentiality issues for your company.
- Your local file system – in theory, you might be able to lock this down, but in practice you’re probably going to gradually expand Claude Code’s permissions to let it do more stuff over time.
- A database server – so think about where you’re pointing this thing, and what login you give it. If it’s going to test code changes, it’s probably going to need to alter procs, create/alter/drop tables, insert/update/delete test data, etc. On harder/longer tasks, it’s also going to be processing in the background while you’re doing other stuff, so you’re probably going to want to give it its own SQL Server service for its development use so it doesn’t hose up yours.
- Your code base – and if everything before didn’t raise security and privacy concerns, this one certainly should.
Think of it as an outside contractor.
When your company hires outside contractors, they put a lot of legal protections in place. They’ll set up:
- A non-disclosure agreement to make sure the contractor doesn’t share your secrets with the rest of the world
- A contract specifying what exactly each side is responsible for and what they’ll deliver to each other
- Insurance requirements to make sure the contractor will be able to pay for any egregious mistakes
- Human resources standards to make sure the contractor isn’t high and hallucinating while they work
With AI tools, you don’t really get any of that. That means if you choose to hire one of these tools for your company, all of this is on you. Even worse, anybody on your team can endanger your entire company if they don’t make good decisions along the way. I can totally understand why some/most companies are a little gun-shy on this stuff. It’s right to be concerned about these risks.
Here – and most of the time when you see me working with AI on the blog or videos – I’m working with the open source First Responder Kit, or code that I use as part of my training classes. This stuff is all open source, licensed under the MIT License. I’m not concerned about AI companies stealing my code.
That’s the best way for you to get started, too: play around with Claude Code on an open source Github repo that you usually use as a user (not a developer), like the First Responder Kit, Ola Hallengren’s maintenance scripts, Erik Darling’s SQL Server Performance Monitor, DBAtools, or even Microsoft’s SQL Server documentation. Learn to use Claude Code there, and later on, after you’ve built up confidence and a few good wins, then think about bringing it into your own company to work on your day job stuff. And when you do that…
When your company brings in an outside contractor…
The security and legal teams are going to care about:
- What Claude Code has access to – aka, Github, your local file system, your development database server, etc.
- Where Claude Code sends that data for thinking/processing – you should assume that it’s sending all of the accessible data somewhere
- If you send that data outside your company walls for thinking/processing, your company is also going care about how the thinker/processor uses your data – as in, not just to process your requests, but possibly for analysis to help the overall public or paying users
This leads to one of the big decisions when you’re using Claude Code: where does the thinking/processing happen?
The thinking can be done locally or remotely.
Claude Code is an app, but the thinking doesn’t actually happen in the app. Claude Code sends your data, prompt, database schema, etc somewhere.
Most people use Anthropic’s servers. They’re the makers of Claude Code. For around $100/month per person, you get unlimited processing up in their cloud. The advantage of using Anthropic’s servers is that you’ll get the fastest performance, with the biggest large language models (LLMs) that have the best thinking power, most accurate answers, and largest memories (context.) The drawback, of course, is that you’re sending your data outside your company’s walls, and you may not be comfortable with that.
If you’re not comfortable with Anthropic, maybe your company is more comfortable with Google Gemini’s models, or OpenAI’s ChatGPT models. At any given time, it’s an arms race between those top companies (and others, like hosting companies like OpenRouter) as to who produces the best tradeoffs for processing speed, accuracy, and cost.
If you’re not comfortable with any of those, you can do the processing on your own server. When I say “server”, that could be a Docker container running on your laptop, an app installed on your gaming PC with a high-powered video card, or a shared server at your company with a bunch of GPUs stuffed in it.
In that case, it’s up to you to pick the best LLM that you can, that runs as quickly as possible, given your server’s hardware. There are tiny not-so-bright models that run (or perhaps, leisurely stroll) on hardware as small as a Raspberry Pi. There are pretty smart models that require multiple expensive and power-hungry video cards. But even the best local models can’t compete with what you get up in Anthropic’s servers today.
The good news is that you don’t have to make some kind of final decision: you can switch between hosted and local models by just changing Claude Code’s config file.
The contractor and prompt qualities affect the results.
Generally speaking, the better/newer LLM that you use, and the smaller of a problem you’re working with, the more vague prompts you can get away with, like “we’re having deadlock problems – can you fix that?”
On the other hand, the older/smaller/cheaper LLM that you use – especially small locally hosted models – the more specific and directed your prompts have to be to get great results. For example, you may have to say something like, “sp_AddCustomer and sp_AddOrder are deadlocking on the CustomerDetails table when both procs are called simultaneously. Can you reduce the deadlock potential by making code changes to one or both of those procs? You can use hints, query rewrites, retry logic, whatever, as long as the transactions still finish the same way.”
And no matter what kind of LLM you’re using, the more ambitious your code changes become, the more important the prompt becomes. When I’m adding a major new feature or proposing a giant change, I start a chat session with Claude – not Claude Code, but just plain old Claude, the chat UI like ChatGPT – and say something like:
I’m working on the attached sp_Blitz.sql script, which builds a health check report on Microsoft SQL Server. It isn’t currently compatible with Azure SQL DB because it uses sp_MSforeachdb and some of the dynamic SQL uses the USE command. I’d like to use Claude Code to perform the rewrite. Can you review the code, and help me write a good prompt for Claude Code?
I know, it sounds like overkill, using one AI to tell another AI what to do, but I’ve found that in a matter of seconds, it produces a muuuuch better prompt than I would have written, taking more edge cases of the code into account. Then I edit that prompt, clarify some of my design decisions and goals, and then finally take the finished prompt over to Claude Code to start work there.
For now, I use Claude Code on a standalone machine.
I really like to think of AI tools like Claude Code as an outside contractor.
I’m sure the contractor is a nice person, and I have to trust it at least a little – after all, I’m the guy who hired it, and I shouldn’t hire someone that I don’t trust. Still, though, I gotta put safeguards in place.
So I keep Claude Code completely isolated.
I know that sounds a little paranoid, but right now in the wild west of AI, paranoia is a good thing.
For me, it starts with isolated hardware. A few years ago, I got a Windows desktop to use for gaming, streaming, and playing around with local large language models (LLMs). It’s got a fast processor, 128GB RAM, a decently powerful NVidia 4090 GPU, Windows 11, Github, and SQL Server 2025.
I think of that computer as Claude Code’s machine: he works there, he lives there. That way, I can guarantee none of my clients’ code or data is on there, and it doesn’t have things like my email either. When I wanna work, stream, record videos from that Windows machine, I just remote desktop into it from my normal Mac laptop.
When I wanna do client work without sending the data to Anthropic, I’ve got Ollama set up on that machine too. It’s a free, open source platform for running your own local models. It supports a huge number of LLMs, and there is no one right answer for which model to use. I love finding utilities like llmfit which check hardware to see what models can be run on it, and finding posts like which models run best on NVidia RTX 40 series GPUs as of April 2025 or on Apple Silicon processors as of February 2026, because they help me take the guesswork out of experimenting. I copy client data onto that machine temporarily, do that local work, and then delete the client data again before reconfiguring Claude Code to talk to Anthropic’s servers.
How you can get started with Claude Code
Your mission, should you choose to accept it, is to add a new warning to sp_Blitz when a SQL Server has Availability Groups enabled at the server level, but it doesn’t have any databases in an AG. To help, I’ve written a short, terse Github issue for this request, and a longer, more explicit one so you can also see how the quality of the input affects the quality of your chosen LLM’s code.
To accomplish the task, the bare minimum tasks would be:
- Install Claude Code (I’d recommend the terminal version first because the documentation is much better – the desktop version looks cool, but it’s much harder to get started with)
- Clone the First Responder Kit repo locally
- Prompt Claude Code to write the code – tell it about the Github issue and ask it to draft a pull request with the improved code, for your review
Stretch goals:
- Set up a SQL Server instance for Claude Code to connect to – could be an existing instance or a new one
- Set up sqlcmd or the SQL Server MCP so Claude Code can connect to it – if you use the MCP, you’ll need to edit Claude Code’s config files to include the server, login, password you want it to use
- Prompt Claude Code to test its code
You don’t have to submit your actual work as a pull request – I’m not going to accept any of those pull requests anyway. (I’ll just delete them if they come in – and it’s okay if you do one, I won’t be offended.) These Github issues exist solely to help you learn Claude Code.
How I can help
Unfortunately, I can’t do free personalized support for tens of thousands of readers to get their Claude Code setups up and running. At some point, I might build a paid training class for using Claude Code with SQL Server, and at that point, the paid students would be able to get some level of support. For now, though, I wanted to get this blog post, video, and GitHub issues out there for the advanced folks to start getting ahead of the curve.
However, If your company would like to hire me to help get a jump start on using Claude Code to improve your DBA productivity, proactively find database issues before they strike, and finally start making progress on your known issues backlog, email me.
Related

Hi! I’m Brent Ozar.
I make Microsoft SQL Server go faster. I love teaching, travel, cars, and laughing. I’m based out of Las Vegas. He/him. I teach SQL Server training classes, or if you haven’t got time for the pain, I’m available for consulting too.
Get Free SQL Stuff
"*" indicates required fields

19 Comments. Leave new
Hi Brent
Why did you choose Claude over other platforms such as Chat GPT? Can the same thing eb accomplished with ChatGPT as I have a subscription with ChatGPT? Should I look at switching to Claude?
Dan – go ahead and Google for “Claude Code vs ChatGPT Codex” and there are a ton of great videos and comparison posts out there.
It seems Claude is the “goto” product for AI integration, especially in the alternative investment world, such as small/medium sized hedge funds. My client, that I have been at for 15+ years, providing DBA,,ETL, and general SQL developmnet services for are now full bore on the Claude boat. I am a new user of it and a bit “old school” and it already it has saved me weeks of time. I was very surprised with the quality of code it genetated with the basic instructions I provided, specifically with genetating ps1 and python scripts to perform various file load/staging tasks to replace my aging OPENROWSET calls to load Excel sheets. My one concern is many of these firms are on a “push the task to the user” mindset with tasks like this. Many of these smaller firms do not have formal code release procedures in practice, and are very “instant gratification focused”, especially if they want to analyze data / DSS as to “yay or nay” to secure a deal. It has the threat of becoming a messy free for all, which I have warned their IT management many times about. So, although AI will provide a huge benefit, it needs to be closely monitored.
Hi Brent,
Thanks for sharing this.
Nice shirt, btw.
My pleasure! Hahaha, thanks.
Excellent article. love the gentle point “make sure the contractor isn’t high and hallucinating while they work”
Hahaha, thanks! The hallucination problem is definitely real.
Another tool worth keeping in mind is GitHub Copilot CLI with Agent mode, which with the Claude models can behave quite similarly to Claude Code (repo exploration, edits, running commands, etc.).
Copilot is also now integrated in recent SSMS versions, although without agent capabilities yet. If that arrives later, it could become an interesting alternative for SQL Server development.
Yep! I look forward to seeing people show the Github Copilot CLI equivalent with SQL Server work – I haven’t seen that demoed, and in my brief experiments it felt pretty far behind.
Copilot in SSMS is waaaaay behind this kind of thing. That’s not bad necessarily – I adore SSMS Copilot’s autocompletions, for example – but I just don’t see how SSMS Copilot can get anywhere near close to what’s happening in the video, not without massive investments.
I agree regarding the SSMS integration. I use Github Copilot with VS 2026 and VS Code (which has Agent mode) and the gap against Claude Code there isn’t as big anymore as it used to be. We can hope for a better integration in SSMS in the future, but I can see it is more challenging as the workspace often is the entire database. However, with Github support in SSMS, and given it is based on Visual Studio, it should not be impossible to implement for a workspace limited to a repository (or maybe just the open files) as context.
I had everything setup in VS Code for SQL connectivity, but would be great if they had a built in connector for SQL server as they do for Other DB platforms. I setup a sql account with only data reader and view definition perms for Claude to connect with.
You need a T1000 version of your cartoon image
[…] Using Claude Code with SQL Server and Azure SQL DB (Brent Ozar) […]
Do you want a hand with expanding this?
Do people want this except based on Oracle or Postgres?
My skills: Oracle, Sql Server, git, Java, Python, time.
Want: Postgres, AI, (or Sql Server).
Actually going to do: Postgres utility/101/Claude App development.
I had not planned it as a combined git-AI-postgres-101 blog/whitepaper. I know windows, but I am actually mac/Linux.
An obvious todo for me is incremental expansion i.e. paragraph and any complications setting up Sql Server or Linux (or on Linux on Mac VM).
You’re definitely welcome to publish your own blog, YouTube video, user group presentation, etc! Go for it – there’s not much info on Claude Code out there right now, and it’s a great chance to get your foot in the door in the community.
I don’t do user-contributed docs/code/etc here though.
Brent… You are going to rip me to pieces for saying this but this AI scare tactic is only because DBAs aren’t developers and don’t understand how to prevent those concerns from happening. DBAs simply don’t have the developer skills to deal with the AI issue. One reason why I have said for several years is that nobody should hire a DBA that does not possess the ability to reasonably develop in a high level language.
Any high school kid with decent skills by the end of their first year can write code that will change the names for every schema, table, and programmability code. That’s simple. The only thing needed is to create a mapping table so you can translate anything AI gives you back into the original naming convention. This step is remarkably easy.
The next step is to look at Programmability and Query Store and change that code from the original to the new naming convention. This is a bit more complex but is doable by most junior C# developers. Databases have to be equivalent, not equal.
The third step requires a backup of the database and the ability to create a new database. If you look at the stats for each table, you only need those columns that are referenced in the ON, WHERE, GROUP BY, HAVING or ORDER BY. All the other columns in the table simply are not needed. You need to keep track that has been removed but you do not need that data for AI. For stats the only thing you need to do is have some kind of ordering mechanic that will create a list for each column and create an ordered transposition. If you have 1,000 people in the tabled named “John”, you just have to replace “John” with the same value that is in the correct order throughout the table. THIS TAKES TIME but since the primary key map you only have it’s not hard. This should create the a stat file that is equivalent to the original table. When you generate the stats for the table then the stats should reflect the same results as you would get with production.
To confuse things a bit more, if you turn off IDENTITY INSERT you can add nnn to every key or you can create a function that changes the key per table thus f() so you can scramble the keys. If you know the what table a foreign key goes to then your keys will match up.
Finally for all of your CRUD statements, you simply run those statements which will generate the stats you have on the table with data that reflects what is in your production database. You convert your UPDATE and DELETE statements into SELECT and only look at INSERT statements that contain a SELECT.
You can run this on your laptop with a portable SSD drive that can create the two databases given that you don’t have some very large database. If you have a 1T database you can create an AI conversion database produced overnight. Any query you do should produce an identical execution plan. For those databases where you decide to eliminate unneeded columns, your execution plan should be ratioed proportionally.
Downside is you have to write an app that converts your human database structure into your mapped structure and the results AI gives you back to your mapped structure. This isn’t difficult but you do have to eliminate and replace those removed columns.
I am not worried about the AI concerns because as a software developer I can write code that can overcome those hurdles. My job is to solve problems and create tools that save time. Not hard to bypass these concerns because hurdles are meant to be overcome. “IMPOSSIBLE” only means it hasn’t been done yet.
Wayne – I asked ChatGPT to summarize your comment into 2 sentences because I thought I was missing something, and it said:
—
The commenter argues that AI-related database privacy and security concerns are solvable technical problems, and says DBAs are overestimating the risk because many lack software development skills. They believe a developer could build tooling to rename and remap schema objects, scrub or transform sensitive data while preserving statistics and execution-plan behavior, and create a safe AI-friendly copy of a production database without much difficulty.
—
If that summary is correct, I don’t understand why you would think I would rip you to pieces for that.
I have repeatedly endorsed the use of AI in my blog posts, social media, and videos. I’ve built it into the First Responder Kit scripts. I have always strived to make it easier for everyone – developers, managers, power users, etc – to do database stuff with a lower barrier to entry.
I’m a former developer, as are many accidental DBAs.
I feel like you’re expecting an argument where there just isn’t one. I don’t understand what you think is controversial about what you’re saying. ¯\_(?)_/¯
This is awesome.. Thanks for sharing. I’m now a proud anthropic customer – $20/month well spent. Puts a smile on my face when interacting with Claude Code. What a shift. I love it.. Thanks again for doing the initial work and letting us all know the value thats out there if we only spend the time to learn and embrace. cheers.