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.
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.
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:
- Prepare your statement in the editor.
- Expand the table containing the list of columns you need. In this example, we’ll use the Customers table from my sample database.
- Click the Columns heading and drag it to the editor. Release the mouse click at the location where you want the columns to appear.
- The list of columns is inserted into the editor in the desired location.
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.
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.