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列产生影响,建议慎用!

  • 相关阅读:
    几个前端可能会遇到的小问题
    函数内部变量与该函数名冲突会怎样
    顺序表之删除算法
    顺序表之插入算法
    IPV4和IPV6的区别
    win10关闭自动更新
    spring常见十大异常
    java中list和Arrylist的区别
    垃圾收集器与内存分配策略
    java类加载机制
  • 原文地址:https://www.cnblogs.com/JohnChen-happy/p/4432878.html
Copyright © 2011-2022 走看看