zoukankan      html  css  js  c++  java
  • mysql auto_increment

    1。 创建表的时候定义:

    create table test ( id int primary key auto_increment)

    2.  创建表的时候指定auto_increment的起始值

    create table test(id int primary key auto_incrment) auto_increment = 100;

    start with 100.... default is 1;

    3.去掉自增属性后,其默认值将变为0

    alter table test modify column id int;

    4.为字段添加auto_increment属性

    alter table test modify column id int auto_increment;

    5. 修改字段的初始值

    alert table test auto_increment = 200;

    6. 怎样查看一个表的auto_increment的下一个自增ID值

    我们知道getLastInsertID()属性只是获取插入记录之后的最大ID,并不是我们想要的,所以我们采用

    show table status like 'tablename', 里面包含Auto_increment的字段

    第二:

    use information_schema;

    select Auto_increment from tables where table_name = 'table_name';

    其中information_schema一般用户无法访问.

    7. 修改全局自增参数:

    利用 show variables like 'AUTO_INCREMENT% ';

    我们将看到

    auto_increment_increment, auto_increment_offset, 它们代表全局的起始值和步进,通过如下方式修改:

    set auto_increment_increment = 100;

    set auto_increment_offset = 10 ;

    这将对全局的auto_increment列产生影响,建议慎用!

  • 相关阅读:
    【Java基础】for循环
    【java基础】for循环一些小例子
    ELK日志搜索引擎
    Spring boot 环境搭建
    【java基础】三元运算符&语句结构
    【接口自动化】正则表达式
    mysql 数据库表的基本操作
    centos下安装jenkins
    问题 H: 例题5-8 Fibonacci数列
    数字特征值
  • 原文地址:https://www.cnblogs.com/JohnChen-happy/p/4432878.html
Copyright © 2011-2022 走看看