In the upcoming version of SQL 2016 a new component of COMPRESS and DECOMPRESS T-SQL functions is added. SQL Server 2016 provides built in functions for compression and decompression.The COMPRESS and DECOMPRESS functions can store and retrieve data using the GZIP compression algorithm. Like you would expect the COMPRESS function compressed data before it is stored in a column or variable. It returns a binary data. The DECOMPRESS function is used to decompress the binary data and return the decompressed version of that data. We need to cast a binary data to text if we compressed the text data.
- CREATE TABLE Person (_id int primary
key identity,name
varchar(max),surname
varchar(max),infobinary(max))
Now, we can directly load compressed information into this column.
-INSERT INTO People (name, surname,
info) SELECT FirstName, LastName,
COMPRESS(AdditionalInfo) FROM
People.People
Now we can forward the compressed data directly to client who can decompress it, or we can decompress the same data in query:
- SELECT name, surname, DECOMPRESS(info) AS original
FROM Person
0 Comment(s)