Does Sql Server Compress Database size on similar data

可紊 提交于 2019-12-13 03:33:29

问题


Just to find out my would be DB size on production environment, I just populated my tables with 1.5 million rows of nearly same data (Except Primary key). It currently shows 261 MB...

Now, Whether I can rely on this, or since the Data is almost similar on all other columns the SQL server has compressed the size. ie. Will the size be different if the values in each rows are different...

Further.. Does even columns will null values contribute to the size of the DB ?

Thanks for your time...

Edit : Here is my schema... And I have made some indexes too...

    CREATE TABLE [dbo].[Trn_Tickets](
        [ObjectID] [bigint] IDENTITY(1,1) NOT NULL,
        [TicketSeqNo] [bigint] NULL,
        [BookSeqNo] [bigint] NULL,
        [MatchID] [int] NULL,
        [TicketNumber] [varchar](20) NULL,
        [BarCodeNumber] [varchar](20) NULL,
        [GateNo] [varchar](5) NULL,
        [EntryFrom] [varchar](10) NULL,
        [MRP] [decimal](9, 2) NULL,
        [Commission] [decimal](9, 2) NULL,
        [Discount] [decimal](9, 2) NULL,
        [CashPrice] [decimal](9, 2) NULL,
        [CashReceived] [decimal](9, 2) NULL,
        [BalanceDue] [decimal](9, 2) NULL,
        [CollectibleFrom] [char](1) NULL,
        [PlaceOfIssue] [varchar](20) NULL,
        [DateOfIssue] [datetime] NULL,
        [PlaceOfSale] [varchar](20) NULL,
        [AgentID] [int] NULL,
        [BuyerID] [int] NULL,
        [SaleTypeID] [tinyint] NULL,
        [SaleDate] [smalldatetime] NULL,
        [ApprovedBy] [varchar](15) NULL,
        [ApprovedDate] [smalldatetime] NULL,
        [InvoiceStatus] [char](1) NULL,
        [InvoiceRefNo] [varchar](15) NULL,
        [InvoiceDate] [smalldatetime] NULL,
        [BookPosition] [char](2) NULL,
        [TicketStatus] [char](2) NULL,
        [RecordStatus] [char](1) NULL,
        [ClosingStatus] [char](2) NULL,
        [ClosingDate] [datetime] NULL,
        [UpdatedDate] [datetime] NULL,
        [UpdatedUser] [varchar](10) NULL,
     CONSTRAINT [PK_Trn_Tickets] PRIMARY KEY CLUSTERED 
    (
        [ObjectID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]

Hope this helps


回答1:


SQL Server 2005 and 2008 Express will not compress your data. SQL Server 2008 can use page compression, but only on Enterprise Edition. NULL columns occupy one bit in the row.

From the description of your data, sounds more like a problem of ordinary normalization. Separate the repeat values into a lookup table, store only distinct combinations, join agaisnt the lookup table. This will save data by schema design and will work on all DB platforms, all versions, all SKUs.




回答2:


Replace ApprovedBy etc (varchar) with lookups to other tables

Do you need datetime?

Do you expect more then 4 billion rows? Why are the 1st 3 cols bigint?

Save a few bytes here and there = a big difference. Higher page density (eg more rows per 8k page) = less space + smaller indexes.

Compress when you have 1.5 billion rows.



来源:https://stackoverflow.com/questions/2299190/does-sql-server-compress-database-size-on-similar-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!