Tag: QuickTips

  • Quick Tips – SQL Prompt Stop the Yelling

    I love SQL Prompt, and think it’s a great productivity tool. Even before I worked at Red Gate, I love the tool and had a copy before Red Gate bought the technology from the original developer. Recently I’ve run into a few people that weren’t aware of some of the ways in which it can help you. This is a quick look at one of the ways I use SQL Prompt.

    Lower Case Keywords

    One of the things that many developers like is lower case keywords. If you examine some C# code, you’ll often find that they have keywords in lower case. For example, here’s a sample from MSDN.

    // versioning.cs
    // CS0114 expected
    public class MyBase 
    {
       public virtual string Meth1() 
       {
          return "MyBase-Meth1";
       }
       public virtual string Meth2() 
       {
          return "MyBase-Meth2";
       }
       public virtual string Meth3() 
       {
          return "MyBase-Meth3";
       }
    }

    When I’ve gotten projects from Red Gate, I see something similar.

    However, if I enter some code in Management Studio, by default, SQL Prompt will format it like this:

    prompt_aa

    Notice the upper case keywords. Personally I like these, but many developers may not. Fortunately there’s an easy fix. Access the SQL Prompt menu in Management Studio and select options (circled below).

    prompt_ab

    This will bring up the options dialog. Select the CASE item as shown below.

    prompt_ac

    On the upper right side, you’ll notice that you have drop downs for keywords, built-in functions and data types. By default these are all set to uppercase. However you have a number of choices.

    prompt_ad

    I’ll change mine to lowercase, click OK, and then reformat my code. I now see this.

    prompt_ae

    Quick and easy, and I can now read code that looks more like what developers are used to. Maybe I’ll leave things set like this…

    You can see a complete list of SQL Prompt tips at Redgate.

  • Quick Tips–SQL Prompt Formatting

    I love SQL Prompt, and think it’s a great productivity tool. Even before I worked at Red Gate, I love the tool and had a copy before Red Gate bought the technology from the original developer. Recently I’ve run into a few people that weren’t aware of some of the ways in which it can help you. This is a quick look at one of the ways I use SQL Prompt.

    Ugly Code

    It’s often that I’ll get code submitted at SQLServerCentral, or it will come in a demo from Red Gate, and it will look something like this:

    prompt_af

    This is actually code from Microsoft in the AdventureWorks 2008 sample database. It’s ugly and hard to read. In fact, I struggle trying to interpret code when I see it like this.

    Reformatting

    One of the things I probably do most often, after SSF, is reformat code so that I can read it. I have a few settings I prefer, but to apply them, I’ll click CTRL+K, then CTRL+Y and my code will get fixed.

    prompt_ag

    If I have invalid SQL, Prompt will throw an error and there will be a squiggle line under the offending sections. If I only want to reformat a portion of code, I can highlight it before hitting the shortcut.

  • Quick Tips – SQL Prompt with SSF

    I love SQL Prompt, and think it’s a great productivity tool. Even before I worked at Red Gate, I love the tool and had a copy before Red Gate bought the technology from the original developer. Recently I’ve run into a few people that weren’t aware of some of the ways in which it can help you. This is a quick look at one of the ways I use SQL Prompt.

    SSF

    I probably type SSF more than any other character combination in SMSS. With SQL Prompt installed, I usually quickly type “SSF” and hit “tab” and get this:

    ssf1

     

    SQL Prompt has expanded my “SSF” into “Select * From” and then popped up a list of tables in this database. I could down arrow to select one, or use the cursor, or start typing.

    This is a quick way to get data from a table back to your SSMS client without worrying about the columns or rows you need from a table. I use this constantly, though I’ve edited this command to return the top 10 rows only. Here’s how I do that:

    Snippet Manager

    There’s a dialog for managing these snippets of code, called the Snippet Manager. You can access that from the SQL Prompt menu

    ssf2

    Once you select this, you get a dialog that shows all the snippets installed on your system. I scrolled down to the “SSF” snippet that I often use.

     

     

     

    ssf3

    If I click the Edit button, then I get a small editor where I can paste in code or edit what’s there. In this case, I add the “TOP 10” keywords, and I also reformat the code slightly. I like my code formatted, so I ensure it’s formatted here.

     

     

    ssf4

    Once that’s done, I click “Save” and then “close” for the Snippet Manager. Then the next time I type “SSF” and tab, I get this:

     

    ssf5

      

    Note that there is an st100 snippet that does the same thing I edited with 100 rows, but I find ssf easier to type, so I just edit this snippet.

    I’d encourage you to play around with snippets, and also adopt this in your daily work. If you don’t have a copy of SQL Prompt, download the evaluation and I’m sure you’ll realize it’s worth the cost of the tool in time savings quickly.