Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

表有100个字段,我知道不想要的5个字段名称,怎样不一一列出95个字段名称就select出来?

一张表有100个字段,我知道有5个字段名称{A,B,C,D,E}是不需要的,我怎样写SQL语句把需要的字段从表里select出来,而不需要写出95个字段的名称?
select ????????
from table


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

这个问题不知道能不能解决你的问题?sql-exclude-a-column-using-select-except-columna-from-tablea

思路是:
创建一个临时表,然后把特定的列丢弃掉,然后再查询这张临时表。

/* Get the data into a temp table */
SELECT * INTO #TempTable
FROM YourTable
/* Drop the columns that are not needed */
ALTER TABLE #TempTable
DROP COLUMN ColumnToDrop
/* Get results and drop temp table */
SELECT * FROM #TempTable
DROP TABLE #TempTable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...