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 --------

  • 相关阅读:
    关于debug和release 以及new 和delete
    关于new 和delete
    构造函数为什么不能是虚函数
    大端小端【转载】
    “error LNK1169: 找到一个或多个多重定义的符号”的解决方法(转载)
    memset memcpy函数
    漫谈递归
    scanf 和cin 的区别
    enum枚举类型 的用法
    关于浮点数和字面值常量 的使用—— 学习汇编的重要性
  • 原文地址:https://www.cnblogs.com/george92/p/7308514.html
Copyright © 2011-2022 走看看