Product articles SQL Prompt SQL Code Snippets
Quick SQL Prompt tip – using the CDB…

18 November 2016
18 November 2016

Quick SQL Prompt tip – using the CDB snippet

SQL Prompt includes a number of snippets by default that can help you quickly write T-SQL code. These are templates of code that users use regularly. One of the more popular snippets is the ‘cdb’ snippet that helps with quickly creating a new database for development work. This can also be used to ensure production databases are created with the standard settings that your organization may have.

Let’s examine how this snippet works. If I type cdb, I get the popup with this snippet:


The code for the snippet is shown to the right, and as you can tell, it’s a lot of code. Three characters and I’ve saved over a hundred keystrokes when I type TAB. Once I do that, I get the code in my window, but I also get my cursor at the point where the database name would be typed:


This is another feature of SQL Prompt. The parameters that are in the snippet can be placed in multiple places. In this case, the database name is also used for the virtual and physical file names. I’ll type QuickTest and then TAB. I now see this:


If you look through the code, you’ll see I have the database name included in the virtual file names (quicktest_data and quicktest_log) as well as the filenames (quicktest.mdf and quicktest.ldf). I would certainly add additional filegroups/filenames if I wanted by editing the snippet. I could also easily uncomment out some of the database settings if they were appropriate for my test databases.

At this point, I could execute this snippet and have a new database that allows me to test some code. Four keystrokes produced all this code.

There are a number of built-in snippets for SQL Prompt, and many of them are very simple, but they can greatly speed up your T-SQL coding if you learn what they are. I’d suggest you download our SQL Prompt Quick Reference Guide and practice using a few of these shortcuts in your code.

I also cover a few other snippets including SSF (SELECT * FROM) and II (INSERT INTO) in the new series of #SuperSQLTips videos. Take a look and you’ll find handy tricks from other Data Platform MVPs and SQL Server experts too, not just on snippets, but a host of tips and tricks to help you write SQL more quickly and accurately:

If you’re not a SQL Prompt user, download a free trial and see how much more productive you can be writing code every day.

Like this? Share it with other SQL professionals using the social sharing buttons below. Simply tweet: I’ve just read @way0utwest’s blog on using the CDB snippet with #SQLPrompt – see the #SuperSQLTip at

Tools in this post

SQL Prompt

Write, format, and refactor SQL effortlessly

Find out more

You may also like

  • Article

    Quick SQL Prompt tip – script objects as ALTER in two clicks

    Working in a large database can be difficult at times. While many of us might learn the meanings and definitions of most objects, it’s easy to forget the exact ways in which some objects work, or what the behavior is in certain calls. This is one place where having tools that assist you like SQL

  • Article

    Finding Correlated Rows Using EXISTS or COUNT

    Should you always use EXISTS rather than COUNT when checking for the existence of any correlating rows that match your criteria? Does the former really offer "superior performance and readability". Louis Davidson investigates.

  • Article

    The '= NULL' Mistake and other SQL NULL Heresies

    The SQL Prompt Best Practice rule checks whether a comparison or expression includes a NULL literal ('NULL'), which in SQL Server, rather than result in an error, will simply always produce a NULL result. Phil Factor explains how to avoid this, and other SQL NULL-related calamities.

  • Article

    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

  • Forums

    SQL Prompt Forum

    Write, format, and refactor SQL effortlessly