zoukankan      html  css  js  c++  java
  • MySQL多对多操作

    MySQL多对多

    返回首页

    示例1:

      用户表和相亲记录表
      用户表

        用户id    用户名                  性别

        1        George      男
        2        Elizabeth     女
        3        Bruce      男
        4        Catherine     女

      相亲表

        相亲组id              用户甲    用户乙

         1        1           2

         2         1           4

         3         2           1

         4         2           3


    示例2:

      用户主机关系表

      用户表userinfo

        用户id    用户名                  

        1        George       
        2        Elizabeth      
        3        Bruce         
        4        Catherine      


      主机表host

         主机id    主机名

        1       c1

        2        c2

        3          c3

      用户主机关系表user2host

        id      用户id    主机id

        1        1       1

        2        1      3

        3        2        1


    create table userinfo(id int auto_increment primary key,

              name char(10),

              gender char(10),

              email varchar(64)

              )engine=innodb default charset=utf8;

    create table host(id int auto_increment primary key,

             hostname char(64)

            )engine=innodb default charset=utf8;

    create table user2host(id int auto_increment primary key,

                userid int not null,

                hostid int not null,

                unique uq_user_host (userid,hostid),

                constraint fk_u2h_user foreignkey (userid) references userinfo(id),

                constraint fk_u2h_host foreign key (hostid) references host(id)

                )engine=innodb default charset=utf8;

      

    -------- END --------

  • 相关阅读:
    git各种操作:基本操作 and 多人协作 and 冲突解决
    mini-ndn0.5.0 安装教程 (避免踩坑)
    ubuntu18.04 更换镜像源
    自定义日志轮转
    linux常用命令
    Thinkphp6 + uniapp框架,接口访问跨域问题
    机器学习-主成分分析PCA与奇异值分解SVD
    机器学习-数据预处理&特征工程
    机器学习-梯度提升树(xgboost)
    github打不开怎么办
  • 原文地址:https://www.cnblogs.com/george92/p/7308514.html
Copyright © 2011-2022 走看看