Skip to content
Advertisement

SELECT (* – some_columns) FROM TABLE in SQL

I have a table with many columns among which I’d like to omit a few alone in my ‘select’ query. Something like select (* - columns_to_be_omitted) from myTable. Is there a way to do this, other than listing all the other columns in the query?

This is a one-time manual query, so I’m not that concerned about performance. Ease of use is the greater need here.

Advertisement

Answer

You can’t do that – the best you can do is use a tool like SQL Prompt if you’re using SQL Server Management Studio.

SQL Prompt will allow you to do a SELECT * FROM MyTable and if you put your cursor after the “*” and press tab, SQL Prompt will enumerate all columns for your table, giving you a list of all columns in the table from which you can then remove those you’re not interested in. Or you can open up a popup dialog box which allows you to pick any number of columns from that table which are then inserted into the SELECT statement.

Too bad that’s not part of SSMS out of the box 🙁

Marc

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement