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.

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

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站