mysql 之序列表,自增id作用

2 篇文章 0 订阅
2 篇文章 0 订阅
    // 序列表
    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");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值