Have you ever driven your car out in the direction of your office by mistake when it was supposed to be a day off? Have you ever done things unconsciously because you are getting trained for something that is common? This is what I call as human nature and how our brain works. Our brain is a complex organ and it used patterns and preset paths of execution when it is pre-occupied. This is the path of least resistance and it may sometimes not be the best option too. In this blog post we will learn how to script out multiple objects in SQL Server.
If you are wondering why I am talking about this. Let me give you an example on a tool that I used almost every single day – SQL Server Management Studio (SSMS). I use the Object Explorer and multiple other windows that are available. I get intrigued how this tool works because there is something to learn or unlearn when it comes to working with SSMS.
I was talking with a junior DBA and he wanted to script out multiple objects. My initial reaction was to guide him and he would learn. I told him to do it using SSMS. After an hour he came back and told me it is not possible. It was important for me to show him how. I asked him to do the steps on my PC.
He opened the Object explorer and said he could right click each object and script out. He could use a wizard etc. But he said it was not an easy step. He claimed to have worked with some 3rd party tool in the past that did help him. But I insisted there is something he was missing and I did have an old trick that I wanted to show him.
I opened in the same window the “Object Explorer Details” (F7 shortcut). In this window, I selected multiple objects (based on where the cursor is in Object Explorer and showed how we can export the script.
As shown above, it is a simple script that got generated in one step and he was surprised it was hidden in SSMS. He was trying to use the CTRL, SHIFT keys on the Object Explorer pane to select multiple objects and it failed. He assumed now that it was not possible. He said he is going to explore SSMS further and there were areas that he was not aware.
Have you ever used this feature before? Been there with SSMS for years now. I find it handy and felt this was lesser appreciated feature.
Reference: Pinal Dave (https://blog.sqlauthority.com)