Insert Trigger
CREATE TRIGGER trig_addAuthor ON [dbo].[Emp]
FOR INSERT
AS
DECLARE @newName VARCHAR(100)
SELECT @newName = (SELECT ename FROM Inserted)
-- Print the name of the new author
PRINT 'New author "' + @newName + '" added.'
Update Trigger
CREATE TRIGGER trig_updateemp
ON emp
FOR UPDATE
AS
DECLARE @oldName VARCHAR(100)
DECLARE @newName VARCHAR(100)
IF NOT UPDATE(ename)
BEGIN
RETURN
END
SELECT @oldName = (SELECT ename FROM Deleted)
SELECT @newName = (SELECT ename FROM Inserted)
PRINT 'Name changed from "' + @oldName + '" to "' + @newName + '"'
This entry was posted
on Thursday, October 08, 2009
and is filed under
Sql
.
You can leave a response
and follow any responses to this entry through the
Subscribe to:
Post Comments (Atom)
.
thanks 4 the info