0%

MySQL高级语句

MySQL高级语句

  • 如果有主键或者唯一键冲突则不插入:insert ignore into
  • 如果有主键或者唯一键冲突则更新:insert into staff (id,name,age,sex) values (1,'李四',18,1) ON DUPLICATE KEY UPDATE name="11111"
  • 如果有就用新的替代,values如果不包含自增列,自增列的值会变化:REPLACE into staff (id,name,age,sex) values (1,'李四',18,1)
  • 备份表:CREATE TABLE user_info SELECT * FROM user_info
  • 复制表结构:CREATE TABLE user_v2 LIKE user
  • 从查询语句中导入:INSERT INTO user_v2 SELECT * FROM user或者INSERT INTO user_v2(id,num) SELECT id,num FROM user

欢迎关注我的其它发布渠道