// 序列表
Drop table if exists sequence;
create table if not exists sequence(
`name` varchar(50) not null,
`current_value` int(11) not null,
`increment` int(11) not null default '1'
)engine=myisam default charset=utf8 checksum=1 delay_key_write=1 row_format=dynamic comment='序列表,命名s_[table_name]';
insert into sequence (`name`,`current_value`,`increment`) values ('s_blog_account',0,1);
函数
drop function if exists `currval`;
delimiter//
create function `currval` ( seq_name varchar(50) ) returns int(11)
reads sql data
deterministic begin
declare value integer;
set value=0;
select current_value into value from sequence where name=seq_name;
return value;
end//
delimiter;
取值
drop function if exists `nextval`;
delimiter//
create function `nextval` (seq_name varchar(50)) returns int(11)
deterministic begin
update sequence set current_value=current_value+increment where name=seq_name;
return currval(seq_name);
end//
delimiter;
// get获取 系列 号
select nextval("s_blog_account");
mysql 之序列表,自增id作用
最新推荐文章于 2024-05-31 14:16:03 发布