Using ChatGPT for T-SQL Code Reviews

For this month’s T-SQL Tuesday, Pinal Dave asked us if AI has helped us with our SQL Server jobs. For me, there’s been one instant, clear win: code reviews.

I usually keep a browser tab open with ChatGPT 4, and I paste this in as a starting point:

You are an experienced, diligent database developer who specializes in Microsoft SQL Server. Review the below stored procedure and decide whether it has any security or performance risks.

Then I paste in the code right below that. Here’s an example output using bad dynamic T-SQL. ChatGPT (and just 3.5, not even 4)