Wandenkolk さんのプロフィールWandenkolk Netoフォトブログつながりその他 ツール ヘルプ
8月14日

All about data compression on SQL Server

Thanks to Luciano Palmas´s article

http://technet.microsoft.com/pt-br/library/dd979521.aspx   --  In portuguese

Using Sparse columns  --  http://technet.microsoft.com/en-us/library/cc280604.aspx

Complementary to sparse columns, filetered indwx --  http://technet.microsoft.com/en-us/library/cc280372.aspx

Row Compression -- http://technet.microsoft.com/pt-br/library/cc280576.aspx

page compression -- http://technet.microsoft.com/pt-br/library/cc280464.aspx

Estimating the compression result from a table, very useful

EXEC sp_estimate_data_compression_savings 'Producao', 'TabelaDePedidos',
NULL, NULL, 'ROW';

Very very very cool…

Besides you got the Backup compression.

8月3日

Dense_rank

Rank fucntions allows us to no simply classify data, but instead of it to rank that data based on two different criteria.

1. The column you use to partition the information

2. The column you use to order the information

The rank column is automatically numbered based on the both criteria mentioned above.

Take a look at the query

USE AdventureWorks;
GO
SELECT i.ProductID, p.Name, i.LocationID, i.Quantity,
    DENSE_RANK() OVER (PARTITION BY i.LocationID ORDER BY i.Quantity)     AS [Rank]
FROM Production.ProductInventory i
    INNER JOIN Production.Product p
        ON i.ProductID = p.ProductID
ORDER BY LocationID, [Rank] ;
GO

-- it creates a column rank, which creates a ranking based on the sales of the productions done at the same location and based on the quantity sold.

 

image

 

The rank and dense_rank functions acts on a similar way.

Let us check another one the NTILE function. Look at the example.

USE AdventureWorks;
GO
SELECT c.FirstName, c.LastName
    ,NTILE(4) OVER(ORDER BY SalesYTD DESC) AS 'Quartile'
    ,s.SalesYTD, a.PostalCode
FROM Sales.SalesPerson s
    INNER JOIN Person.Contact c
        ON s.SalesPersonID = c.ContactID
    INNER JOIN Person.Address a
        ON a.AddressID = c.ContactID
WHERE TerritoryID IS NOT NULL
    AND SalesYTD <> 0;
GO

 

image

 

It actually creates a Quartile column, creating four groups by the division in such groups of the ordered values on the SalesYTD column.  With the NTILE function we can create a rank of an specified number of groups as we wish.  We can create 10 groups of customers for example, based on their income, or their average ticket.

We can create an statistically correct sample for analisys, for example, excluding the extremes, the greatest and the worst customers we got based on a spacified criteria.