mysql - What's wrong with my SQL trigger -


i need sql trigger following:

when insert row in table user want 2 primary keys (id, year) following: 1 - 2016 2 - 2016 3 - 2016 1 - 2017 2 - 2017

so want autoincrement reset new year id column int(3) unsigned auto_increment field year column year field type

the trigger tried is

    create trigger reset before insert on user each row -- trigger creation     begin     select max(year) @x user; -- selecting max year table compare     if @x <> year(curdate()) -- if max table differs current     alter table user auto_increment=1; -- reset auto increment 1       end if;     end; 

but keeps saying there's error in sql syntax


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -