未加星标

Compress & Decompress new Feature in SQL SERVER 2016 #2

字体大小 | |
[数据库(mssql) 所属分类 数据库(mssql) | 发布者 店小二03 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

This is another article in the series of SQL SERVER 2016 Journey . I am pretty much sure you might aware of Gzip Compression algorithm . If not then try this link .

So, SQL SERVER 2016 introduce this two awesome functions for C ompress & Decompress the data.

Before SQL SERVER 2016 version we have data compression feature like Page & Row compression ( check Previous post for it Link ) which is different then this column value compression.

In SQL SERVER 2016 Compress function, data compression is done via GZIP algorithm and return VARBINARY(MAX).

Below is the simple syntax of Compress function

Compress (Expression)

Here Expression can be nvarchar(n), nvarchar(max), varchar(n), varchar(max), varbinary(n), varbinary(max), char(n), nchar(n), or binary(n)

Decompress function is just opposite of compress function. It is used to decompress the value of VARBINARY which is converted using Compress function. The only tweak is you need to cast the output of Decompress function in specific data type to make it readable (if using varchar ,nvarchar compression) .

below is the simple syntax of

Decompress

Decompress (Compressed string)

Let’s understand this via an example as shown below .


Compress & Decompress new Feature in SQL SERVER 2016 #2

In this example I have taken 3 tables with exact same schema & data

1) IndiandotnetFriends 2) IndiandotnetFriends_Compress 3) IndiandotneFriends_Decompress

You can see snap in which we are inserting same data.

As the name suggested in first table normal data from Adventureworks’s person table.

In second table we are inserting compressed value of first Name and in 3rd table we are inserting decompress value of First Name from the Compressed table.

Now, let’s check compress & decompress table data


Compress & Decompress new Feature in SQL SERVER 2016 #2
is

Now, Your might thinking that the output of both compress and decompress is not readable.

So you are right to make data readable of Decompress table we need to type cast .

See below snap for same.


Compress & Decompress new Feature in SQL SERVER 2016 #2

Till now we know how to use this Compress & Decompress function . Now, let me share the benefit of using Compress. if you see below snap you will find that data length of compress is comparatively less than normal and decompressed data length .


Compress & Decompress new Feature in SQL SERVER 2016 #2

Obviously, compression helps you somewhere in the overall performance of your application.

The good point is you can pass the compress data to your .net application and decompress using GzipStream as well.

The only thing which we need to take care is type casting. Suppose your base column which compressed is VARCHAR then you need to typecast again in VARCHAR.

Now, next question is where we can use this functions. So, we can use in compressing large object like binary data in which we save jpg, pdf , word document etc..

I hope you will be excited in using this function.

Please, share your input.

RJ!

本文数据库(mssql)相关术语:熊片数据库 mssql数据库 oracle数据库 pubmed数据库 access数据库 万方数据库

主题: SQLRY
分页:12
转载请注明
本文标题:Compress & Decompress new Feature in SQL SERVER 2016 #2
本站链接:http://www.codesec.net/view/485468.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(mssql) | 评论(0) | 阅读(26)