SSMS Tip: Drag Table Columns to Editor

This post looks at how to save time using a feature of SSMS: Dragging columns to the editor window.

The Problem

A need often arises to list all columns in a table in the editor. Take an insert statement for example, which often looks like:

Insert into SomeTable (column1, column2, column3...)
Values (value1, value2, value3...)

It can be really tedious to type out all of the columns when there are many columns in a table. Code completion does help, but manually typing all of the column names still takes a long time.

The Solution

As a developer that often works with SQL Server databases, I worked with SSMS for several years before I found out about this extremely handy feature. You can drag the columns from the explorer to the editor. Here are the steps:

  1. Prepare your statement in the editor.

Statement ready for columns

  1. Expand the table containing the list of columns you need. In this example, we’ll use the Customers table from my sample database.

Customers table expanded

  1. Click the Columns heading and drag it to the editor. Release the mouse click at the location where you want the columns to appear.

Drag columns heading to editor

  1. The list of columns is inserted into the editor in the desired location.

Columns inserted

Now I can finish my insert statement. I remove the primary key, as I want that to be auto-generated, add square brackets around name and address to specify these are column names and not reserved words, and add the remaining values I need to insert.

Statement completed and execute

Conclusion

Even for a small, simple example like this, dragging the Columns folder to the editor to automatically insert the column names can save a lot of time. The amount of time saved grows even more when the tables get much larger and more complicated. This can also be a very handy way to get the list of columns to copy into a text editor like Visual Studio Code for reformatting into class properties, for example.


The postings on this site are my own and do not necessarily reflect the views of my employer.

The content on this blog is for informational and educational purposes only and represents my personal opinions and experience. While I strive to provide accurate and up-to-date information, I make no guarantees regarding the completeness, reliability, or accuracy of the information provided.

By using this website, you acknowledge that any actions you take based on the information provided here are at your own risk. I am not liable for any losses, damages, or issues arising from the use or misuse of the content on this blog.

Please consult a qualified professional or conduct your own research before implementing any solutions or advice mentioned here.