I'm designing a database for students. Computer science students here in Switzerland can decide between different specializations, e.g. application development, system engineering etc.
There are students from other professions in this application as well, which have no such specialization. A few examples:
+--------------------+-------------------------+
| Profession | Specialization |
+--------------------+-------------------------+
| Computer scientist | |
| | Application development |
| | System engineering |
| | Support |
| | |
| Electrician | |
| | none |
| | |
| Janitor | |
| | none |
| | |
| Architect | |
| | Small buildings |
| | High buildings |
| | |
+--------------------+-------------------------+
I hope you get the idea. My question now is, how do I design the database tables with these attributes, since they're dependent of each other? Every user has a profession, some do not have a specialization depending on their profession. So an electrician should not be an application developer, nor should an architect.
My thoughts so far 1
+-----------------------------+
| User |
+-----------------------------+
| #id |
| profession_id |
| specialisazion_id, nullable |
+-----------------------------+
Enforce logic through constraint checks
Approach 2
+-------------------+ +----------------+ +------------+
| User | | Specialization | | Profession |
+-------------------+ +----------------+ +------------+
| #id | +--| #id | +--| #id |
| username | | | name | | | name |
| specialization_id |--+ | profession_id |--+ +------------+
+-------------------+ +----------------+
Manage the logic myself and ensure, that every profession with no specialization has a specialization entry.
Approach 3
+----------------+ +-----------------------------+ +------------+
| Specialization | | spec_prof | | Profession |
+----------------+ +-----------------------------+ +------------+
| #id |--+ | #id | +--| #id |
| name | +--| specialization_id, nullable | | | name |
+----------------+ | profession_id |--+ +------------+
+-----------------------------+
|
|
+--------------+ |
| User | |
+--------------+ |
| #id | |
| username | |
| spec_prof_id |--+
+--------------+
Somehow all different approaches feel clumsy, dirty. What are the arguments for and against the different approaches? Is there a better way?
And how do I even search for this problem? Is dependent the correct naming?
Any help is greatly appreciated.