mysql直接create as select

  • Post author:
  • Post category:mysql


create as select :

create table grade_1 as
select *
from grade;

表结构比较:auto_increment变成了default ‘0’,所以用create as select 这种简单粗暴方式建表的时候

一定要比较前后表结构

。避免出现以下情况:

1、主键丢失

2、auto_increment –>default ‘0’

create table `grade_1`
(
    `gradeid`   int                               not null default '0' comment '年级id',
    `gradename` varchar(50) character set utf8mb3 not null comment '年级名称'
) engine = innodb
  default charset = utf8mb4
  collate = utf8mb4_0900_ai_ci;

create table `grade`
(
    `gradeid`   int(10)     not null auto_increment comment '年级id',
    `gradename` varchar(50) not null comment '年级名称',
    primary key (`gradeid`)
) engine = innodb
  default charset = utf8



版权声明:本文为qq_41081716原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。