Friday 12 April 2013

what is Magic table in Sqlserver

   The following tables are called magic tables.
  1.  Inserted
  2. Deleted
  3. updated
  Inserted table: 
                      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