--生成表语句
CREATE TABLE tb_sequence (
NAME VARCHAR (50) NOT NULL,
current_value INT NOT NULL,
_increment INT NOT NULL DEFAULT 1,
PRIMARY KEY (NAME)
);
---创建函数
create function _nextval(n varchar(50)) returns integer
begin
declare _cur int;
set _cur=(select current_value from tb_sequence where name= n);
update tb_sequence
set current_value = _cur + _increment
where name=n ;
return _cur;
end;
DELIMITER ;
--插入
insert into tb_sequence values('userid',1000,1);
--查询结果
select _nextval('userid');