为什么“select count(*)”从无返回1 [英] Why does "select count(*)" from nothing return 1

查看:871
本文介绍了为什么“select count(*)”从无返回1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用SQL Server 2012:

 使用master 
select *



产生


p>

这正是我的期望。



但有趣的是

 使用master 
select count(*)

返回1.



有人可以向我解释这里计算的是什么?



编辑:可能包括来源...

解决方案

SQL Server(幕后)有效地将一个from应用到一个只有一行的虚拟表。因此,你会得到1为你的计数。

 选择'test'

会做同样的事情,例如,返回'test'一次。



它类似于Oracle中的DUAL表,DB2中的SYSDUMMY1



根据需要,这里有一个指向MS Connect的链接:


点击



更多点击


With SQL Server 2012 :

use master
select *

yields

Must specify table to select from

which is exactly what I would expect.

But the funny thing is that

use master
select count(*)

returns 1.

Can someone explain to me what is counted here?

Edit : And possibly include sources...

解决方案

SQL Server is (behind the curtain) effectively applying a from to a dummy table, which has only one row. Thus you will get 1 for your count.

select 'test'

will do the same thing, as an example, return 'test' one time.

It's like the DUAL table in Oracle, SYSDUMMY1 in DB2, etc.

As requested, here's a couple of links to MS Connect on this topic:

Clicky

More Clicky

这篇关于为什么“select count(*)”从无返回1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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