The YouTube video by Andy Novick demonstrates using a large language model (specifically Grok-3 in April 2025) to generate T-SQL code for a simple ETL task. Novick, a SQL Server consultant, provides a scenario involving moving data between two similar tables with slightly different column names. He shows how he prompted the AI to create a new stored procedure based on an existing one, and the AI successfully generated the code. Impressively, the AI also identified a potential bug in the original procedure and explained its reasoning before generating the new, functional code. The generated code successfully transferred the data as intended, showcasing the potential of LLMs in code generation.

The code is on GitHub here:  https://github.com/anovick/TSQL_CodeGen1

Take a look at the video: https://www.youtube.com/watch?v=G7eHQKerVMk

Here’s a transcript of what I said: 
Hi, I’m Andy Novick and today I’m going to show you a simple example of using an AI large language model (LLM) to generate T-SQL code it’s a pretty simple problem. 

i’m a SQL Server consultant, been around for a while, wrote a couple books a long time ago, and I’ve got an email address and a website the task we’re given is to generate TSQL for an ETL.   We already have code that’s sort of what we’re going to write: we have a table ETL_source_A, it’s got a few columns, the code brings data into the ETL_destination table.  Now, we’re given a new table ETL_Source_B.  The new table also has a batch ID column. The column names are similar to the ones in ETL_Soruce_A but with different names and the same data types  Our task is to write the store procedure that moves the data from ETL_source_B into the ETL_destination.  This task would be very easy for you and me,  so let’s do it with the AI now..  I’m going to flip over to some TSQL and show you some of the database objects.   LIke the Attribute table, which is just the numeric attribute ID.   Then ETL_destination table ,ETL_source_a table, a lookup function just for convenience, and the procedure. This is not the world’s greatest procedure it was based on loosely on something I’ve written before and it has a loop that’s not the greatest thing, but it’s a simple doesn’t take very long to run in practice.  We see that there’s nothing in the destination table.  Here I show the attributes like pressure and kilowatt hours. 

Next I show the source data. for batch one and the old code.    Let’s just run the old code see it gives us 100 rows in our destination table.  Next flip over to the AI.   Instead of showing you the AI in the prompt that I’m going to give the AI in the browser window let’s go through it here where it’s nice and large so I’ll read it to you:   

In the ETL_process_AandB.txt file there is a T-SQL stored procedure named ETL_proc_by_hand_source_A that loads data from ETL_source_A into ETL_destination. Please create a similar procedure named ETL_proc_Gen_source_B that loads data from ETL_source_B into ETL_destination. The column names are not identical, but are similar.

i tried to be very explicit.  It’ very simple. It’s kind of a spec. I guess that’s the kind of thing we might get as a spec ification.  Let’s take a look at the AI generating the code.  The AI I’m going to use is Grok 3, which is my current favorite. We’re doing this in April of 2025, and AI is changing week by week. I’ve tried some of the others, this one gave a really nice answer.  I put pasted my prompt in.  Then I attached the file with the existing code.  I had to use a TXT file instead of a SQL file because the user interface of Grok didn’t like the SQL extension.  Ii’m not going to make you wait and watch it because it took a minute and 56 seconds to run so let’s just look at the answer.

It starts by summarizing the problem, restating the problem, it’s got the existing procedure.  It talks about the loop, it just loops over iterates over the attribute name. Here’s something interesting:

However the original procedure has an potential oversight the insert statement does not filter by attribute ID meaning it inserts all rows for batch ID with the attribute ID of the current loop iteration which could lead to incorrect data mapping

It found a weakness in the code and, in fact, had a batch contained more than one attribute ID, which the code seems to anticipate, that would have been a bug.   Then it goes on to say

for accuracy I’ll assume it’s an unattended and correct it in the new procedure but I’ll align it with the similar procedure requirement by maintaining its structure

That’s, actually, pretty responsive. It goes on to do some analysis show us some analysis that it’s done design the new procedure and then it gives it to us and I’ll  just grab it with this button go back to SSMS, Let’s paste it.  In this case it didn’t give us a USE statement and it didn’t give us a SET QUOTED_IDENTIFIER.   Let’s just execute it.  We already executed the old proc.  We have some rows in ETL_destination,  we’ve got rows in ETL_source_B for  thepressure attribute,  and we can see that there are no rows in ETL_destination for pressure.  Let’s load them and see if they’re there.  Now there are 99 rows, and there’s our row counts so it did the job.

It was a simple job, it did it pretty well, found the bug.  Other As I’ve tried did more simple work, but maybe  I haven’t worked with them quite as much, and I’m sure they’re all changing, so “your mileage may vary”

i put all this code up on GitHub, including the prompt and including a print out of the uh page from Grock and um you’re welcome to take a look at them and I just like to say thank you for coming email me with any questions you have or put them in the comments thank you for watching i’ll see you sometime on YouTube.