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)

  • 相关阅读:
    Java ES api 查询例子
    leveldb学习
    Viewstamp Replication协议
    PacificA协议
    vhost架构
    数据分片方法
    常见分布式存储系统架构分析
    数据存储(B+树 vs LSM树)
    paxos算法理解
    Raft协议理解
  • 原文地址:https://www.cnblogs.com/ly570/p/11448343.html
Copyright © 2011-2022 走看看