Understanding the differences in the storage space used by two tablesIndexing - Uniqueidentifier Foreign Key or Intermediary mapping table?Why is Clustered Index on Primary Key compulsory?Parent-Child Tree Hierarchical ORDERUnable to drop non-PK index because it is referenced in a foreign key constraintdeteriorating stored procedure running timesSelect Into removes IDENTITY property from target tableWhy does imported txt table consume so much spaceMaximizing Availability on a Table When Changing Data TypeWhat is the most efficient way to store a bunch of empty fields, and ones with only a few choices?Identity Column in Concurrency, Multithreading, Parallel Processing

Is my plasma cannon concept viable?

Python program for fibonacci sequence using a recursive function

Need to read my home electrical Meter

What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?

First Program Tic-Tac-Toe

Why A=2 and B=1 in the call signs for Spirit and Opportunity?

How to keep consistency across the application architecture as a team grows?

Would Buddhists help non-Buddhists continuing their attachments?

Why does the Starter Set wizard have six spells in their spellbook?

Variable declaraton with extra in C

Did this character show any indication of wanting to rule before S8E6?

Co-author wants to put their current funding source in the acknowledgements section because they edited the paper

Are there any German nonsense poems (Jabberwocky)?

Is "vegetable base" a common term in English?

I want to know what marumaru means

What are nvme namespaces? How do they work?

Gravitational Force Between Numbers

Finding all files with a given extension whose base name is the name of the parent directory

What weight should be given to writers groups critiques?

The disk image is 497GB smaller than the target device

Why do Russians almost not use verbs of possession akin to "have"?

Why is this integration method not valid?

Dad jokes are fun

Count all vowels in string



Understanding the differences in the storage space used by two tables


Indexing - Uniqueidentifier Foreign Key or Intermediary mapping table?Why is Clustered Index on Primary Key compulsory?Parent-Child Tree Hierarchical ORDERUnable to drop non-PK index because it is referenced in a foreign key constraintdeteriorating stored procedure running timesSelect Into removes IDENTITY property from target tableWhy does imported txt table consume so much spaceMaximizing Availability on a Table When Changing Data TypeWhat is the most efficient way to store a bunch of empty fields, and ones with only a few choices?Identity Column in Concurrency, Multithreading, Parallel Processing






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I have two tables in which, more or less, one contains a subset of data of the other one. There is some data I delete from the first table, which is inserted in the second one as historical data.



These are the defintions:



CREATE TABLE [dbo].[CIC_DESLUNGHE](
[CD_CIC_DESLUNGHE] [bigint] IDENTITY(1,1) NOT NULL,
[CD_CIC_PRODUZIONE] [bigint] NOT NULL,
[CD_CIC_OPERAZIONI] [bigint] NOT NULL,
[AFNMPROG] [int] NOT NULL,
[AFDSLINE] [nvarchar](max) NULL,
CONSTRAINT [PK_CIC_DESLUNGHE] PRIMARY KEY CLUSTERED
(
[CD_CIC_DESLUNGHE] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 99) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO


CREATE TABLE [dbo].[CIC_DESLUNGHE_STORICI](
[CD_CIC_DESLUNGHE_STORICI] [bigint] IDENTITY(1,1) NOT NULL,
[CD_CIC_PRODUZIONE_STORICI] [bigint] NOT NULL,
[CD_CIC_OPERAZIONI_STORICI] [bigint] NOT NULL,
[AFNMPROG] [int] NOT NULL,
[AFDSLINE] [nvarchar](max) NOT NULL,
CONSTRAINT [PK_CIC_DESLUNGHE_STORICI_1] PRIMARY KEY CLUSTERED
(
[CD_CIC_DESLUNGHE_STORICI] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO


The second table contains a subset of data that I need it as historicization of my data.



Table Rows TotalSpace MB
--------------------- ---------- -------------
CIC_DESLUNGHE_STORICI 12.709.497 48214,75
CIC_DESLUNGHE 24.827.337 5675,49


What leaves me astonished is that the total storage space utilized. The subset table use 10 times the space of the other.



Any idea why this is happening?



I tried rebuilding the clustered index of CIC_DESLUNGHE_STORICI, but the storage only dropped from 48 GB to 47 GB.



-- EDIT --



This is the result I got with the query of Josh Darnell



CIC_DESLUNGHE



CIC_DESLUNGHE_STORICI










share|improve this question









New contributor



Galma88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    2















    I have two tables in which, more or less, one contains a subset of data of the other one. There is some data I delete from the first table, which is inserted in the second one as historical data.



    These are the defintions:



    CREATE TABLE [dbo].[CIC_DESLUNGHE](
    [CD_CIC_DESLUNGHE] [bigint] IDENTITY(1,1) NOT NULL,
    [CD_CIC_PRODUZIONE] [bigint] NOT NULL,
    [CD_CIC_OPERAZIONI] [bigint] NOT NULL,
    [AFNMPROG] [int] NOT NULL,
    [AFDSLINE] [nvarchar](max) NULL,
    CONSTRAINT [PK_CIC_DESLUNGHE] PRIMARY KEY CLUSTERED
    (
    [CD_CIC_DESLUNGHE] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 99) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO


    CREATE TABLE [dbo].[CIC_DESLUNGHE_STORICI](
    [CD_CIC_DESLUNGHE_STORICI] [bigint] IDENTITY(1,1) NOT NULL,
    [CD_CIC_PRODUZIONE_STORICI] [bigint] NOT NULL,
    [CD_CIC_OPERAZIONI_STORICI] [bigint] NOT NULL,
    [AFNMPROG] [int] NOT NULL,
    [AFDSLINE] [nvarchar](max) NOT NULL,
    CONSTRAINT [PK_CIC_DESLUNGHE_STORICI_1] PRIMARY KEY CLUSTERED
    (
    [CD_CIC_DESLUNGHE_STORICI] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO


    The second table contains a subset of data that I need it as historicization of my data.



    Table Rows TotalSpace MB
    --------------------- ---------- -------------
    CIC_DESLUNGHE_STORICI 12.709.497 48214,75
    CIC_DESLUNGHE 24.827.337 5675,49


    What leaves me astonished is that the total storage space utilized. The subset table use 10 times the space of the other.



    Any idea why this is happening?



    I tried rebuilding the clustered index of CIC_DESLUNGHE_STORICI, but the storage only dropped from 48 GB to 47 GB.



    -- EDIT --



    This is the result I got with the query of Josh Darnell



    CIC_DESLUNGHE



    CIC_DESLUNGHE_STORICI










    share|improve this question









    New contributor



    Galma88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      2












      2








      2


      1






      I have two tables in which, more or less, one contains a subset of data of the other one. There is some data I delete from the first table, which is inserted in the second one as historical data.



      These are the defintions:



      CREATE TABLE [dbo].[CIC_DESLUNGHE](
      [CD_CIC_DESLUNGHE] [bigint] IDENTITY(1,1) NOT NULL,
      [CD_CIC_PRODUZIONE] [bigint] NOT NULL,
      [CD_CIC_OPERAZIONI] [bigint] NOT NULL,
      [AFNMPROG] [int] NOT NULL,
      [AFDSLINE] [nvarchar](max) NULL,
      CONSTRAINT [PK_CIC_DESLUNGHE] PRIMARY KEY CLUSTERED
      (
      [CD_CIC_DESLUNGHE] ASC
      )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 99) ON [PRIMARY]
      ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
      GO


      CREATE TABLE [dbo].[CIC_DESLUNGHE_STORICI](
      [CD_CIC_DESLUNGHE_STORICI] [bigint] IDENTITY(1,1) NOT NULL,
      [CD_CIC_PRODUZIONE_STORICI] [bigint] NOT NULL,
      [CD_CIC_OPERAZIONI_STORICI] [bigint] NOT NULL,
      [AFNMPROG] [int] NOT NULL,
      [AFDSLINE] [nvarchar](max) NOT NULL,
      CONSTRAINT [PK_CIC_DESLUNGHE_STORICI_1] PRIMARY KEY CLUSTERED
      (
      [CD_CIC_DESLUNGHE_STORICI] ASC
      )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
      ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
      GO


      The second table contains a subset of data that I need it as historicization of my data.



      Table Rows TotalSpace MB
      --------------------- ---------- -------------
      CIC_DESLUNGHE_STORICI 12.709.497 48214,75
      CIC_DESLUNGHE 24.827.337 5675,49


      What leaves me astonished is that the total storage space utilized. The subset table use 10 times the space of the other.



      Any idea why this is happening?



      I tried rebuilding the clustered index of CIC_DESLUNGHE_STORICI, but the storage only dropped from 48 GB to 47 GB.



      -- EDIT --



      This is the result I got with the query of Josh Darnell



      CIC_DESLUNGHE



      CIC_DESLUNGHE_STORICI










      share|improve this question









      New contributor



      Galma88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have two tables in which, more or less, one contains a subset of data of the other one. There is some data I delete from the first table, which is inserted in the second one as historical data.



      These are the defintions:



      CREATE TABLE [dbo].[CIC_DESLUNGHE](
      [CD_CIC_DESLUNGHE] [bigint] IDENTITY(1,1) NOT NULL,
      [CD_CIC_PRODUZIONE] [bigint] NOT NULL,
      [CD_CIC_OPERAZIONI] [bigint] NOT NULL,
      [AFNMPROG] [int] NOT NULL,
      [AFDSLINE] [nvarchar](max) NULL,
      CONSTRAINT [PK_CIC_DESLUNGHE] PRIMARY KEY CLUSTERED
      (
      [CD_CIC_DESLUNGHE] ASC
      )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 99) ON [PRIMARY]
      ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
      GO


      CREATE TABLE [dbo].[CIC_DESLUNGHE_STORICI](
      [CD_CIC_DESLUNGHE_STORICI] [bigint] IDENTITY(1,1) NOT NULL,
      [CD_CIC_PRODUZIONE_STORICI] [bigint] NOT NULL,
      [CD_CIC_OPERAZIONI_STORICI] [bigint] NOT NULL,
      [AFNMPROG] [int] NOT NULL,
      [AFDSLINE] [nvarchar](max) NOT NULL,
      CONSTRAINT [PK_CIC_DESLUNGHE_STORICI_1] PRIMARY KEY CLUSTERED
      (
      [CD_CIC_DESLUNGHE_STORICI] ASC
      )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
      ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
      GO


      The second table contains a subset of data that I need it as historicization of my data.



      Table Rows TotalSpace MB
      --------------------- ---------- -------------
      CIC_DESLUNGHE_STORICI 12.709.497 48214,75
      CIC_DESLUNGHE 24.827.337 5675,49


      What leaves me astonished is that the total storage space utilized. The subset table use 10 times the space of the other.



      Any idea why this is happening?



      I tried rebuilding the clustered index of CIC_DESLUNGHE_STORICI, but the storage only dropped from 48 GB to 47 GB.



      -- EDIT --



      This is the result I got with the query of Josh Darnell



      CIC_DESLUNGHE



      CIC_DESLUNGHE_STORICI







      sql-server sql-server-2016 storage






      share|improve this question









      New contributor



      Galma88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      Galma88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited May 17 at 7:53







      Galma88













      New contributor



      Galma88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked May 16 at 14:56









      Galma88Galma88

      1136




      1136




      New contributor



      Galma88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Galma88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          6














          Based on the information given, one explanation is that the size of the data being stored in the nvarchar(max) column used to be much larger than it is now.



          • ~12 million historical rows averaging 3.88 KB per row

          • ~24 million live rows averaging 0.23 KB per row

          You can double check this by using the dynamic management function sys.dm_db_index_physical_stats on each of the two tables, specifically looking at the "avg_record_size_in_bytes" column. Something like this:



          SELECT 
          DB_NAME(ips.database_id),
          OBJECT_NAME(ips.[object_id]),
          ips.index_id,
          ips.index_type_desc,
          ips.index_level,
          ips.alloc_unit_type_desc,
          ips.page_count,
          ips.record_count,
          ips.min_record_size_in_bytes,
          ips.max_record_size_in_bytes,
          ips.avg_record_size_in_bytes
          FROM sys.dm_db_index_physical_stats
          (
          DB_ID(N'YourDatabaseName'),
          OBJECT_ID(N'CIC_DESLUNGHE'),
          NULL,
          NULL ,
          'DETAILED'
          ) ips;


          And



          SELECT 
          DB_NAME(ips.database_id),
          OBJECT_NAME(ips.[object_id]),
          ips.index_id,
          ips.index_type_desc,
          ips.index_level,
          ips.alloc_unit_type_desc,
          ips.page_count,
          ips.record_count,
          ips.min_record_size_in_bytes,
          ips.max_record_size_in_bytes,
          ips.avg_record_size_in_bytes
          FROM sys.dm_db_index_physical_stats
          (
          DB_ID(N'YourDatabaseName'),
          OBJECT_ID(N'CIC_DESLUNGHE_STORICI'),
          NULL,
          NULL ,
          'DETAILED'
          ) ips;


          Compare the results of the two queries and see if there are any surprising discrepancies.



          I left other filters off the function call because this will also show nonclustered indexes. You didn't mention how you arrived at the numbers in your question, but if they include NC indexes on the tables, perhaps those are contributing to the size difference.






          share|improve this answer

























          • I edited my question with the results of the execution of your query. What I can see is a big difference in the first row where there's a avg value higher than in the first table

            – Galma88
            May 17 at 7:54







          • 1





            @Galma88 That confirms my theory. You have older data in the history table, and both the number of LOB_DATA rows, and the avg size of rows in the clustered index, is higher. This means your more recent rows, in the live table, have less data into the [AFDSLINE] column. Maybe the application has been changed to put less data there.

            – Josh Darnell
            May 17 at 11:31











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "182"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Galma88 is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f238331%2funderstanding-the-differences-in-the-storage-space-used-by-two-tables%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6














          Based on the information given, one explanation is that the size of the data being stored in the nvarchar(max) column used to be much larger than it is now.



          • ~12 million historical rows averaging 3.88 KB per row

          • ~24 million live rows averaging 0.23 KB per row

          You can double check this by using the dynamic management function sys.dm_db_index_physical_stats on each of the two tables, specifically looking at the "avg_record_size_in_bytes" column. Something like this:



          SELECT 
          DB_NAME(ips.database_id),
          OBJECT_NAME(ips.[object_id]),
          ips.index_id,
          ips.index_type_desc,
          ips.index_level,
          ips.alloc_unit_type_desc,
          ips.page_count,
          ips.record_count,
          ips.min_record_size_in_bytes,
          ips.max_record_size_in_bytes,
          ips.avg_record_size_in_bytes
          FROM sys.dm_db_index_physical_stats
          (
          DB_ID(N'YourDatabaseName'),
          OBJECT_ID(N'CIC_DESLUNGHE'),
          NULL,
          NULL ,
          'DETAILED'
          ) ips;


          And



          SELECT 
          DB_NAME(ips.database_id),
          OBJECT_NAME(ips.[object_id]),
          ips.index_id,
          ips.index_type_desc,
          ips.index_level,
          ips.alloc_unit_type_desc,
          ips.page_count,
          ips.record_count,
          ips.min_record_size_in_bytes,
          ips.max_record_size_in_bytes,
          ips.avg_record_size_in_bytes
          FROM sys.dm_db_index_physical_stats
          (
          DB_ID(N'YourDatabaseName'),
          OBJECT_ID(N'CIC_DESLUNGHE_STORICI'),
          NULL,
          NULL ,
          'DETAILED'
          ) ips;


          Compare the results of the two queries and see if there are any surprising discrepancies.



          I left other filters off the function call because this will also show nonclustered indexes. You didn't mention how you arrived at the numbers in your question, but if they include NC indexes on the tables, perhaps those are contributing to the size difference.






          share|improve this answer

























          • I edited my question with the results of the execution of your query. What I can see is a big difference in the first row where there's a avg value higher than in the first table

            – Galma88
            May 17 at 7:54







          • 1





            @Galma88 That confirms my theory. You have older data in the history table, and both the number of LOB_DATA rows, and the avg size of rows in the clustered index, is higher. This means your more recent rows, in the live table, have less data into the [AFDSLINE] column. Maybe the application has been changed to put less data there.

            – Josh Darnell
            May 17 at 11:31















          6














          Based on the information given, one explanation is that the size of the data being stored in the nvarchar(max) column used to be much larger than it is now.



          • ~12 million historical rows averaging 3.88 KB per row

          • ~24 million live rows averaging 0.23 KB per row

          You can double check this by using the dynamic management function sys.dm_db_index_physical_stats on each of the two tables, specifically looking at the "avg_record_size_in_bytes" column. Something like this:



          SELECT 
          DB_NAME(ips.database_id),
          OBJECT_NAME(ips.[object_id]),
          ips.index_id,
          ips.index_type_desc,
          ips.index_level,
          ips.alloc_unit_type_desc,
          ips.page_count,
          ips.record_count,
          ips.min_record_size_in_bytes,
          ips.max_record_size_in_bytes,
          ips.avg_record_size_in_bytes
          FROM sys.dm_db_index_physical_stats
          (
          DB_ID(N'YourDatabaseName'),
          OBJECT_ID(N'CIC_DESLUNGHE'),
          NULL,
          NULL ,
          'DETAILED'
          ) ips;


          And



          SELECT 
          DB_NAME(ips.database_id),
          OBJECT_NAME(ips.[object_id]),
          ips.index_id,
          ips.index_type_desc,
          ips.index_level,
          ips.alloc_unit_type_desc,
          ips.page_count,
          ips.record_count,
          ips.min_record_size_in_bytes,
          ips.max_record_size_in_bytes,
          ips.avg_record_size_in_bytes
          FROM sys.dm_db_index_physical_stats
          (
          DB_ID(N'YourDatabaseName'),
          OBJECT_ID(N'CIC_DESLUNGHE_STORICI'),
          NULL,
          NULL ,
          'DETAILED'
          ) ips;


          Compare the results of the two queries and see if there are any surprising discrepancies.



          I left other filters off the function call because this will also show nonclustered indexes. You didn't mention how you arrived at the numbers in your question, but if they include NC indexes on the tables, perhaps those are contributing to the size difference.






          share|improve this answer

























          • I edited my question with the results of the execution of your query. What I can see is a big difference in the first row where there's a avg value higher than in the first table

            – Galma88
            May 17 at 7:54







          • 1





            @Galma88 That confirms my theory. You have older data in the history table, and both the number of LOB_DATA rows, and the avg size of rows in the clustered index, is higher. This means your more recent rows, in the live table, have less data into the [AFDSLINE] column. Maybe the application has been changed to put less data there.

            – Josh Darnell
            May 17 at 11:31













          6












          6








          6







          Based on the information given, one explanation is that the size of the data being stored in the nvarchar(max) column used to be much larger than it is now.



          • ~12 million historical rows averaging 3.88 KB per row

          • ~24 million live rows averaging 0.23 KB per row

          You can double check this by using the dynamic management function sys.dm_db_index_physical_stats on each of the two tables, specifically looking at the "avg_record_size_in_bytes" column. Something like this:



          SELECT 
          DB_NAME(ips.database_id),
          OBJECT_NAME(ips.[object_id]),
          ips.index_id,
          ips.index_type_desc,
          ips.index_level,
          ips.alloc_unit_type_desc,
          ips.page_count,
          ips.record_count,
          ips.min_record_size_in_bytes,
          ips.max_record_size_in_bytes,
          ips.avg_record_size_in_bytes
          FROM sys.dm_db_index_physical_stats
          (
          DB_ID(N'YourDatabaseName'),
          OBJECT_ID(N'CIC_DESLUNGHE'),
          NULL,
          NULL ,
          'DETAILED'
          ) ips;


          And



          SELECT 
          DB_NAME(ips.database_id),
          OBJECT_NAME(ips.[object_id]),
          ips.index_id,
          ips.index_type_desc,
          ips.index_level,
          ips.alloc_unit_type_desc,
          ips.page_count,
          ips.record_count,
          ips.min_record_size_in_bytes,
          ips.max_record_size_in_bytes,
          ips.avg_record_size_in_bytes
          FROM sys.dm_db_index_physical_stats
          (
          DB_ID(N'YourDatabaseName'),
          OBJECT_ID(N'CIC_DESLUNGHE_STORICI'),
          NULL,
          NULL ,
          'DETAILED'
          ) ips;


          Compare the results of the two queries and see if there are any surprising discrepancies.



          I left other filters off the function call because this will also show nonclustered indexes. You didn't mention how you arrived at the numbers in your question, but if they include NC indexes on the tables, perhaps those are contributing to the size difference.






          share|improve this answer















          Based on the information given, one explanation is that the size of the data being stored in the nvarchar(max) column used to be much larger than it is now.



          • ~12 million historical rows averaging 3.88 KB per row

          • ~24 million live rows averaging 0.23 KB per row

          You can double check this by using the dynamic management function sys.dm_db_index_physical_stats on each of the two tables, specifically looking at the "avg_record_size_in_bytes" column. Something like this:



          SELECT 
          DB_NAME(ips.database_id),
          OBJECT_NAME(ips.[object_id]),
          ips.index_id,
          ips.index_type_desc,
          ips.index_level,
          ips.alloc_unit_type_desc,
          ips.page_count,
          ips.record_count,
          ips.min_record_size_in_bytes,
          ips.max_record_size_in_bytes,
          ips.avg_record_size_in_bytes
          FROM sys.dm_db_index_physical_stats
          (
          DB_ID(N'YourDatabaseName'),
          OBJECT_ID(N'CIC_DESLUNGHE'),
          NULL,
          NULL ,
          'DETAILED'
          ) ips;


          And



          SELECT 
          DB_NAME(ips.database_id),
          OBJECT_NAME(ips.[object_id]),
          ips.index_id,
          ips.index_type_desc,
          ips.index_level,
          ips.alloc_unit_type_desc,
          ips.page_count,
          ips.record_count,
          ips.min_record_size_in_bytes,
          ips.max_record_size_in_bytes,
          ips.avg_record_size_in_bytes
          FROM sys.dm_db_index_physical_stats
          (
          DB_ID(N'YourDatabaseName'),
          OBJECT_ID(N'CIC_DESLUNGHE_STORICI'),
          NULL,
          NULL ,
          'DETAILED'
          ) ips;


          Compare the results of the two queries and see if there are any surprising discrepancies.



          I left other filters off the function call because this will also show nonclustered indexes. You didn't mention how you arrived at the numbers in your question, but if they include NC indexes on the tables, perhaps those are contributing to the size difference.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 16 at 16:08

























          answered May 16 at 16:03









          Josh DarnellJosh Darnell

          9,20232345




          9,20232345












          • I edited my question with the results of the execution of your query. What I can see is a big difference in the first row where there's a avg value higher than in the first table

            – Galma88
            May 17 at 7:54







          • 1





            @Galma88 That confirms my theory. You have older data in the history table, and both the number of LOB_DATA rows, and the avg size of rows in the clustered index, is higher. This means your more recent rows, in the live table, have less data into the [AFDSLINE] column. Maybe the application has been changed to put less data there.

            – Josh Darnell
            May 17 at 11:31

















          • I edited my question with the results of the execution of your query. What I can see is a big difference in the first row where there's a avg value higher than in the first table

            – Galma88
            May 17 at 7:54







          • 1





            @Galma88 That confirms my theory. You have older data in the history table, and both the number of LOB_DATA rows, and the avg size of rows in the clustered index, is higher. This means your more recent rows, in the live table, have less data into the [AFDSLINE] column. Maybe the application has been changed to put less data there.

            – Josh Darnell
            May 17 at 11:31
















          I edited my question with the results of the execution of your query. What I can see is a big difference in the first row where there's a avg value higher than in the first table

          – Galma88
          May 17 at 7:54






          I edited my question with the results of the execution of your query. What I can see is a big difference in the first row where there's a avg value higher than in the first table

          – Galma88
          May 17 at 7:54





          1




          1





          @Galma88 That confirms my theory. You have older data in the history table, and both the number of LOB_DATA rows, and the avg size of rows in the clustered index, is higher. This means your more recent rows, in the live table, have less data into the [AFDSLINE] column. Maybe the application has been changed to put less data there.

          – Josh Darnell
          May 17 at 11:31





          @Galma88 That confirms my theory. You have older data in the history table, and both the number of LOB_DATA rows, and the avg size of rows in the clustered index, is higher. This means your more recent rows, in the live table, have less data into the [AFDSLINE] column. Maybe the application has been changed to put less data there.

          – Josh Darnell
          May 17 at 11:31










          Galma88 is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          Galma88 is a new contributor. Be nice, and check out our Code of Conduct.












          Galma88 is a new contributor. Be nice, and check out our Code of Conduct.











          Galma88 is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f238331%2funderstanding-the-differences-in-the-storage-space-used-by-two-tables%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?