• mysql select last_insert_id()函数返回的值


    mysql> create table j(id int primary key auto_increment, name varchar(10));

    创建表j

    插入数据

    mysql> insert into j(name) values('wanggiqpg');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select last_insert_id() from j;
    +------------------+
    | last_insert_id() |
    +------------------+
    |                1 |
    +------------------+
    1 row in set (0.00 sec)

    再插入一些数据

    mysql> insert into j(name) values('wanggiqpg'),('chengyn'),('wanggiqpg'),('chengyn'),('wanggiqpg'),('chengyn'),('wanggiqpg'),('chengyn'),('wanggiqpg') ,('chengyn'),('wanggiqpg'),('chengyn');
    mysql> select * from j;
    +----+-----------+
    | id | name |
    +----+-----------+
    | 1 | wanggiqpg |
    | 2 | wanggiqpg |
    | 3 | chengyn |
    | 4 | wanggiqpg |
    | 5 | chengyn |
    | 6 | wanggiqpg |
    | 7 | chengyn |
    | 8 | wanggiqpg |
    | 9 | chengyn |
    | 10 | wanggiqpg |
    | 11 | chengyn |
    | 12 | wanggiqpg |
    | 13 | chengyn |
    +----+-----------+
    mysql> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    |                2 |
    +------------------+

    判断可知

    select last_insert_id();得到的是上一条insert或者update语句开始执行时开始的自增ID
  • 相关阅读:
    git 镜像地址
    IntelliJ IDEA 2019 控制台中文乱码问题
    LINUX配置本地YUM源
    动态添加js的代码
    Java 多线程
    Java I/O系统
    Java 中的容器 Collection 和 Map
    Java 数组
    javaweb的四大作用域
    三层 转自http://git.oschina.net/tzhsweet/superui
  • 原文地址:https://www.cnblogs.com/wang666/p/9254721.html
Copyright © 2020-2023  润新知