Collections:
"DELETED" - Old Record of an DML Event Instance in SQL Server
How To Access the Deleted Record of an Event in SQL Server?
✍: FYIcenter.com
When a DML event occurs, SQL Server will prepare a temporary table called "DELETED", which contains the old record of the affected row, which is:
The tutorial exercise below shows you how to improve the trigger, update_user, to report email changes on table, fyi_users, with both old and new emails:
USE FyiCenterData; GO ALTER TRIGGER update_user ON fyi_users AFTER UPDATE AS DECLARE @new VARCHAR(80); DECLARE @old VARCHAR(80); SELECT @new = email FROM INSERTED; SELECT @old = email FROM DELETED; PRINT 'Email changed from '+@old+' to '+@new; GO UPDATE fyi_users SET email='king@fyicenter' WHERE name = 'John King'; GO Email changed from john@fyicenter to king@fyicenter (1 row(s) affected)
INSERTED and DELETED are working as expected. The reported message is getting better.
⇒ Improving the Trigger to Handle NULL Values in SQL Server
⇐ "INSERTED" - New Record of an DML Event Instance in SQL Server
2016-10-24, 2073🔥, 0💬
Popular Posts:
How To Calculate Age in Days, Hours and Minutes in SQL Server Transact-SQL? On many Web sites, news ...
What are binary literals supported in SQL Server Transact-SQL? Binary literals in Transact-SQL are s...
How To Use "IF ... ELSE IF ..." Statement Structures in SQL Server Transact-SQL? "IF ... ELSE IF ......
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
How To Convert Binary Strings into Integers in SQL Server Transact-SQL? Binary strings and integers ...