This function compresses the input expression, using the GZIP algorithm. The function returns a byte array of type varbinary(max).
Transact-SQL Syntax Conventions
expression
A
or
expression. See Expressions (Transact-SQL) for more information.
varbinary(max) representing the compressed content of the input.
Compressed data cannot be indexed.
The COMPRESS
function compresses the input expression data. You must invoke this function for each data section to compress. See Data Compression for more information about automatic data compression during storage at the row or page level.
This example shows how to compress data inserted into a table:
INSERT INTO player (name, surname, info )
VALUES (N'Ovidiu', N'Cracium',
COMPRESS(N'{"sport":"Tennis","age": 28,"rank":1,"points":15258, turn":17}'));
INSERT INTO player (name, surname, info )
VALUES (N'Michael', N'Raheem', compress(@info));
This statement first deletes old player records from the player
table. To save space, it then stores the records in the inactivePlayer
table, in a compressed format.
DELETE player
WHERE datemodified < @startOfYear
OUTPUT id, name, surname datemodifier, COMPRESS(info)
INTO dbo.inactivePlayers ;