14 September 2016
14 September 2016

Quick SQL Prompt tip – why you should expand the wildcard

One of the great things about SQL Prompt is that it quickly removes the need to use so many keystrokes. That’s helpful and handy, but to become a really efficient T-SQL coder, you’ll want to practice incorporating a few tricks into your routine.

Here’s a good one. Often I run into tables and can’t remember all the columns. One trick many people use is to type SELECT *, which gives you a quick look at a table, but isn’t what you want in production code. Instead, you’ll want to specify which fields you need to return.

When I type SELECT, I don’t get a list of columns, but a list of tables.

SQL-Prompt-1

I can pick one and then get a list of columns, but that’s slow.

SQL-Prompt-2

Instead, what I do is use the SELECT *. However, if I place the cursor after the *, I get this:

SQL-Prompt-3

If I hit TAB, I’ll then get a list of columns added to my query:

SQL-Prompt-4

Easy for this query, but for large tables and a few joins, it can be really handy. For example, look at this query:

SQL-Prompt-5b

If I expand the wildcard by typing TAB with my cursor after the *, I get this:

SQL-Prompt-6b

More fields than I need, but I can easily remove the few I don’t want and get to the actual query I need.

SQL-Prompt-7b

Using the wildcards is handy, and one of the ways you can quickly structure large queries without worrying about finding specific fields within each table.

Check out this quick video to show you SQL Prompt expanding the wildcard in action:

Or you can use one of my other SQL Prompt tips, the Column Picker. Check out this video and the rest of the #SuperSQLTips from other Data Platform MVPs and SQL Server experts. I’m sure you’ll find something really helpful for your everyday work.

Like this? Share it with other SQL professionals using the social sharing buttons below. Simply tweet: I’ve just read @way0utwest’s blog on expanding the wildcard with #SQLPrompt – see the #SuperSQLTip at rd.gt/2ctbpo9

Tools in this post

SQL Prompt

Write, format, and refactor SQL effortlessly in SQL Server Management Studio and Visual Studio.

Find out more

Share this post.

Share on FacebookShare on Google+Share on LinkedInTweet about this on Twitter

You may also like

  • Article

    How to Test SQL Server Functions and Procedures using SQL Prompt

    Phil Factor shows how to use the "Script As Insert" feature in SQL Prompt to refactor a table of "input and expected output" values into a simple test harness for stored procedures and functions.

  • Article

    SQL Prompt Tip: how to control when the suggestion box pops up

    By default, SQL Prompt shows code auto-completion suggestions automatically, and continuously. Phil Factor shows how to control this behavior, for the times when you need it to be a little less intrusive, such as when working through more intricate coding problems that require careful thought.

  • Article

    Driving up database coding standards using SQL Prompt

    A strategic view of how a development team can use SQL Prompt to establish and share coding standards, through code analysis rules, formatting styles and code snippets.

  • Article

    Finding code smells using SQL Prompt: old-style join syntax (ST001)

    There are no advantages to using old-style join syntax. If SQL prompt identifies its use in legacy code, then rewriting the statements to use ANSI-standard join syntax will simplify and improve the code.

  • University

    Take the SQL Prompt course

    This Redgate University course takes you from installation all the way up to getting the most out of the advanced operations in SQL Prompt. As well as autocompleting your code, you’ll learn how SQL Prompt can help you with code formatting, object renaming, code analysis, and other useful tip and tricks.

  • Forums

    SQL Prompt Forum

    Write, format, and refactor SQL effortlessly