Hello!
- I use: Enterprise core edition SQL server
I am trying to understand how to compress a SQL table. Now I have looked at the GZIP algorithm, that would be interesting to test out as it offers a very good compression. This is my first time when it comes to compression, so I am not exactly sure how I will do this correctly. I have looked at the below link which shows that a compressed table only takes up 6% of the space which means that it offers very good compression.
https://www.mssqltips.com/sqlservertip/5709/using-compress-and-decompress-in-sql-server-to-save-disk-space/
I will try to tell what I now do step by step without compression.
Step 1: I create this table
CREATE TABLE [dbo].[table123] (
[_DateTime] SMALLDATETIME DEFAULT (getdate()) NOT NULL,
[_DayNr] TINYINT DEFAULT ((0)) NOT NULL,
[_CategoryNbr] TINYINT DEFAULT ((0)) NOT NULL,
[_FeatureNbr] SMALLINT DEFAULT ((-1)) NOT NULL,
[_Value] FLOAT (53) NULL,
[_Bool] BIT NULL,
CONSTRAINT [PK_table123] PRIMARY KEY CLUSTERED ([_DayNr] ASC, [_DateTime] ASC, [_CategoryNbr] ASC, [_FeatureNbr] ASC),
CONSTRAINT [UC_table123] UNIQUE NONCLUSTERED ([_FeatureNbr] ASC, [_DateTime] ASC)
);
Step 2: I now insert many rows at a time, usually about 100 rows at a time, to save overhead time and make the inserts faster more efficient
INSERT INTO table123 (
_DateTime,
_DayNr,
_CategoryNbr,
_FeatureNbr,
_Value,
_Bool
)
VALUES
('2010-08-01 17:00:00', 1, 1, 1, 12.4578941564, 1),
('2010-08-02 17:00:00', 2, 1, 1, 13.4578941564, 1),
('2010-08-03 17:00:00', 3, 1, 1, 14.4578941564, 1),
('2010-08-04 17:00:00', 4, 1, 1, 15.4578941564, 1);
Many questions at the same time now:
1. Am I thinking correct by saving overhead/time by inserting multiple rows at a time like this?
2. Now I simply wonder. How can I apply the GZIP compress algorithm for all those 4 rows(with all column values) while I insert them to the table like above, - is my big question now, I beleive. At the very same time, I wonder if the GZIP algorithm would offer the best/one the best compressions just thinking of taking up as low storage on the disk as possible. If not please be free to tell me a better compression method for this table?
I beleive it must be possible to query/extract the values without uncompressing the data, if this is possible(Here then thinking of if not all compression methods can do that)
Thank you!