Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Expert Performance Indexing for SQL Server 2012 for $15Cardinality Estimate and Computed Columns »
    comments

    I took a backup of one of our test databases today and gave it to someone so that it could be restored on one of their servers.

    I got back the following in an email from the person who tried to do the restore



    Date 11/16/2012 12:58:16 PM
    Log SQL Server (Current - 11/16/2012 1:00:00 PM)

    Source spid76

    Message
    Database 'YourCrappyDB' cannot be started in this edition of SQL Server because part or all of object 'CrappyIndexData' is enabled with data compression or vardecimal storage format. Data compression and vardecimal storage format are only supported on SQL Server Enterprise Edition.

    Okay, so they are running the standard edition of SQL Server. How can you quickly find all the tables and indexes that use compression? Let's take a look, first we are going to create three tables, a heap, a table with a non clustered index and a table with a clustered index

    A table without indexes (a heap)

    1. CREATE TABLE TestCompress(SomeCol VARCHAR(1000))
    2. GO
    3.  
    4. ALTER TABLE TestCompress
    5. REBUILD PARTITION = ALL WITH (DATA_COMPRESSION =  PAGE)

    A table with a non clustered index

    1. --Non clustered index
    2. CREATE TABLE TestCompress2(SomeCol VARCHAR(100) NOT null)
    3. GO
    4.  
    5. CREATE NONCLUSTERED INDEX IX_TestCompress2
    6.     ON TestCompress2 (SomeCol)
    7. WITH ( DATA_COMPRESSION = ROW ) ;
    8. GO

    A table with a clustered index

    1. --Clustered index
    2. CREATE TABLE TestCompress3(SomeCol VARCHAR(100) NOT null)
    3. GO
    4.  
    5. CREATE CLUSTERED INDEX IX_TestCompress3
    6.     ON TestCompress3 (SomeCol)
    7. WITH ( DATA_COMPRESSION = ROW ) ;
    8. GO

    Here is the query that will give you the table name, the storage type, the index name if there is one and the type of compression

    1. SELECT DISTINCT
    2. SCHEMA_NAME(o.schema_id)  + '.' + OBJECT_NAME(o.object_id) AS TableName,
    3. i.name AS IndexName,
    4. p.data_compression_desc AS CompressionType,
    5. i.type_desc AS StorageType
    6. FROM sys.partitions  p
    7. INNER JOIN sys.objects o
    8. ON p.object_id = o.object_id
    9. JOIN sys.indexes i
    10. ON p.object_id = i.object_id
    11. AND i.index_id = p.index_id
    12. WHERE p.data_compression > 0
    13. AND SCHEMA_NAME(o.schema_id) <> 'SYS'

    Here is the output of that query

    TableName IndexName CompressionType StorageType
    dbo.TestCompress NULL PAGE HEAP
    dbo.TestCompress2 IX_TestCompress2 ROW NONCLUSTERED
    dbo.TestCompress3 IX_TestCompress3 ROW CLUSTERED

    Now why do I have a distinct in my query? The reason is that if you have your indexes/tables partitioned you will get more than one row per index. you can add p.rows to the select portion of the queries and you will see how many rows each partition holds

    Hopefully this will help someone in the future

    About the Author

    User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
    Social SitingsTwitterFacebookLinkedInHomePageFlickrLTD RSS Feed
    3655 views
    InstapaperVote on HN

    2 comments

    Comment from: Steve Bergkamp [Visitor]
    Steve Bergkamp Denis:
    Nice post, the query will be most helpful.
    I haven't encountered a situation where I had only part of a schema compressed.

    I got to wondering, how one would go about creating a backup of this database so that it could be restored onto a "Standard" version of SQL server.

    Backup with no compression ?
    or ?

    Thanks
    Steve B.
    11/17/12 @ 11:14
    Comment from: SQLDenis [Member] Email
    SQLDenis Steve,

    You would have to recreate the tables/indexes without compression

    You could do a backup and restore on a developer/enterprose edition first if you don't want to make changes on a current live server, you can't just do a backup without compression to fix this
    11/17/12 @ 11:22

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)