I have a regular program in our .NET web application that allows a user on our platform to clear their account (i.e. delete all their data). This procedure runs in a stored procedure and essentially goes through the corresponding data tables and clears all the different elements that they created.
The stored procedure looks something like this.
ALTER procedure [dbo].[spDeleteAccountData](
@accountNumber varchar(30) )
AS
BEGIN
SET ANSI_NULLS ON ;
SET NOCOUNT ON;
BEGIN TRAN
BEGIN TRY
DELETE FROM myDataTable1 WHERE accountNumber = @accountNumber
DELETE FROM myDataTable2 WHERE accountNumber = @accountNumber
DELETE FROM myDataTable3 WHERE accountNumber = @accountNumber
//Etc.........
END TRY
BEGIN CATCH
//CATCH ERROR
END CATCH
IF @@TRANCOUNT > 0
COMMIT TRANSACTION;
SET ANSI_NULLS OFF;
SET NOCOUNT OFF;
END
The problem is that in some cases we can have more than 10,000 lines on the table, and the procedure can take up to 3-5 minutes. During this period, all other connections in the database receive throttling, causing timeout errors, such as below:
System.Data.SqlClient.SqlException (0x80131904): Timed out. The wait period expires before the operation is completed or the server is not responding.
- , ? , , , ! , , , , .
:
: 16:52 GMT
20 . 5 . 200 000, 1000-2000 .