mysql sequence 实现

-- ----------------------------
-- 添加表tbl_sequence
-- ----------------------------
DROP TABLE IF EXISTS `tbl_sequence`;
CREATE TABLE tbl_sequence (
  seq_name VARCHAR(50) NOT NULL COMMENT '序列名称',
  min_value bigint(20) NOT NULL COMMENT '最小值',
  max_value bigint(20) NOT NULL COMMENT '最大值',
  current_val bigint(20) NOT NULL COMMENT '当前值',
  increment_val INT DEFAULT '1' NOT NULL COMMENT '增长步数',
  remark VARCHAR(500) DEFAULT null  COMMENT '备注',
  PRIMARY KEY (seq_name)
  )ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='sequence表';
-- ----------------------------
-- 添加表单据编号sequence
-- 插入数据前判断,防止数据重复插入
-- ----------------------------
insert into tbl_sequence (seq_name, min_value, max_value, current_val, increment_val,remark)
select 'depot_number_seq', 1, 999999999999999999, 1, 1,'单据编号sequence' from dual where not exists
(select * from tbl_sequence where  seq_name='depot_number_seq');

1 打赏
打赏 1 积分后可见