zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    nginx端口被占用解决方案
    linux安装pip报错
    小程序学习-小程序特点及适用场景
    总结行内元素与块级元素
    重装系统之无法在驱动器0的分区1上安装windows
    重装系统之win10不能进入bios界面
    重装系统之U盘设为第一启动项
    重装系统之制作U盘启动盘
    Vue-条件渲染v-if与v-show
    Cookie与Session
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/9852002.html
Copyright © 2011-2022 走看看