Skip to content
Retour AccueilRetour Accueil

L'actualité technique MS SQL Server en France (et ailleurs)

L'actualité technique MS SQL Server en France (et ailleurs)

  • Sites francophones
  • Sites anglophones
  • Sites Microsoft
  • Vidéos
  • Script Center
  • Recherche
Accueil » Tous les articles » Sites anglophones » Counting more efficiently

Counting more efficiently

20 décembre 2023  dans Sites anglophones  étiqueté Homepage / metadata / T-SQL Coding / T-SQL Programming par simple-talk.com

 

Nearly a decade ago, I wrote a post called “Bad habits : Counting rows the hard way.” In that post, I talked about how we can use SQL Server’s metadata to instantly retrieve the row count for a table. Typically, people do the following, which has to read the entire table or index:

DECLARE @c int = (SELECT COUNT(*) FROM dbo.TableName);

To largely avoid size-of-data constraints, we can instead use sys.partitions.

Note: We could use OBJECT_ID() instead of a join, but that function doesn’t observe isolation semantics, so can cause blocking – or be a victim. A potential compromise is

 


Parcourir les articles

  • ← [Video] Office Hours: Wrong Side of the Bed Edition
  • [Video] Office Hours: 21 Good Questions →

Cette compilation de ressources vous est proposée
par Arian Papillon, MVP Data Platform
mvp Datafly
Site sponsorisé par DATAFLY - www.datafly.fr
Microsoft et SQL Server sont des marques déposées de Microsoft Corporation

· © 2018 mssql.fr · Designed by Arian Papillon - Datafly ·

Retour haut de page