Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

We all know that to select all columns from a table, we can use

SELECT * FROM tableA

Is there a way to exclude column(s) from a table without specifying all the columns?

SELECT * [except columnA] FROM tableA

The only way that I know is to manually specify all the columns and exclude the unwanted column. This is really time consuming so I'm looking for ways to save time and effort on this, as well as future maintenance should the table has more/less columns.

Thanks!

1 Answer

0 votes
by (40.4k points)

It’s recommendable to do it in this way:

SELECT * INTO #Temp_Table

/* Get the data into a temp1 table(Here temp1 is a temporary table which is used to store the temporary data)  */

FROM Table  /* Drop those columns which are not needed */

ALTER TABLE #Temp_Table

DROP COLUMN ColumnToDrop /* Get the results and drop temporary table */

SELECT * FROM #Temp_Table

DROP TABLE #Temp_Table

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...