在SQL上的问题检索列 [英] Quetion on sql retrieve the columns

查看:115
本文介绍了在SQL上的问题检索列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..


我在从数据库表中检索数据时遇到问题...我的问题是我的数据库中有一个表,我想检索表中除DbId以外的所有数据.我该如何获得任何帮助.


提前致谢
Mishrutha

Hi..


Iam facing a problem in retrieving the data from the database table... my question is i have one table in my database i would like to retrieve the all the data in my table except DbId how can i get this can any one help..


Thank''s in Advance
Mishrutha

推荐答案

您不能做"SELECT * EXCEPT DbId FROM myTable"的等效项-Sql中没有相应的机制.

这样做的一种好方法是按照您想要的顺序命名您希望检索的所有列:
You can''t do the equivilent of "SELECT * EXCEPT DbId FROM myTable" - there is no mechanism in Sql for that.

The good practice way to do it is to name all the columns you do wish to retrieve, in the order you want them:
SELECT Column1, Column3, Column2 FROM myTable

减少了传输中的浪费,因为它不会获取您不感兴趣的列,并指定了使用顺序访问检索到的数据时的数字索引.

您可以通过创建一个临时表,将整个表复制到其中,然后在返回整个表之前从该临时表中删除DbId列来做到这一点,但是t效率极低!

The reduces waste in the transfer, as it doesn''t get columns you aren''t interested in, and specifies the order if you use a numeric index when you access the retrieved data.

You could do it by creating a temporary table, copying the whole table into it, and then dropping the DbId column from the temporary table before returning the whole of that, but t would be incredibly inefficient!

SELECT * INTO #Temp FROM myTable
ALTER TABLE #Temp DROP COLUMN DbId
SELECT * FROM #Temp
DROP TABLE #Temp


这篇关于在SQL上的问题检索列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆