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

  • 相关阅读:
    【实验吧】CTF_Web_登录一下好吗?
    各种常用数字格式化
    .Net 4.0 (2)
    springBoot+springSecurity 数据库动态管理用户、角色、权限
    springboot+mybatis+SpringSecurity 实现用户角色数据库管理
    Spring boot中Redis的使用
    spring data jpa的使用
    如何优雅的使用mybatis
    WebJars
    mvn打包的POm文件
  • 原文地址:https://www.cnblogs.com/george92/p/7308514.html
Copyright © 2011-2022 走看看