zoukankan      html  css  js  c++  java
  • 插入失败时

    [root@yejr.me]> CREATE TABLE `t` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `c1` int(10) unsigned NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB;

    # 第一次插入,没问题
    [root@yejr.me]> insert into t select 0,rand()*1024;
    [root@yejr.me]> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    | 1 |
    +------------------+

    # 第二次插入,也没问题
    [root@yejr.me]> insert into t select 0,rand()*1024;
    [root@yejr.me]> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    | 2 |
    +------------------+

    # 第三次插入,故意制造一个重复主键,这次就不对了
    [root@yejr.me]> insert into t values(0,rand()*1024), (3, rand()*1024);
    ERROR 1062 (23000): Duplicate entry '3' for key 'PRIMARY'
    [root@yejr.me]> select last_insert_id(http://www.amjmh.com/v/BIBRGZ_558768/);
    +------------------+
    | last_insert_id() |
    +------------------+
    | 3 |
    +------------------+

    # 表中实际只有两条记录
    [root@yejr.me]> select * from t;
    +----+-----+
    | id | c1 |
    +----+-----+
    | 1 | 784 |
    | 2 | 574 |
    +----+-----+
    2 rows in set (0.00 sec)

  • 相关阅读:
    spring 管理struts2的一个问题
    Log4j的使用
    json
    jbpm
    jbpm的开发流程
    HTML5 INPUT新增属性
    JQuery Mobile
    struts2配置中通配符
    2010新的开始,先留个脚印。:)
    EyesBaby1.0使用帮助文档
  • 原文地址:https://www.cnblogs.com/ly570/p/11448343.html
Copyright © 2011-2022 走看看