Posts

Showing posts from October, 2013

SQL Server - Delete Large table data with Where clause

If we want to delete data from large table with some where caluse, the best way to do is : Select COUNT(*)  FROM  [Server].[Database].[MyTable]  WHERE ... By doing above we can know the count of records to be deleted. DECLARE @RowsDeleted INTEGER DECLARE @RowsToDeleteAtATime SET @RowsDeleted = 1 SET  @RowsToDeleteAtATime = 50000 WHILE (@RowsDeleted > 0)     BEGIN         DELETE TOP ( @RowsToDeleteAtATime ) FROM [Server].[Database].[MyTable] WHERE ...         SET @RowsDeleted = @@ROWCOUNT     END And by doing : Select COUNT(*)  FROM [Server].[Database].[MyTable] WHERE ... We can know the status.