Mendapatkan nilai autoincrement untuk ‘before insert trigger’


auto increment dapat diperoleh dari table information_schema

delimiter |
create trigger no_fb
before insert on clients
for each row
begin
declare next_id int;
declare branch varchar(5);
select abbr into branch from branches where id=new.branch_id;
set next_id = (select auto_increment from information_schema.tables where table_schema=database() and table_name='clients');
set new.no_fb=concat(branch,'-',year(curdate()),month(curdate()),'-',lpad(next_id,4,'0'));
end|
delimiter ;

About abunajiyah
A Programmer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: