The following tables are called magic tables.
The record effected by insert command is copied to inserted table .
Deleted table :
The record effected by delete command is copied to deleted table.
Updated table:
the record effected by update command is copied to both inserted table and deleted table. the old values are copied to deleted table and new values are copied to inserted table.
example: create a trigger don't to allow to decrements the salary of employee?
create trigger t3 on emp
after update
as
begin
declare @oldsal smallmoney
declare @newsal smallmoney
select @oldsal=salary from deleted
select @newsal=salary from inserted
if @oldsal>@newsal
begin
rollback
raiserror('not allowed to decrements',15,1)
end
end
- Inserted
- Deleted
- updated
The record effected by insert command is copied to inserted table .
Deleted table :
The record effected by delete command is copied to deleted table.
Updated table:
the record effected by update command is copied to both inserted table and deleted table. the old values are copied to deleted table and new values are copied to inserted table.
example: create a trigger don't to allow to decrements the salary of employee?
create trigger t3 on emp
after update
as
begin
declare @oldsal smallmoney
declare @newsal smallmoney
select @oldsal=salary from deleted
select @newsal=salary from inserted
if @oldsal>@newsal
begin
rollback
raiserror('not allowed to decrements',15,1)
end
end
No comments:
Post a Comment