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)
  • 相关阅读:
    关于C_Sharp集中处理异常
    关于Java连接SQL Sever数据库
    MongoDB 的主键 _id 为什么不是自增数字
    svn 命令行基本操作
    如何删除 Git 仓库中的历史提交记录
    .git 文件太大时怎样处理
    Git 提交到多个远程仓库
    Git SSH keygen 生成与配置
    Git 远端回滚
    Git 合并或修改线上 commit
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/9852002.html
Copyright © 2011-2022 走看看