V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
RoxyBrowser - 轻盈、安全的指纹浏览器
Roxy 凭借领先的指纹反追踪技术,助力隐私保护、跨境电商、数据采集等场景,为您的卓越事业保驾护航。
Promoted by RoxyBrowser
quietin
V2EX  ›  MySQL

关于插入纪录时进 set id=0 无效的问题

  •  
  •   quietin · 2016-01-11 19:57:51 +08:00 · 2596 次点击
    这是一个创建于 3483 天前的主题,其中的信息可能已经有所发展或是发生改变。

    +------------+--------------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +------------+--------------+------+-----+---------+----------------+
    | id | int(11) | NO | PRI | NULL | auto_increment |
    | desc | varchar(100) | NO | | NULL | |
    +------------+--------------+------+-----+---------+----------------+

    对于这样的表,如果插入 id 为 0 的纪录,会插入成功,但插入的纪录 id 不为 0 而是自增后的值,但是 id 为-1 时,则能成功插入并且 id=-1 ,这是为什么?

    insert into content_cornermark set id=-1, content_cornermark.desc='无';

    3 条回复    2016-01-12 15:14:37 +08:00
    geeglo
        1
    geeglo  
       2016-01-11 20:01:27 +08:00
    -1 在 int 的范围中
    msg7086
        2
    msg7086  
       2016-01-12 02:15:20 +08:00   ❤️ 1
    Let me google that for you:
    http://stackoverflow.com/a/1142588
    quietin
        3
    quietin  
    OP
       2016-01-12 15:14:37 +08:00
    @geeglo 0 难道不是 int 么
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2389 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:34 · PVG 18:34 · LAX 03:34 · JFK 06:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.