I just created a Instead After Trigger whose syntax is given below:
Create trigger tgrInsteadTrigger on copytableto
Instead of Insert as
Declare @store_name varchar(30);
declare @sales int;
declare @date datetime;
select @store_name = i.store_name from inserted i
select @sales = i.sales from inserted i
select @date = i.Date from inserted i
begin
if (@sales > 1000)
begin
RAISERROR('Cannot Insert where salary > 1000',16,1); ROLLBACK;
end
else
begin
insert into copytablefrom(store_name, sales, date) values (@store_name, @sales, @date);
Print 'Instead After Trigger Executed';
end
End
In the above syntax I have used RAISERROR('Cannot Insert where salary > 1000',16,1)
But when I write RAISERROR('Cannot Insert where salary > 1000')
it gives the error "Incorrect syntax near ')'" on the same line.
Can anyone please explain the use of (16,1) here.
RaIsError
is explained here.inserted
, whereas in fact there can be 0, 1, or many rows ininserted
.RAISERROR
and to useTHROW
instead.