温欣爸比

  • 主页
  • Alfred Workflow
  • 《Vim 练级手册》
  • 常用命令
  • 代码笔记
  • 合辑
  • 在线工具
所有文章 友链 关于我

温欣爸比

  • 主页
  • Alfred Workflow
  • 《Vim 练级手册》
  • 常用命令
  • 代码笔记
  • 合辑
  • 在线工具

2017-08-10 新建collection_resource表,新建trigger更新collection资源总数

2017-08-10

今天练习的目标,新建collection_resource表,并新建trigger更新collection的资源数

专辑:mysql每天练习

新建collection_resource

1
2
3
4
5
6
7
8
drop table if exists `collection_resource`;
CREATE TABLE `collection_resource` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`collection_id` int(11) NOT NULL,
`resource_id` int(11) NOT NULL,
`resource_type` varchar(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='合集资源对应表';

collection表添加资源数量字段

1
alter table collection add column resource_count int(11) not null default 0 comment '资源总数';

新建trigger

1
2
3
4
5
6
7
8
9
10
11
drop trigger if exists `insert_collection_resource`;
delimiter $
create trigger `insert_collection_resource` after insert on collection_resource for each row
begin
declare count int;
select count(0) into count from collection where id = new.collection_id;
if (count > 0) then
update collection set resource_count = resource_count + 1 where id = new.collection_id;
end if;
end $
delimiter ;

运行

1
2
3
insert into collection(name) values ('合集');
insert into collection_resource (collection_id,resource_id,resource_type) values(1,1,'video');
select * from collection;
最近更新
Alfred Workflow 命令行帮助工具
最近热读
Go 判断数组中是否包含某个 item
Vim 高级功能 vimgrep 全局搜索文件
办理北京工作居住证的一些细节
Go 语法错误:Non-declaration statement outside function body
Mac 电脑查看字体文件位置
扫码关注公众号,或搜索公众号“温欣爸比” 及时获取我的最新文章
赏

谢谢你请我喝咖啡

支付宝
微信
  • mysql
mac清除DNS缓存
Linux 环境下安装 pyenv 和 virtualenv
  1. 1. 新建collection_resource
  2. 2. collection表添加资源数量字段
  3. 3. 新建trigger
  4. 4. 运行
© 2017 - 2022 温欣爸比 京ICP备15062634号 总访问量次 访客数人次 本文总阅读量次
Hexo Theme Yilia by Litten
  • 所有文章
  • 友链
  • 关于我

tag:

  • python
  • flask
  • javascript
  • docker
  • 工具
  • openresty
  • 微信
  • java
  • hexo
  • 杂谈
  • vim
  • git
  • mysql
  • http
  • linux
  • mac
  • tmux
  • ssh
  • 算法
  • 开发
  • node
  • 杂文
  • jinja2
  • maven
  • spring
  • 北京
  • 生活
  • springboot
  • react
  • shell
  • graphql
  • iterm
  • expect
  • nginx
  • sqlalchemy
  • html
  • electron
  • vagrant
  • elastic
  • 宝贝
  • ansible
  • css
  • jquery
  • go
  • markdown
  • awk
  • redis
  • leetcode
  • zsh
  • 漫威
  • ssr
  • android
  • ffmpeg
  • chrome
  • vmware
  • youtube
  • windows
  • jupyter
  • excel
  • jq
  • Mac
  • Homebrew
  • mongo
  • py2
  • HomeBrew
  • movie
  • nodejs

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • Guru99
每天看书
每天背单词
每天一篇
写写代码
听听周杰伦
爱爱老婆