sql server - Query in trigger doesn't give expected result -


i tried following output through triggers in sql server 2005. i'm using query change values of age (column name) zero, if less zero.

create trigger agecheck  on account  insert  begin     declare @age int      select @age = age      inserted       if @age < 0         set @age = 0;  

end

i able execute query successfully, i'm not getting desired result. i'm using sql server 2005.

could please suggest on this.

what doing in trigger setting variable @age 0 if less 0. selecting age variable that, doesn't link variable field in table.

not that, inserted virtual table can have more 1 row in it. select statement assign last age returned query variable.

what need join table inserted in, inserted virtual table on primary key.

assuming account table has key account_id, give following create statement:

create trigger agecheck    on account   after insert  begin   update     account   set     age=0       inserted     inner join account on       a.account_id=i.account_id       i.age<0 end 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -