0

I'm trying to calculate how many pages a single table has. For this i end up with different queries

    SELECT SUM(si.dpages)
    FROM sys.sysindexes si 
         INNER JOIN sys.tables st on si.id = st.object_id
    WHERE st.name = 'job'


    SELECT SUM(page_count)
    FROM sys.dm_db_index_physical_stats (NULL, NULL, NULL, NULL, NULL) s
    WHERE 
        s.database_id = db_id() 
        and s.object_id = OBJECT_ID('job')

    SELECT SUM(used_page_count)
    FROM sys.dm_db_partition_stats   
    WHERE object_id = OBJECT_ID('job'); 


    dbcc ind
    (
        'wellnew' 
        ,'dbo.job' 
        ,-1 
    );

And these are the results:

  1. 16681
  2. 16681
  3. 16771
  4. (16771 row(s) affected)

Now, which one is right? Or what's the correct way to get that information? There is quite a similar question here it's even using a query similar tom mine, but i have 4 queries that in theory are all correct but they return different results

Thanks in advance Henrry

Kirzy
  • 138
  • 1
  • 16
  • For what purpose? – Tanner Sep 17 '17 at 00:07
  • Possible duplicate of [SQL Server: Number of 8K Pages Used by a Table and/or Database](https://stackoverflow.com/questions/11946957/sql-server-number-of-8k-pages-used-by-a-table-and-or-database) – Tanner Sep 17 '17 at 00:11
  • Does your table contain any columnstore indices? Because it becomes much more complicated in this case. – Roger Wolf Sep 17 '17 at 03:51
  • Hi Roger. No columnstore at all – Kirzy Sep 17 '17 at 17:17
  • 1
    Hi Tanner I want to set some columns to be sparse. So i wanted to show to the rest of the team the number of pages before and after the sparse – Kirzy Sep 17 '17 at 17:18

0 Answers0