Tables whose sole purpose is specify a subset of another table

后端 未结 3 838
遇见更好的自我
遇见更好的自我 2020-12-12 05:50

The database I\'m designing has an employees table; there can be multiple types of employees, one of which are medical employees. The database needs to also des

3条回答
  •  不知归路
    2020-12-12 06:28

    Why a separate table for that. Why not just create a BIT/Boolean field say IsMedical and set that to TRUE for medical employees in employee table like

    /* Defines a generic employee */
    CREATE TABLE employees (
        id      INT PRIMARY KEY AUTO_INCREMENT,
        name    VARCHAR(100) NOT NULL,
        IsMedical BIT(1)
    );
    

    That way, say if you want to get all medical employees from Employee table; you will just have to do a single filter in WHERE condition saying WHERE IsMedical = true. Whereas, if you go by a separate table then you will have perform a INNER JOIN with medical_employees and employees table which I believe would be more costly and unnecessary.

提交回复
热议问题