mysql数据库:

把表1的所有数据,插入到表2

字段取值规则

id 取id

stu_id 取id

c_name 取 uname

istester 和 grade字段,给默认值 60

 

insert into 表2 (id,stu_id,c_name,istester,grade) select id,id,uname,60,60 from 表1;

 

当主键冲突时报错:[Err] 1062 - Duplicate entry '1' for key 'PRIMARY'

 

主键冲突

方法一:删除表2的数据重新将表1的数据插入。

方法二:设置被插入表的id字段为自增,将其他值插入。

 

相关文章:

  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
猜你喜欢
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
  • 2021-04-29
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
相关资源
相似解决方案