SQL select join: is it possible to prefix all columns as 'prefix.*'?

后端 未结 22 1792
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 06:20

I\'m wondering if this is possible in SQL. Say you have two tables A and B, and you do a select on table A and join on table B:

SELECT a.*, b.* FROM TABLE_A a         


        
22条回答
  •  庸人自扰
    2020-12-02 06:50

    The only database I know that does this is SQLite, depending on the settings you configure with PRAGMA full_column_names and PRAGMA short_column_names. See http://www.sqlite.org/pragma.html

    Otherwise all I can recommend is to fetch columns in a result set by ordinal position rather than by column name, if it's too much trouble for you to type the names of the columns in your query.

    This is a good example of why it's bad practice to use SELECT * -- because eventually you'll have a need to type out all the column names anyway.

    I understand the need to support columns that may change name or position, but using wildcards makes that harder, not easier.

提交回复
热议问题