Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top