SQL exclude a column using SELECT * [except columnA] FROM tableA?

后端 未结 30 2599
花落未央
花落未央 2020-11-21 23:15

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 witho

30条回答
  •  一个人的身影
    2020-11-22 00:01

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

    Using declarative SQL in the usual way, no.

    I think your proposed syntax is worthy and good. In fact, the relational database language 'Tutorial D' has a very similar syntax where the keywords ALL BUT are followed by a set of attributes (columns).

    However, SQL's SELECT * already gets a lot a flak (@Guffa's answer here is a typical objection), so I don't think SELECT ALL BUT will get into the SQL Standard anytime soon.

    I think the best 'work around' is to create a VIEW with only the columns you desire then SELECT * FROM ThatView.

提交回复
热议问题