开发者

How do I get all the columns of a table besides one

Suppose we have 20 columns in a table and I want to return 19 of them. How can I do that ?

select *

will give me all of them but I want only 19.

Is there a开发者_StackOverflow good solution for that situation ? something like

select * - [columnName]

?!?


Nope, sorry. You can take *, or you can take them one at a time, but you can't take "all of them except for X, Y, or Z."


As has been said, you use SELECT * for all columns or list the columns individually if you don't want them all.

Listing columns does seem like a chore but there is an important reason why it's actually good.

While it's OK for ad hoc queries, it's highly recommended that use don't use SELECT * in code because when the database schema changes you will get different columns in the results returned to your application which is almost certainly not what you want. If you could do select * but address from customer this would have the same problem: changing the DB would change the structure of the results of your query which is bad.

So not only can you not do it, I would recommend not doing it even if you could.


You can explicitly name each column you wish to select. That is the only way to exclude columns.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜