zoukankan      html  css  js  c++  java
  • 关于MySQL中自增的理解和设置

    show create table t10;--查看表的创建结果
    show create table t10G;--竖列查看
    alter table t10 AUTO_INCREMENT =20 --设置自增为20
    alter table t2.name  char(30);
    insert into t2(name) values ('yaoming');
    ALTER TABLE t2 ALTER Column Name varchar(100) not null;
    主键:
        1.一个表只能有一个主键,主键可以由多列组成,主键不能为空.
        CREATE TABLE t5 (
                        nid int(11) NOT NULL AUTO_INCREMENT,
                        pid int(11) not NULL,
                        num int(11),
                        primary key(nid,pid)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
     外键:
         1.创建外键时可以在一个表达式中创建多个外键
              create table t5(
         id int auto_increment primary key,
         name char(10),
         nid int,
         pid int,
         )engine = innodb default charset=utf8;
         
         create table t6(
         id int auto_increment primary key,
         name char(10),
         id1 int,
         id2 int,
         constraint fk_t5_t6 foreign key (id1,id2)
         references t1(nid,pid)
         )engine = innodb default charset=utf8;
     数据行:
        插入多个数据是可以在values后面使用,分割写
        insert into tb1(name,age) values ('xiaoli',18),('xiaoming',12)
    自增:
        show create table t2G 可以查看创建表时的结构
        alter create table  t2 auto_increment = 20; --可以改变自增的起始数字
        MySQL:自增步长:
        --基于会话级别的:
            show session variables like 'auto_inc%';--查看全局变量的步长和起始值
            set session auto_increment_increment=2;
            --设置步长
            set session auto_increment_offset=10;
            --设置起始数字
         --基于全局级别的:
            show global variables like 'auto_inc%';
            --查看全局变量
            set global auto_increment_increment=2;
            --设置全局步长
            set global auto_increment_offset=10;
            --设置全局起始数字
          SqlServer: 自增步长基于表可以实现
            create table t2(
            sid int primary key identity(3,5),--从3开始 ,步长为5
            sname nchar(8) not null,
            ssex nchar(1)
            )
  • 相关阅读:
    std thread
    windows更新包发布地址
    How to set up logging level for Spark application in IntelliJ IDEA?
    spark 错误 How to set heap size in spark within the Eclipse environment?
    hadoop 常用命令
    windows 安装hadoop 3.2.1
    windows JAVA_HOME 路径有空格,执行软连接
    day01MyBatisPlus条件构造器(04)
    day01MyBatisPlus的CRUD 接口(03)
    day01MyBatisPlus入门(02)
  • 原文地址:https://www.cnblogs.com/tataerzu/p/10165614.html
Copyright © 2011-2022 走看看