Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

Quickest way to SELECT All Columns from a Table

Sep 4 2011 12:00AM by Dattatrey Sindol (Datta)   

Suppose you have a huge table which has say 30-40 columns and you want to select all of them or most of them say around 30 columns. It is a tedious job to type each of the column names. Here is a quick way to get a comma separated list of all the columns with minimal effort.

  1. Go to SSMS, Open a new query window, Type SELECT followed by a space
  2. Go to Object Explorer
  3. Expand the databases node, expand the user database which contains your table, expand the Tables folder, Expand the Table from which you need to selec the Columns/Data.
  4. Click on "Columns" folder, hold it, and drag it on to the Query Surface after the "SELECT " (Step 1). This place all the columns on to the query surface in a comma separated fashion.
  5. Remove the unwanted columns
  6. Now type in " FROM TableName" at the end of the column list (Outcome of Step 4 & 5) and do the necessary formatting.

It is as simple as that ! This can save a lot of effort required to manually type in the Column Names.

Read More..   [71 clicks]

Published under: SQL Server Tips ·  ·  ·  · 


Dattatrey Sindol (Datta)
43 · 4% · 1333
49
 
14
 
46
 
0
Incorrect
 
0
Interesting
 
0
Forgotten



Submit

31  Comments  

  • Great.... It really helped .. Thanks...

    commented on Sep 5 2011 1:07AM
    Sandeep Prajapati
    60 · 3% · 926
  • You can also right click on table and choose: Script table as - Select to - New query editor window

    commented on Sep 5 2011 3:08AM
    Jan Novak
    469 · 0% · 80
  • I typically use the method highlighted by Jan Novak.

    Thanks for sharing, Dattatrey!

    commented on Sep 5 2011 4:47AM
    Nakul Vachhrajani
    4 · 33% · 10575
  • I used to use select "columns" method only..

    commented on Sep 5 2011 4:57AM
    Ramireddy
    2 · 41% · 12972
  • Nice tip. Too bad it doesn't put the column's names intro square brackets though.

    commented on Sep 5 2011 5:06AM
    Sergejack
    41 · 4% · 1393
  • I use something else: after typing "SELECT * FROM TableName", I select the query and press Ctrl+Shift+Q ("Design in query editor") then select OK.

    commented on Sep 5 2011 5:44AM
    Razvan Socol
    176 · 1% · 278
  • The Query Designer would do the trick. If you would like to know more on the query designer, do check out my post here - SSMS – Query Designer – Ad-hoc query writing/editing made simple

    commented on Sep 5 2011 7:23AM
    Nakul Vachhrajani
    4 · 33% · 10575
  • I think the method posted by Jan Novak is faster.

    commented on Sep 5 2011 8:57AM
    Ben Rodriguez
    1912 · 0% · 9
  • I usually issue the following command to get a list of all columns in a table or view:

    sp_help [table-or-view-name]

    (This is command also usually bound to the Alt+F1 key, so type the tablename out, highlight it and do Alt+F1)

    You can then copy & paste the column names from the resultset up into your query pane. I find this invaluable - I must do sp_help a hundred times a day when I'm writing queries and want to remind myself what a column is called...

    commented on Sep 5 2011 10:42AM
    bettername
    1720 · 0% · 11
  • Great to know so many different ways to achieve this :)

    commented on Sep 6 2011 12:53AM
    Dattatrey Sindol (Datta)
    43 · 4% · 1333
  • you can directly right-click on the table name in object explorer of SSMS and click on "Select TOP 1000 rows" option the query will be opened in a new query window and there you can make your changes to the query.

    commented on Sep 6 2011 4:09AM
    mshijat
    204 · 1% · 226
  • Square bracket is required to remove the conflict between SQL keyword and column name.

    I am always using 'Select To' to generate the column list because it is giving result with square bracket in column as well as in table name.

    commented on Sep 9 2011 2:41AM
    Hardik Doshi
    20 · 9% · 2839
  • This is good practice, becasue it does allow one to get all the columns for a table quickly. As for Sergejack's wish, one can solve that simply by using another trick, which is the do a quick "find and replace" within the SQL client query interface.

    If you're not familiar with that, simply press "Ctrl+H" or go to the "Edit" sub menu, select "Find and Replace", and then select "Quick Replace". Once the dialog windows presents itself, simply replace all "," with "], [". For example,

    select Field1, Field2, Field3, Field4, Field5, .... from Table_A

    After using the "Find and Replace" feature, you will have

    select Field1], [Field2], [Field3], [Field4], [Field5 ... from Table_A

    after which point you can just add a starting bracket, "[", and ending bracke, "]", to complete your wish.

    select [Field1], [Field2], [Field3], [Field4], [Field5] ... from Table_A

    commented on Sep 15 2011 10:40AM
    Rich
    909 · 0% · 30
  • dint know these many ways are used..

    commented on Sep 26 2011 12:08PM
    vanne040
    83 · 2% · 657
  • I am so glad to learn this shortcut. Thanks!

    commented on Oct 21 2011 9:07AM
    jlmurphy
    322 · 0% · 131
  • great this is more helpful for us

    commented on Oct 27 2011 1:49AM
    ramesh
    680 · 0% · 48
  • Excelent tip!

    Thank you! :)

    commented on Dec 8 2011 8:32PM
    Rechousa
    1912 · 0% · 9
  • It's a nice and quick way but I always use @Jan Novak 's way.

    commented on Jan 2 2012 11:51AM
    Suvendu Shekhar Giri
    168 · 1% · 289
  • Hi,

    I write SQL "select * from tablename" then highlight entire select statement and right click open in "Design in Query Editor" and copy from every all code from Query editor and paste back to SSMS query.Uses SSMS tool to format it.

    thanks Nachi

    commented on Jan 14 2012 7:33PM
    nachikethm
    1912 · 0% · 9
  • Hi All,

    By querying INFORMATION_SCHEMA.COLUMNS and using COALESCE() Function, all the table names can be selected and seperated by comma and can be even sorted by column name.

    DECLARE @i VARCHAR(MAX) 
    SELECT @i = COALESCE(@i + ', ','') + '[' + COLUMN_NAME + ']'
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'Your Table Name' 
    ORDER BY COLUMN_NAME
    SELECT @i
    
    commented on Feb 17 2012 8:43AM
    rrc012
    1978 · 0% · 7
Previous 1 | 2 Next

Your Comment


Sign Up or Login to post a comment.

"Quickest way to SELECT All Columns from a Table" rated 5 out of 5 by 49 readers
Quickest way to SELECT All Columns from a Table , 5.0 out of 5 based on 49 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]