dongxixian7803 2014-04-16 20:26
浏览 21
已采纳

传承自动增量

I want to create 3 tables: boss and employe inheriting the table person.

person: id, login, password;
boss: id, login, mdp, firstname, lastname, email;
employe: id, login, mdp, firstname, lastname, email;

I separate those two types of persons for control the rights.

But I want to keep a table that contains all users to manage a connection.

The problem is the auto indentation in the three Ids. When I create a member of type "boss", the ids in the tables boss and "person" are auto identated at 1. And when I create a new member of type employe, The ids (1 in "employe" and 2 in "personn" beacause the first is the boss) are not the same.

How I can modelize it?

Thanks and sorry for my English, Florian.

  • 写回答

1条回答 默认 最新

  • dqls67891 2014-04-16 20:53
    关注

    You have a lot of duplicate data being stored. Consider this alternative:

    person
    ------
    id
    login
    password
    firstname
    lastname
    email
    
    boss
    ----
    id
    person_id
    
    employee
    --------
    id
    person_id
    

    I can store the exact same information using this structure as you can in yours, but each 'person' will only have a single firstname/lastname, email address, login and password. You should only store in the boss / employee tables information that is relevant to only that entity. A boss for instance might have a security_code field whereas a regular employee wouldn't.

    You shouldn't try to keep id primary keys between two different tables to match up (i.e., boss id doesn't need to match person id). Instead, add the person_id foreign key so that if you have a boss record you can easily lookup their information in the person table from that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度