Skip to content

Stedman SQL Podcast Sn 2 Ep 24 The Lean DBA

Stedman SQL Podcast Season 2 Episode 24 The Lean DBA

In this episode, we dive into “The Lean DBA,” exploring how process improvements can streamline your workflow and boost efficiency as a database administrator. Discover time-saving SSMS tips like Block Mode Select, dragging table/column names, using “GO” for multiple query executions, and powerful hotkeys (e.g., F5, Ctrl+M, Alt+F1). Learn how to display results in a separate tab for easier viewing, set up a Ctrl+3 shortcut for quick SELECT TOP 100 queries, and use sp_help with Alt+F1. We also cover bulk indenting, displaying line numbers, and leveraging Registered Servers for multi-server queries. Plus, get insights on the Database Health Monitor’s Quickscan Report and DBAssistant. Finally, we discuss the role of AI in the DBA world—featuring tools like Grok, ChatGPT, and Copilot—and why embracing AI is crucial to stay ahead. Don’t miss these practical tips to become a leaner, more efficient DBA!

Podcast Transcript

Steve Stedman  00:16

Hey everyone, and welcome to this week’s episode of The Stedman SQL podcast. We’re in season two. This is episode 24 and I’m your host, Steve Stedman. Around the time that this podcast airs the database health monitor, version three should be released. And if you haven’t seen what’s happening with the new things we’re doing in database health monitor, check out our previous podcast that we did on database health monitor. We’ve got about six months of development work on new features and things that are have gone into this version, so please check that out. I’d like to welcome all of our listeners to this podcast. Our listener base continues to grow week over week, and we definitely appreciate everyone listening. So if you’re listening and watching on YouTube, please click that like and subscribe button so you get informed of more of our podcast coming up. If you’re watching on other platforms, keep in mind that I think YouTube is the only platform we have that has video where the others are just audio only.

So this week’s topic is the Lean DBA and how process improvements can help make things more efficient. So let’s go to share my screen, and we’ll take a look here. All right. So as we’re going through the demo, I’m going to be sharing my screen. But first, let’s talk about the whole Lean process. So the whole concept of Lean DBA is something I came up with about 15 years ago where I was working for a company, and there was a local company that was pushing the concept of lean, and they did tours and things like that of their factory. And lean is really like a manufacturing thing where the idea is with Lean, everyone in the company is trying to figure out, how can continually make process improvements. Imagine if you have a factory and you’re making widgets, and you have 50 people involved in doing those widgets. If all of those 50 people can figure out, how can I make one small process improvement today that might save 10 seconds off of each widget, well, that makes the company more profitable, that makes you more productive, and that makes things run smoother, so or you get more out the door. And the what it really comes down to is the fact that the people who are doing the work are really the ones who are the best to figure out, how can I make things a little bit faster or a little bit better than what they were yesterday? And you sometimes I see where somebody will hire a consultant to come in, and usually the what that involves is the consultant will work with the people to figure out how those people can make things faster.

What I’ve done with the Lean DBA concept is taken that same philosophy, but instead of an assembly line where we’re making widgets or whatever the product is, it’s about how much we’re getting done in as a DBA on a daily basis. So for for instance, one of the things that after working on this whole lean DBA concept, it just drives me crazy, anything that I have to spend like hours doing editing in SQL Server Management Studio and things like that. So let’s take an example. An example is I was working with a client, and they had a process where it was taken an hour or two on a quarterly basis to do a restore of their production environment into dev so their dev database was kind of up to date. And then that involved this process of dozens of scripts that with different places that you had to go in and edit and replace and change backup file names and change database names and do all that kind of thing to do the Restore. And in fact, there was multiple clients that had the same thing. It was interesting because, as we started looking because as we started looking into this, one client had it, and then the same thing popped up with two other clients’ similar need. What we did is we had George, one of our team members, he created a process to go out and or a stored procedure to go out and grab the latest backup for a given database and restore it as a different name. Specifically to restore it to be used as a dev database. It could be restored as a dev database on a production server, or a dev database on a dev or staging server, things like that. Anyway, we went through this, we probably spent, gosh, I don’t know, 25-30 hours building that process, but that 25 to 30 hours was a one time investment that then gave us a tool that we could take a two hour process and trim it down to well, 15 to 20 minutes, and then next time we do it, we’ll figure out how to get it down to five minutes, and every time we go through it, we make it a little bit faster and a little bit faster. Now we’ve taken that script that George created in that example, we’ve deployed. We’re using it at multiple clients, and it’s saving a ton of time there.

So really, the concept of Lean is figuring out what are those things that bog you down or slow you down in your process, and figuring out how to make those things go faster. So what we’re going to do on today’s podcast is talk about some tips and tricks and things that I have done in order to sort of speed up my process, and we’ll see what we can do there to hopefully everyone can learn a little bit and improve their process. So one of the things that we do a lot of at Stedman Solutions, is we do mentoring, and mentoring is where we’re kind of doing pair programming, or pair working together, where a mentoring, you pay for a couple hours of prepaid mentoring, and then what you do is you get time with me or one of our team members, where we’ll do a teams or a zoom call, and we’ll help you through, help you through learning what it is you need to do on a specific task. And one of the things that I don’t know is drives me crazy, and I always try and help people with as we’re doing that mentoring is when somebody’s doing some process that they could do way, way faster.

And an example of that is like commenting out code. So for instance, right here, I have this test database set up, and I have this chunk of code here where I’m going to drop a table, and then I’m going to recreate the table, because I’m just using it for testing purposes. Well, one of the things that I’ve found working with people is that oftentimes people will use that dash, dash comment like we’re seeing there, and they’ll go through and painfully delete all of the comments like this in order to put something back in, where the reality is, you could do this a whole lot quicker if you just highlighted the whole thing and hit Control K, Control C to comment it, or you hit Control K, control you and Management Studio to uncomment. So no matter how big your block is, it’s really quick to be to comment it out doing things like that with the hotkey, control K, Control C, or for comment or control K, control you for uncomment. Now with that, that’s one of those things that I try and teach people as we’re doing that mentoring process is don’t pay me to sit here for minutes while you’re doing this deleting of comments like that. I’ll show you how to do it quicker and faster. So that’s one of those things that and my rating is, if it can save me 10 seconds in some process that I’m doing, it’s worth taking a few minutes to figure out a better way to do it. So highlighting and being able to comment out. Control K, control U for uncomment. Control K, Control C, for comment worth every second it saves there.

All right, so moving down the list, next is there’s this concept of the block mode select. And this is one of those things that I find that whenever I use the keyboard, it slows me down when I’m working in Management Studio. So we have this block mode select that lets you do things. And what I’m going to do is I’m going to hold down the ALT and the shift key and start highlighting here. And notice that I’ve now highlighted this insert into block. And let’s say I was working on the code and I wanted to change it. I mean, it doesn’t make any sense, but if I wanted to just highlight that block and type select star from, I could then, and then I’d go delete the end of it. That is something that with that bulk mode select, it lets me type on all of those lines at one point in time. But we don’t want to do that. We want to do insert into but let’s go back and bulk selected again, and let’s just pretend that they these had originally been

typed in lowercase, and I just made them lowercase by doing Control Shift L for lowercase. And because SQL syntax generally you’re expecting uppercase for keywords, or at least that’s the way it’s documented. And as some people say it makes it sound like DBAs are always screaming because they’re in all caps. But if we wanted to make it all caps, we do Control Shift U to put it uppercase, Control Shift L for lowercase, and it switches it back and forth there using that block select. It’s really handy. But let’s say that we added we’re looking at this and we said, Okay, well, we’ve got all these orders that we’re inserting with these about dozen insert statements, and we realized that, okay, we goofed. These first five were not supposed to be FedEx or not five. That’s more than five there. But this first block was not supposed to be FedEx. They were instead supposed to be ups. And then these last one was last three were supposed to be USPS. So I’m going to do Control Shift arrow to block select and change them to United States Postal Service there, so you can see how much faster that would be compared to trying to go through and edit each line, each line, one after another. So that block SELECT mode is really pretty cool.

And then the other thing you can do with it is you can do interesting block, select, copy and paste stuff. You can go in here and say, Okay, well, let’s say I got these wrong and we wanted the order date. Let’s say we wanted order date to be the second column inserted, not the first column. I could go in and select that whole list, hit Control X, chop out order date, move my cursor over to where I want it to go. I’m going to put it right here and paste in order date at that point. So a lot of sort of handy stuff in SQL Server Management Studio there to allow you to quickly select and move things around. And then, of course, Control Z is one of those that for undo I use all the time.

Now, another one that’s handy is, let’s say you’ve got this Select star from orders down here, and I could go in here and I could type in, let’s say I just wanted three of the four columns. I could go in and type order ID, order date and shipping method and in here. But there’s an easy way to do that, because I know I’m going to goof it up and I’m going to get sloppy on how I type there. So if I go back to this table called orders, and I just right click on the word columns in the tree view on the left side, drag the word columns over here, and you’ll notice that it’s not dragging the word columns. It’s actually dragging the actual column. So if I wanted only select three of the four columns, I could drag that over, go in and highlight that and select that way. That’s one of the quickest ways in order to be able to get column select mode, or to get specific columns into your SELECT statement. There’s some other real handy ones here. We already talked about, control K, Control C, for comment out uncomment. We can make things upper and lower. The other one is sometimes, like, after you create a table and your IntelliSense hasn’t updated, so you’re getting, like, the squiggly line showing up under stuff to show that it’s not there. If you hit control shift and R that tells IntelliSense to go and refresh. And that’s a real handy hot key to have there as well.

Another thing that we’ve that I use a lot is the Go statement. And the Go statement, I think most people have used SQL server at all. They know the Go statement is a batch separator and it’s used in SQL Server Management Studio, or it can be used in some other tools to separate it out. And it says, basically, take the things between the set of go statements and run that as a single batch, and then, because there’s no go statements between these inserts down below, it runs that whole thing as a single batch. But let’s say I want to do this insert here, and I’m trying to build a test table out to test some load or something like that, and I want to put in 1000 rows into that table. I can just take that INSERT statement and say, Go 1000 and it says, Take That previous batch up to the previous go statement or whatever is highlighted there, and run it 1000 times. So when we execute that and we go look at the messages window. We can see one row affected. And this is going to run for a little bit until all 1000 rows have been inserted. And there it is. It finished, 1000 rows inserted. And we go back over here, and if we select it from that table, there’s now 1000 rows more than there were there before. So the Go statement with a number after it is basically saying do a loop that just repeats that previous chunk of code that many times. Super handy when you’re trying to well for a lot of different reasons, but I use it a lot when I’m trying to fill out like a demo or sample database with test data, stuff like that.

There’s another feature which is kind of handy, which is the display results in a separate tab. Normally, when you run something in Management Studio and you hit execute, oh, by the way, f5 is the hotkey for execute. If somebody wants to run a query and they’re using their mouse to go up here and hit execute this way, that’s just too slow for me. So f5 is the hot key I use for execute, and you just hit f5 and it runs your query. But normally when you do that, when you run a query, it splits it where your query results appear down below, but there’s an option, and let’s go back to the select statement here, where we have our editor still in full screen mode, our results in another tab, and then our messages window showing up here. And if we had execution plan, it shows another tab, but that shows up as the results in a different window, which can be really handy for demo purposes like this. But also, if you’re on a small screen or something, and you’re fighting with the split screen there, it’s a handy way to be able to see the full grid. And the way you go to get to that as you go into tools options, and then you go into query results SQL Server, General, or here it is results to grid, and it says display results in a separate tab. If you get rid of that, then it makes it go back to the half and half display that you would normally. See kind of out of the freshly installed version of SQL Server Management Studio.

Okay, so moving down the list, then other things that are handy is the SP help function. So you can use SP help to find a lot of interesting things. But by default, SQL Server Management Studio is set up so that the alt f1 key is set to run SP help. And if I hit, hold down my Alt key and hit f1 well, it runs SP help, just kind of on the whole database. But where it gets interesting is if you select a table name, like orders here, and I run it, alt f1 for SP help, it brings up information on here’s all the columns in the table. Here’s the identity value. There’s no row column good. It’s on the primary file store. There are two indexes here and the index keys. So one of the things that I always I mean indexes are poorly named, and you can’t always guess what columns are in an index by the by the name or the title of the index. So this is a real handy way to go and see what indexes are on a table and what columns are being indexed, and then what other constraints are on the table. So all you have to do to use that is select an object name, highlight it, and then hit control f1 and it’ll bring up SP help on that handy, quick thing to use there. Another thing we can do is go back to bulk indent or unindent. Let’s say you’re working in your code, and I’m going to select this batch, just part of the batch of insert statements here, and I’m going to say pretending, for whatever reason, these need to be indented. I can hit after they’re highlighted, I can hit Tab, and it indents the whole block all at once. If I want to unintended it moves it back out. And what I’ve seen, when people are trying to put code into a stored procedure, they’ll oftentimes come in and do this manual process of click and click and click all the way through. And Oops, I missed one. I got to go back up and fix that. Where to use the it’s not even block SELECT mode. It’s just regular SELECT mode to highlight a bunch of rows and tab to indent all of them at once, or Shift Tab to shift them back out. Pretty handy, quick way to do things.

Another thing that I find that saves a lot of time when I’m working either pair programming with a team member or mentoring with a client, is line numbers in here. Let’s say we’re working on this together, and I want to refer to this insert statement down at the bottom, or maybe these are different insert statements. I want to say, well, look at the third or the fourth or the fifth INSERT statement here. Well, that can get confusing, but instead, if I just say, look at line 34 it’s a lot more useful. Or look at line 40, it’s more useful by default. SQL Server Management Studio does not have line numbers turned on like this. And to get to the line numbers, you have to go into tools options, and you go into text editor and then expand it for transact SQL, and then go to general and you get the option in here for line numbers. You can turn it on or off. Oh, I should say, when you turn line numbers on or off, it’s immediate in Management Studio, it happens right away. But on the previous setting about how you’re changing the Results tab, you’ve got to close your tabs that are open and reopen them in order for that to work.

So anyway, so next registered servers. This is one of, gosh, one of my favorites for a way to, like quickly run and run access different servers. So to get to registered servers, you have to go to the View menu and just click on the registered servers here. But once you’ve done that option, it then shows up over here as a tab. Sometimes it’s a tab on the bottom, sometimes the tab on the right, but you can go in and set up a bunch of test or a bunch of servers that you regularly connect to. I have one client that we work with that there’s over 45 servers that were regularly connecting to. So with that, we use registered servers and set it all up so we can just go in and we don’t have to remember all of the information. So to add a server, you would right click on the folder where you want it to go, and you’d say new server registration. And from here, you put in the server name, you put in your credentials, and then you can test it to make sure it’s good. And then you can save it. Once you save it, registered servers show up in the list here. So let’s say I want to go to this server called multi SQL with the instance of SQL 2016 it’s here. I can just double click on it. I jump there. I’m logged in, and I can go see, here’s the databases that are on there. Let’s disconnect that one, and then we’ll go over to registered servers. And what’s really cool here is to be able to run queries across multiple registered servers. If I had a query that I wanted to run against all my registered servers, I could click on local server group and do a new query, and it would run across all the servers in the list. I’m going to do it with a smaller batch. I’m just going to take the server called multi SQL, I’m going to hit Control N for new query, because anything else is too slow for that. And now you’ll notice that when that query window opened, the tab down below is shown in pink, and it says connected 16 out of 16, and it says multi SQL, and it’s in the master database, whereas on a previously it said your server name, but here it’s the group called multi SQL. Now, what happens if I run a query here, I’m just going to say, select at server name, and when I run that query, it goes out and it runs it that one query on all 16 of these servers, we can look at the messages window and it says this server had one row affected, that one run, one row affected, and so on, and you get the results back. But on any results that come back, it puts the server name in the front of it, so you know which server it came from, and then it puts the actual wellness. This was the results that I selected.

So let me change the query. Instead of just selecting at server name, what if we select? And I’m going to do that I know this is going to fail, and I’m going to show you why select star from sys dot databases. Now between SQL Server 2008 and SQL Server 2022 Microsoft changed the columns that you get back from sys dot databases. So one of the things that when you run a query using the registered servers here, across multiple they all have to have the same result set. So if we run across sys dot databases, we can see in the results, yes, we got some results here. 2008 2008 Express and 2008 r2, well, it turns out that when it tried to run those, those were the first ones in the list that ran. And then they established what the row set was going to look like coming or the column set was going to look like coming back. And then all these other servers failed because they had a different number of columns. So what we can do in that case is, let’s say we want to know just I want to know what databases are on all the servers. If you go here and do name, SELECT name FROM sys dot databases, and now there were no errors on that one that ran across all the different SQL servers and gave me a list of all the databases on all these test SQL servers. So imagine if you have some kind of a maintenance script or something like that, that you want to deploy across 50 SQL servers, and you normally have to go open 50 different windows to run it. Don’t do that. Use the use the registered servers area to do that, and it’s much more efficient, and it’s a quick way to do it now.

Short story. Just 20 minutes before starting this podcast, I was working on Database Health Monitor bug where a query was failing on SQL Server, 2008 and 2008 are two but I wanted to test it to see how it was working, and test it across all of the databases. So what I did is I took the query, paste it in here, ran it, and from there I could see that it was failing. So what, what was actually in the code, was the if statement. IIf name = master. Then let’s go with the output would be, yeah, yes, comma, no. I mean, I’m just totally sort of mocking up something similar. But the problem was somehow the IIF statement in line if got in there and it was failing on the older servers. So now, if I run this, you can see on 2008 r2 2008 Express and 2008 it failed, and we get red on that, but the results showed up functioning and working on everything that was on 2012 and newer, because 2012 was where the IIF statement was introduced, but it’s failing on 2008 or two. So that showed me it’s a quick way to test and make sure my code worked across all those different servers. So a lot of the times, if I do a blog post where I have a specific query, I’ll say what versions of SQL Server that works in and the way I determine that is I just go in here, open multi SQL and run it across all those versions and see where it works or where it doesn’t.

Okay. So next on the list is Database Health Monitor. And Database Health Monitor is a another speed improvement, performance improvement that I consider it a lean style improvement, because around the time I learned lean was around the time I started building Database Health Monitor. So everything I’ve built in here has been done to make things faster for working with lots and lots of servers. So like here, if we go and look, I can click on one of them, one of my test servers, multi, SQL, SQL, 2020, or 24 15 and I can go in there and see something like, Okay, we have the quick scan report. That’s a report that takes a moment, it goes out and runs and it finds all of the things on that server that need work. Now let’s say I want to run that same one again, SQL Server 24 or the next one in the list. I hit Control down arrow, and there’s a lot of things that have been built in here just to make it quick and easy to access and run all of these things in order to save you time.

So one of my biggest gripes is when something is slow, something takes me a lot of time to do something I will oftentimes go and figure out ways to make it faster. Now, the next item on the list that I wanted to take a look at was AI. Now there’s a lot of interesting stuff going around, going on with AI, and I think that using GROK, using chat, GPT, using copilot, they’re all great tools. I think that copilot is integrated in the newer version of SQL Server Management Studio for 2025 and as well as in Visual Studio. But I think as far as running something outside of Visual Studio, GROK is really good. So what I find is that if I go into GROK, and this is through my X or formerly Twitter login, I can go in here and, gosh, we could do a whole episode just on maybe we’ll do that just on AI. But for now, I’m going to show you a quick thing here. So you always want to say what you want done. Create a procedure in what language, T SQL, that will calculate 100 numbers in the Fibonacci sequence. Okay, just a quick thing. We run that query, and what it’s doing now is it’s going and figuring out, how do I build this in T SQL? So here’s a calculate Fibonacci sequence that comes back. And yeah, it looks like a pretty good function to do it. It looks like it would work. I mean, I know I would probably do it using a CTE just because I’ve done that demo so many times with my CTE book or CTE class. But here’s another way to do it, and then it works really well. A similar thing you can do. I did the same thing earlier with copilot, and let me bring that over on screen here, and we can see Fibonacci sequence, slightly different, but a very close implementation of similar code.

So what I’d be curious about, I mean, there’s a lot of other AI tools out there. So why don’t you get back to me and let me know what AI tools you’re using and what you like, because there’s a lot going on there. I think that what we’ve covered is a lot of things that can save you time and figure out how to make things go faster for your daily process. And I think that using Management Studio, a lot of tips and tricks in there, using Database Health Monitor, another great way to do that. But AI is coming. AI is the future. There are a lot of people who just want to put their head in the sand and say, AI doesn’t exist. But I kind of look at that like the difference between a manual typewriter and electric typewriter, and then eventually a computer. I mean, it may it really change the way the world works with that type of an innovation, and I think that AI is going to be the same way. And there’s a lot of businesses out there that are really looking at, how can I be more productive, how can I be more lean, how can I be more effective with my workforce, using tools like AI, using tools like what I’m doing, what we’re doing with management studio, all of it, figuring out how to be faster and better than you were yesterday. And it really comes down to, how can you do like, a 10 second improvement and this Fibonacci? If I needed to go and actually create a function to generate Fibonacci sequence, yeah, I would have done it. It would have probably taken me 10 minutes to do it. But here they get it back in copilot or GROK in just a matter of seconds. Now, the thing you do have to remember when you’re using AI is it is not perfect, and there are some things that just plain don’t work. So don’t ever blindly just take AI code and use it. You want to take it and use it and manipulate it, manipulate it into what you need to function, to do your job and for it to work well, all right?

Well, I think that wraps things up. I guess at this point I would like to ask, what kind of things do you do to make your job faster? Please let me know. Using SQL Server as a DBA, what kind of things are you doing to make your system more effective, to be better every single day. The point here is, if you’re not, you need to be, because someone else will eventually come along and take your job. You always want to be improving, and you always want to be getting better and faster, and that’s going to keep you ahead of the next person in the job search or in the next time somebody’s up for a promotion. So always be improving. The key process behind Lean is to keep improving and keep getting faster and better every single day. So at this point, thank you for tuning in our podcast. We’re currently doing it about every other week, so check back in a couple weeks for our next podcast. And I’m Steve, thanks for watching. Have a great day.

Getting Help from Steve and the Stedman Solutions Team
We are ready to help. Steve and the team at Stedman Solutions are here to help with your SQL Server needs. Get help today by contacting Stedman Solutions through the free 30 minute consultation form.

Contact Info for Stedman Solutions, LLC. --- PO Box 3175, Ferndale WA 98248, Phone: (360)610-7833
Our Privacy Policy