简体   繁体   中英

Saving Space For Archive Table In SQL Server

I have a SQL 2008 table with 773,705,261 rows in the table. I want to create an archive table to archive off the data, but I want to reduce the amount of space required for this data. Speed of accessing the archived data is not the primary concern, but is always desired.

The current table definition is something like this:

TableID     (PK)    BIGINT      NOT NULL
DocumentID  (FK)    BIGINT      NOT NULL
StatusID    (FK)    INT         NOT NULL
RowCreateDate       DATETIME    NOT NULL

With my calculation, the current table uses 28 bytes per row in the table. The problem is that for each DocumentID it could have 6 – 10 rows in this table (the amount of rows per DocumentID could grow in the future too) depending on the amount of Statuses that the system processed.

My first thought of reducing the amount of space required to store this data is to have 1 row for each DocumentID and have an XML field containing all of the StatusIDs and Times they occurred. Something like this:

TableID     (PK)    BIGINT      NOT NULL
DocumentID  (FK)    BIGINT      NOT NULL
Statuses            XML         NOT NULL

Does anyone have any recommendations for me? Any methods I can research?

Set your archive table to use page compression.

From BOL

CREATE TABLE dbo.T1 
(c1 int, c2 nvarchar(200) )
WITH (DATA_COMPRESSION = PAGE);

If you do not expect to be doing any updates or deletes from your archive table (well deletes that aren't off either end of the table) then I would also create a clustered index using a fillfactor of 100%. That way there will not be any space left in each page.

Of course I would look at both in BOL before actually applying anything.

You may be able to use INT data type for TableID and DocumentID, and SMALLINT or TINYINT for StatusID. Depending on the precision you need from the RowCreateDate column, you may be able to use SMALLDATETIME or DATE . These data types use less disk space and will save you several GB over your 775,000,000 rows.

Kenneth's suggestions of using page compression and FILLFACTOR = 100 are definitely worth considering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM