SQL Server-2005中Select和Select count()之间的区别 [英] Difference between Select and Select count() in sql server-2005
本文介绍了SQL Server-2005中Select和Select count()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
海
我想知道 select *
和 select count(*)
之间的区别
如果我使用 select *
,则会出现错误
Hai
I would to know the difference between select *
and select count(*)
If I use select *
it gives an error
"Msg 263, Level 16, State 1, Line 1
Must specify table to select from"
但 select count(*)
没有给出任何错误
相反,它给出1作为计数.
请问原因.
在此先感谢.
but select count(*)
does not give any error
Instead It gives 1 as count.
May I know the reason.
Thanks in advance.
推荐答案
当您说"SELECT *"时,您正在编写部分命令:"SELECT these fields"而不保存它们的来源. "*"是通配符,它扩展为所有字段",因此您需要指定要从中读取的表:
When you say "SELECT *" you are writing a partial command: "SELECT these fields" without saving where they should come from. "*" is a wildcard which expands to "all fields" so you need to specify the table to read from:
"SELECT * FROM myTable"
当您说"SELECT COUNT(*)"时,您将执行不同的命令:一个SELECT,它返回单个项目,即项目数COUNT.因为没有列表,所以结果为1-计数本身.
When you say "SELECT COUNT(*)" you are a different command: a SELECT that returns a single item, the COUNT, of the number of items. Because there is no list, the result comes out at 1 - the count itself.
这意味着在该表中,您只有一个字段,并且只有一行.!
因此,当您使用"select count(*)"时,它将不计算您最近使用的表中的行数.
对于``select *"-您应该提及表名.. !!
It mean in that table you have only one field and it has only one row.!
so, When you use ''select count(*)'' it count no of rows from the table which you used recently.
for ''select * '' - you should mention the table name..!
Count(*)对结果集中的所有行进行计数.选择*返回结果集中行的所有列.
如果计数发生变化,则可能是在目标表上发生了插入和删除操作.
praveen
chennai
Count(*) counts all the rows in the result set. Select * returns all columns for the rows in the resultset.
If the count is changing it''s probably there are inserts and deletes happening against the destination table.
praveen
chennai
这篇关于SQL Server-2005中Select和Select count()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文