Blog Post

Summarizing a Script with SQL Prompt

,

I have never used this feature, but someone was asking for feedback on Prompt, and I noticed  this in the menu: Summarize script.

prompt_summary_a

I had guessed that it might look at the code and give me some outline, which is what it does, but I wasn’t sure how it might work. I decided to try it on a few scripts.

I had a demo script for a customer, and I ran it there. I got what I expected, an ordering of various operations.

2021-03-12 08_10_22-SQLQuery1.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (65))_ - Microsoft SQL Server

Useful in some sense. I can see I cleaned up the CREATE with the DROP. However, I could also see that easily if I looked at the script. Depending on length, this might be helpful to remind me or let me see if I’ve dropped all the code I expected.

I picked a longer script from some of the Advent of Code stuff I’ve been slowly working on. In this one, there is some looping, as it’s a looping type of problem (to me). In this case, I see something more complex.

2021-03-12 08_14_16-day3.sql - ARISTOTLE.AdventofCode (ARISTOTLE_Steve (57)) - Microsoft SQL Server

Not a lot of information from the SELECTs, but I do see some looping. The actual code is a bunch of math changes, and I could have used SET, which might have helped here. This let’s me see that the code is more of a procedural construct, which looks like this:

2021-03-12 08_14_51-day3.sql - ARISTOTLE.AdventofCode (ARISTOTLE_Steve (57)) - Microsoft SQL Server

What about other types of code? I looked at a CTE, which wasn’t that helpful. I can’t see the base tables here, which isn’t useful.

2021-03-12 08_16_26-SQLQuery1.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (61)) - Microsoft SQL Server

However, in AdventureWorks, there is a procedure that shows me a TRY CATCH. In a long set of code, this might help me make sure I’ve actually included the CATCH, among other things.

2021-03-12 08_17_41-SQLQuery5.sql - ARISTOTLE_SQL2017.AdventureWorks2017 (ARISTOTLE_Steve (61)) - Mi

I’m not sure how useful this feature is, but it’s now in my mind to try a few times and see what I think. What is the outline and structure of my code.

If you have other ideas, I’m sure Redgate would appreciate suggestions. Otherwise, give it a try and let me know if it works.

If you don’t have SQL Prompt, it’s an amazing developer productivity tool, and we now offer it as a subscription, so you can try it for a bit longer than than evaluation without committing.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating