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

  • 相关阅读:
    KindEditor编辑器的使用
    导航栏
    ajax php 验证注册用户名是否存在
    PS照片改底色
    截取邮箱@后面内容的两种情况
    js导航栏单击事件背景颜色变换
    model中的自动验证 $_validate $_auto
    一对一关联模型,HAS_ONE
    一对多关联模型,BELONGS_TO
    C++操作MySQL数据库
  • 原文地址:https://www.cnblogs.com/george92/p/7308514.html
Copyright © 2011-2022 走看看