• mysql 约束条件 auto_increment 自动增长 修改自增字段起始值


    创建一张表 t20

    mysql> create table t20( id int primary key auto_increment, name char(16) );
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> desc t20;
    +-------+----------+------+-----+---------+----------------+
    | Field | Type     | Null | Key | Default | Extra          |
    +-------+----------+------+-----+---------+----------------+
    | id    | int(11)  | NO   | PRI | NULL    | auto_increment |
    | name  | char(16) | YES  |     | NULL    |                |
    +-------+----------+------+-----+---------+----------------+
    2 rows in set (0.00 sec)

    修改自增字段为3 下次插入新纪录 从3开始

    mysql> alter table t20 auto_increment=3;
    Query OK, 0 rows affected (0.00 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    mysql> show create  table t20G;
    *************************** 1. row ***************************
           Table: t20
    Create Table: CREATE TABLE `t20` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `name` char(16) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
    1 row in set (0.00 sec)

    插入记录

    mysql> insert into t20(name) values('mike');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select * from t20;
    +----+------+
    | id | name |
    +----+------+
    |  3 | mike |
    +----+------+
    1 row in set (0.00 sec)
    mysql> show create  table t20G;
    *************************** 1. row ***************************
           Table: t20
    Create Table: CREATE TABLE `t20` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `name` char(16) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
    1 row in set (0.00 sec)
  • 相关阅读:
    CAP分布式
    专职DBA-MySQL数据库开篇
    os.sep
    DocStrings
    Python如何获取脚本的参数
    LVM基础命令
    VoAndEntityTrans
    短信倒计时
    springboot在eclipse上搭建项目一(无页面)
    springboot问题
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/9852002.html
Copyright © 2020-2023  润新知