Mysql Error when creating trigger -


error note:error : have error in sql syntax; check manual corresponds mysql server version right syntax use near '@sum int default 0;     set @sum=(select count(*) inserted);     if @sum>1     ' @ line 5 

and code:

delimiter //  create trigger insert_only_one  after insert on sc  each row  begin  declare @sum int default 0;  set @sum=(select count(*) inserted);  if @sum>1  print('dont insert more 1 record');  rollback transaction  end 

the error note shows have error @ line 5. tried int(5) or 'int', or without default 0 still can't work.

you don't need declare variable because using @sum variable initialized automatically..

you can't print inside trigger...

also command rollback transaction invalid mysql. use rollback semicolon..


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -