Dragging a name from the object explorer to a query window
8May 13, 2013 by Kenneth Fisher
In the same vein as Steve Jones’ series on Customizing SSMS this is a fairly basic trick, but one that not everyone appears to know.
A fairly standard layout of SSMS looks like this.
If you drill down, to say the table list, you can left-click and drag a table name from the object explorer to the query window. For long object names this can be a real life saver!
This trick will work with almost every object name in object explorer. One notable exception is the instance name. I have no idea why and I could wish that Microsoft would eliminate this exception in the future as it would have come in very handy on more than one occasion. In the mean time the ability to drag and drop the name of a Table, Column, Constraint, Index, Stored Procedure, Function, Login, or even a Job (to name just a few objects) has come in very handy time and time again.
Update
I was watching a SQL Skills insider video (if you arn’t one you should be) and was shown that you can drag the list of columns as well as individual columns. This appears to work for the groups under an individual table but not anything else.
You forgot to mention that you can also drag many of the actual nodes to get a comma delimited list of elements in the node. hmmm….an example would explain better.
Drag the node ‘Columns’ (under a table or view node) and you get a comma delimited list of the column names. (Same works for indexes, keys etc. but columns is certainly the most useful I think.)
That certainly would have been good to mention, if I had known you could do that! Just goes to show I guess that no matter how much of an “export” you consider yourself there are plenty of “easy” things that you might have missed along the way.
I did notice upon trying out what you suggested that it only seems to work on the lowest collections. For example it worked on columns, but not on tables. I also tried it out on parameters (within stored procedures) and it worked there too. And that would be another of the potentially more “useful” options.
Thanks for the additional tip!
Thanks for the tip. This is great and needed information.
Glad ya’ll like it 🙂
Excellent post, thanks!
[…] if there are a large number of columns it’s a real pain too. (Not that you can’t just pull the column list from the object explorer.) So how do we do it without specifically listing all the columns? Well the source of this post was […]
This doesnt appear to work if the column name contains a keyword eg “Date”, “Primary” etc
Of course you can drag the columns to Excel and add brackets – but that stops it from being a 1-click solution..
Hmm, I’m going to have to play with that 🙂