I have database table contains around 3 millions records. When I delete large number of rows, around 400,000 records, the transaction takes forever to finish.
The table is not partitioned and the database is running on Sql Server 2012 Standard Edition. I'm using Nhibernate as ORM.
How do I make the transaction faster?
Here the creation script of the table
/****** Object: Table [dbo].[ES_DirectorDataParameters] Script Date: 03/10/2016 4:10:30 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[ES_DirectorDataParameters](
[DDP_ID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[DP_Name] [varchar](255) NOT NULL,
[D_ID] [numeric](18, 0) NOT NULL,
[DDP_DisplayName] [varchar](255) NULL,
[DDP_Visibility] [varchar](50) NULL,
[DDP_Replicable] [numeric](18, 0) NOT NULL CONSTRAINT [DF_ES_DirectorDataParameters_DD_Replicable] DEFAULT ((1)),
CONSTRAINT [PK_ES_DirectorDataParameters] PRIMARY KEY CLUSTERED
(
[DP_Name] ASC,
[D_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[ES_DirectorDataParameters] WITH CHECK ADD CONSTRAINT [FK_ES_DirectorDataParameters_ES_DataParameters] FOREIGN KEY([DP_Name])
REFERENCES [dbo].[ES_DataParameters] ([DP_Name])
GO
ALTER TABLE [dbo].[ES_DirectorDataParameters] CHECK CONSTRAINT [FK_ES_DirectorDataParameters_ES_DataParameters]
GO
ALTER TABLE [dbo].[ES_DirectorDataParameters] WITH CHECK ADD CONSTRAINT [FK_ES_DirectorDataParameters_ES_Directors] FOREIGN KEY([D_ID])
REFERENCES [dbo].[ES_Directors] ([D_ID])
GO
ALTER TABLE [dbo].[ES_DirectorDataParameters] CHECK CONSTRAINT [FK_ES_DirectorDataParameters_ES_Directors]
GO
here is the delete statement I found in the Activity Monitor when executing the delete (deleting around 200000 rows)
DELETE FROM ES_DirectorDataParameters WHERE DDP_ID = @p0
Note: Creating Cluster Index for the column DDP_ID helped the deletion performance slightly
Thanks