Qual a diferença entre Count() e Count(*) no SQL Server?
Count: Conta os valores não nulos
Veja um exemplo no banco BDWebMundi a tabela WmTitulos rodamos o seguinte comando:
SELECT count(titulos) from WMTitulos
Resultado:
———–
18
(1 row(s) affected)
Warning: Null value is eliminated by an aggregate or other SET operation.
Sendo que a tabela WMTitulos com o campo titulos tem o seguinte conteúdo:
titulos
——————————————————————————–
But Is It User Friendly?
Computer Phobic AND Non-Phobic Individuals: Behavior Variations
Cooking with Computers: Surreptitious Balance Sheets
Emotional Security: A New Algorithm
Fifty Years in Buckingham Palace Kitchens
Is Anger the Enemy?
Life Without Fear
Net Etiquette
Onions, Leeks, and Garlic: Cooking Secrets of the Mediterranean
Prolonged Data Deprivation: Four Case Studies
Secrets of Silicon Valley
Silicon Valley Gastronomic Treats
Straight Talk About Computers
Sushi, Anyone?
The Busy Executive’s Database Guide
The Gourmet Microwave
The Psychology of Computer Cooking
You Can Combat Computer Stress!
NULL
(19 row(s) affected)
Count(*): conta o número de linhas da tabela incluindo os valores nulos
Exemplo:
SELECT COUNT(*) FROM WMTitulos
Resultado:
———–
19
(1 row(s) affected)