Good morning,
We're noticing some unusual behaviour on one of our very old SQL 2005 (sp3) database servers and was wondering if anybody had come across anything similar.
Below is the schema of a temporary table which is used to briefly hold scanned image data before it is "finalised" and put into the main database table.
There are quite a few inserts and subsequent deletes on this table each day.
/****** Object: Table [dbo].[T_TempImages] Script Date: 18/09/2014 09:45:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[T_TempImages](
[ImageID] [uniqueidentifier] NOT NULL,
[ImageFile] [image] NULL,
[ScanBatchID] [uniqueidentifier] NULL,
[InsertDate] [datetime] NULL,
[KeepTogether] [bit] NULL,
CONSTRAINT [PK_T_TempImages] PRIMARY KEY CLUSTERED
(
[ImageID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[T_TempImages] ADD CONSTRAINT [DF_T_TempImages_InsertDate] DEFAULT (getdate()) FOR [InsertDate]
GO
ALTER TABLE [dbo].[T_TempImages] ADD CONSTRAINT [DF_T_TempImages_KeepTogether] DEFAULT ((0)) FOR [KeepTogether]
GO
So, what we are seeing is that the table seems to constantly grow and grow... so much so in fact that yesterday when we checked, the table was taking up 42GB when the ACTUAL data being held was only around 25mb...
I tried doing an index rebuild using the below command :
ALTER INDEX [PK_T_TempImages] ON [dbo].[T_TempImages] REBUILD WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO
But this did nothing (and the index fragmentation was only 40% in any case so I didnt expect this to have an effect).
The only way I was able to shrink the table was to drop it and rebuild it (i did this a little lazily by adding a new column as the first column using the table designer, saving, and then dropping it again).
Has anybody seen this before? Is there a fix out there? Can anybody think of a SQL command which will force a table rebuild that I can run regularly that doesnt require a lot of messing around? I was going to try and dynamically script
out all the defaults/columns/indexes etc, but this is quite a large task.
The rebuild I performed yesterday only took one or two seconds, so it isnt a slow process, and we have a regular maintenance window for this application.
I have tried considering dropping the primary key and recreating it, however this does not actually drop/rebuild the table (which I hoped it might) so does not release the space.
Regards,
Andy