I'm running daily tasks of deleting historical data as a SQL server jobs. How do I print how many rows were affected in each run?
Here's a step in the job I'm interested in (replaced the actual DB name with "Database_Name_Here")
Print CAST(GETDATE() as Datetime2 (3) )
DECLARE @Deleted_Rows_1 INT;
SET @Deleted_Rows_1 = 1;
WHILE (@Deleted_Rows_1 > 0)
BEGIN
BEGIN TRANSACTION
delete top (1000) FROM [Database_Name_Here].[dbo].[SESSION_LOG]
where start_timestamp < DATEADD(MONTH, -22, GETDATE())
SET @Deleted_Rows_1 = @@ROWCOUNT;
COMMIT TRANSACTION
CHECKPOINT
END
If I run it from SSMS, I can see this in the messages: (1020 row(s) affected) DBCC execution completed. If DBCC printed error messages, contact your system administrator.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.