复(学)习一下 SQL

MySQL 实例

Index 目录

  • like
  • MySQL 更新某一行
  • MySQL 已有字段更新(包括重命名 Rename field)
  • MySQL 添加字段 Add field
  • MySQL 利用已有数据创建新一行数据
  • MongoDB select * from table
  • MongoDB describe table(collection)
  • 复制行

like 用法

  1. SELECT endAt FROM `lives` WHERE endAt like '2717%'

MySQL 已有字段更新(包括重命名 Rename field)

  1. update settings set guard_amount = 333 where id = 1;

MySQL 已有字段更新(包括重命名 Rename field)

  1. alter table rates change column deleted isDeleted tinyint(1) default 0;

MySQL 添加字段 Add field

  1. alter table rates add isVisible tinyint(1) default 1;

MySQL 利用已有数据创建新一行数据

  1. insert into rates (liveId, userId, rateNum, text, visible, createdAt, deleted, audited) select liveId, userId, rateNum, text, visible, createdAt, deleted, audited from rates where id = 1;

MongoDB select * from table

  1. db.tableName.findOne();

MongoDB describe table(collection)

  1. var col_list = db.tableName.findOne();
  2. for (var col in col_list) { print (col); }
  3. for (var col in col_list) { print (col, typeof col_list[col]); }

复制行

unique 字段可以直接指定值,多行且不重复可以通过写脚本,console.log 到文本中再复制粘贴

  1. insert into lives (name, subtitle, liveId, type, startAt, endAt, price, originalPrice, intro, banner, anchorId, categoryId, course, assistant, messageVisible, isActive, isShowSection, exerciseIntro, extra, isHidden, isVipFree)
  2. select name, subtitle, 1111, type, startAt, endAt, price, originalPrice, intro, banner, anchorId, categoryId, course, assistant, messageVisible, isActive, isShowSection, exerciseIntro, extra, isHidden, isVipFree
  3. from lives
  4. where id = 1;
  1. s = (id) => {
  2. return `
  3. insert into lives (name, subtitle, liveId, type, startAt, endAt, price, originalPrice, intro, banner, anchorId, categoryId, course, assistant, messageVisible, isActive, isShowSection, exerciseIntro, extra, isHidden, isVipFree)
  4. select name, subtitle, ${id}, type, startAt, endAt, price, originalPrice, intro, banner, anchorId, categoryId, course, assistant, messageVisible, isActive, isShowSection, exerciseIntro, extra, isHidden, isVipFree
  5. from lives
  6. where id = 1;
  7. `;
  8. };
  9. for (let i = 100000; i < 100040; i++) {
  10. console.log(s(i));
  11. }