Select * 和 Select [list each col] 之间有区别吗 [英] Is there a difference between Select * and Select [list each col]

查看:30
本文介绍了Select * 和 Select [list each col] 之间有区别吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 MS SQL Server 2005.SQL 引擎之间是否存在差异

I'm using MS SQL Server 2005. Is there a difference, to the SQL engine, between

SELECT * FROM MyTable;

SELECT ColA, ColB, ColC FROM MyTable;

当 ColA、ColB 和 ColC 代表表中的每一列时?

When ColA, ColB, and ColC represent every column in the table?

如果它们相同,那么您是否有理由仍然使用第二个?我有一个在 LINQ 上很重要的项目,我不确定它生成的标准 SELECT * 是否是一种不好的做法,或者我是否应该始终使用 .Select() 来指定我想要的列.

If they are the same, is there a reason why you should use the 2nd one anyway? I have a project that's heavy on LINQ, and I'm not sure if the standard SELECT * it generates is a bad practice, or if I should always be a .Select() on it to specify which cols I want.

更改了当 ColA、ColB 和 ColC 都是表的所有列时?"到当 ColA、ColB 和 ColC 代表表中的每一列时?"为清楚起见.

Changed "When ColA, ColB, and ColC are all the columns to the table?" to "When ColA, ColB, and ColC represent every column in the table?" for clarity.

推荐答案

一般来说,最好是明确的,所以 Select col1, col2 from Table 更好.原因是在某些时候,可能会在该表中添加一个额外的列,并且会导致从查询中带回不需要的数据.

Generally, it's better to be explicit, so Select col1, col2 from Table is better. The reason being that at some point, an extra column may be added to that table, and would cause unneeded data to be brought back from the query.

虽然这不是硬性规定.

这篇关于Select * 和 Select [list each col] 之间有区别吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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