zoukankan      html  css  js  c++  java
  • mysql 外键 级联

    主表

    -- 创建用户信息表
    create table userinfo ( 
    	userid int primary key not null auto_increment COMMENT '主键',
        username varchar (20) not null unique comment '用户名',
        userpwd varchar (20) not null comment '用户密码' ,
        sex boolean not null default true comment '性别' ,
        idiograph varchar (50) comment '个性签名' ,
        address varchar(100) comment '地址' ,
        job varchar(10) comment '职位' ,
        studenttime int not null default 0 comment '学习时长单位分' ,
    	integral int not null default 0 comment '积分' ,
        solicitude int not null default 0 comment '关注量' ,
        follower int not null default 0 comment '粉丝量' ,
        headportrait varchar(100) comment '头像' ,
        email varchar(20) comment '邮箱'
    );  
    

      外键连接主表

    -- 粉丝表
    create table follower(
    	solicitudeid int not null comment '用户id',
        followerid int not null comment '关注的用户id',
        -- 设置外键foreign key(solicitudeid,主键references userinfo(userid),当触发某种事件on delete,执行的操作CASCADE,这里是当删除主表的时候就清除这里的相关数据
    	foreign key(solicitudeid) references userinfo(userid) on delete CASCADE, 
        foreign key(followerid) references userinfo(userid) on delete CASCADE
    );

      粉丝表有个外键去连接用户信息表

    当用户信息表中的某个数据被删除时会触发粉丝表的on delete的cascade,会清除掉相关的数据

  • 相关阅读:
    css实现自适应正方形
    遇到稍微复杂的场景发现css功力不足
    聊聊缓存
    git学习笔记
    font-size:0的作用
    移动端高清屏适配方案
    react生命周期
    javascript写定时器
    js判断字符串是否以某个字符串开头和js分解字符串
    json.parse()和json.stringify()
  • 原文地址:https://www.cnblogs.com/xiaohuihui96/p/6102026.html
Copyright © 2011-2022 走看看