zoukankan      html  css  js  c++  java
  • 当 LAST_INSERT_ID() 带有参数时# 清空重来

    [root@yejr.me]> truncate table t;

    # 插入1条新记录
    [root@yejr.me]> insert into t select 0,rand()*1024;

    # 查看 last_insert_id(), 符合预期
    [root@yejr.me]> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    | 1 |
    +------------------+

    [root@yejr.me]> select * from t;
    +----+-----+
    | id | c1 |
    +----+-----+
    | 1 | 730 |
    +----+-----+

    # 调用 last_insert_id() 时增加表达式
    [root@yejr.me]> select last_insert_id(id+2) from t;
    +----------------------+
    | last_insert_id(id+2) |
    +----------------------+
    | 3 |
    +----------------------+

    # 再看 last_insert_id() 的值,好像“又不符合预期”了
    [root@yejr.me]> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    | 3 |
    +------------------+

    # 插入1条新纪录
    [root@yejr.me]> insert into t select 0,rand()*1024;

    # 再看 last_insert_id() 的值,好像“又回到正轨”了
    [root@yejr.me]> select last_insert_id();
    +------------------+
    | last_insert_id(http://www.amjmh.com) |
    +------------------+
    | 2 |
    +------------------+

    [root@yejr.me]> select * from t;
    +----+-----+
    | id | c1 |
    +----+-----+
    | 1 | 730 |
    | 2 | 600 |
    +----+-----+
    2 rows in set (0.00 sec)

  • 相关阅读:
    第十五篇 -- 学习第十四天打卡20190702
    第三篇 -- 方向
    第十四篇 -- 学习第十三天打卡20190701
    yum更换阿里源
    Jenkins+sonar7.3集成
    xshell 5 书写汉字乱码
    zabbix 短信报警
    zabbix 微信报警
    zabbix邮件报警
    zabbix主动监测客户端设置
  • 原文地址:https://www.cnblogs.com/ly570/p/11448345.html
Copyright © 2011-2022 走看看