Created
May 21, 2023 21:53
-
-
Save ifarbod/8d7c302d811ea3b900e8352836d92319 to your computer and use it in GitHub Desktop.
count the number of deleted rows using an after-delete trigger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- count the number of deleted rows using an after-delete trigger | |
-- sql server 2019 | |
CREATE TABLE Orders ( | |
OrderID int IDENTITY (1, 1) NOT NULL, | |
Names nchar (15) NULL, | |
) | |
GO CREATE TRIGGER Deleted ON Orders FOR DELETE AS | |
DECLARE @Count int | |
SELECT @Count = COUNT(*) | |
FROM DELETED IF @Count > 0 BEGIN PRINT @Count | |
END | |
GO | |
INSERT INTO Orders | |
values ('yes') | |
GO | |
DELETE FROM Orders | |
GO | |
INSERT INTO Orders | |
values ('yes'), | |
('yessss'), | |
('yesss'), | |
('yesss'), | |
('yesss') | |
GO | |
DELETE FROM Orders | |
GO DROP TRIGGER Deleted | |
GO DROP table Orders |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment