posted 7/6/2010 by BrianKnight - Views: [1856]
It's always funny when I go 12 years in this industry and don't know some basic trick about writing T-SQL until weeks ago. So, in today's installment of Doh' that's Cool, I wanted to share with you a trick I learned from watching another DBA (Patrick LeBlanc) recently and then said, "How'd you do that?!".
This trick will help you write queries much faster and hopefully get you out of the bad habit of typing SELECT *. To do the trick, simply open your query window in Management Studio. Then, when you want to list all the columns in your query, drill into the table in Object Explorer and drag the word "Columns" under your table name into the query pane. Every column name will come over with it, and save you the trouble of dragging single columns over.
Hope this helps!
Thanks for the shout out BK! Much respect
Cool!
A lot more easier than: Right-mouse-click > Script Table as > SELECT to > New Query Editor Window ...
Seems like a lot of people (me included) learn this "trick" on their own.
Thanks for getting the word out. Here's my blog entry when I learned my lesson.
http://michaeljswart.com/?p=299
Michael J Swart
Your brother showed us that cool trick in the Foundation Class. Make sure you stay tuned to my series of blogs on Back to The TSQL Basics for future tricks.
Very cool! I've used dragging the table name, and a single field into the query window, but never the Columns folder. Very helpful!