mysql directly create as select

create as select :

create table grade_1 as
select *
from grade;

Table structure comparison: auto_increment has changed to default '0', so when creating a table in a simple and crude way such as create as select, you must compare the structure of the table before and after . Avoid the following situations:

1. The primary key is lost

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

Guess you like

Origin blog.csdn.net/qq_41081716/article/details/130181150