I am working on a project where there are several types of users (students and teachers). Currently to store the user's information, two tables are used. The users
table stores the information that all users have in common. The teachers
table stores information that only teachers have with a foreign key relating it to the users
table.
users
table
teachers
table
In the rest of the database, there are no references to teachers.id
. All other tables who need to relate to a user use users.id
. Since a user will only have one corresponding entry in the teachers table, should I just move the fields from the teachers table into the users table and leave them blank for users who aren't teachers?
e.g.
users
Is this too many fields for one table? Will this impede performance?
A table has records (rows) and fields (columns). Fields have different types of data, such as text, numbers, dates, and hyperlinks. A record: Contains specific data, like information about a particular employee or a product.
Storing all data in one single table will be confusing, may have security issues and there will be duplication in recording. Multiple table helps in recording the data in more organized manner when there are multiple users. The data can be stored as per the category and there will be less chances of duplication.
On the Home tab, in the Views group, click View, and then click Datasheet View. On the Fields tab, in the Add & Delete group, click More Fields. Select a field in the More Fields list to insert the new column. Access places the field to the right of the column where your cursor is currently located.
You can also use the SQL CREATE TABLE AS statement to create a table from an existing table by copying the existing table's columns. It is important to note that when creating a table in this way, the new table will be populated with the records from the existing table (based on the SELECT Statement).
I think this design is fine, assuming that most of the time you only need the user
data, and that you know when you need to show the teacher
-specific fields.
In addition, you get only teachers just by doing a JOIN
, which might come in handy.
Tomorrow you might have another kind of user who is not a teacher, and you'll be glad of the separation.
Edited to add: yes, this is an inheritance pattern, but since he didn't say what language he was using I didn't want to muddy the waters...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With