Preferred database design method for assigning user roles? (Hats vs. Groups)

后端 未结 9 1273
后悔当初
后悔当初 2021-02-01 10:47

I have medium sized MySQL database with a primary \"persons\" table which contains basic contact information about every human being connected to the theatre and theatre school

9条回答
  •  梦毁少年i
    2021-02-01 11:32

    The groups and hats models you describe are convertible, one to the other. There's no real worry about data loss. Specifically, the "master groups" table can be produced by outer joins of the "hat person" table with the various "hat detail" tables.

    If you're using a "hat" model you need to make sure that a given "hat table" accurately encapsulates the unique characteristics of that hat. There's a lot less forgiveness there than with the groups model.

    You'll probably want to set up a few views for common tasks if you go this way - for example, if somebody's typing into a field for "teacher name" and you want to pop up some autocompletes, having a view which is basically

    SELECT firstName, lastName 
    FROM persons 
    INNER JOIN teachers ON persons.id = teachers.person_id 
    

    will help enormously.

    On a tangential note, one thing I've found to be useful is to call foreign keys by the same name as the primary key in their original table. That way you can just

    INNER JOIN original_table USING (primary_key) 
    

    in your FROM instead of monkeying with WHERE or ON equivalencies.

提交回复
热议问题