Tuesday, July 18, 2023

SQL Server -How to check truncation/ all rows deleted status of the table in SQL Server Database

We can check truncation/ all rows deleted status by using the below query. E.g. Employee is a table.

SELECT object_Name(object_id)
	,[Rows] AS RowCounts
FROM sys.partitions 

WHERE object_id = object_id('Employee')

We can use this query in the SQL Agent to notify  required team if there will be a requirement of notification too.

IF (
		SELECT [Rows] AS RowCounts
		FROM sys.partitions
		WHERE object_id = object_id('Employee')
		) <= 0
BEGIN
	PRINT 'Write send email code' 

END 

No comments:

Post a Comment