shared table for entities teachers and students? - database

I have to create a database and I want to know what would be the best solution.
Let's say I have to store information about students and teachers.
Should I make one single table containing all the personal information (name,email,phone password) to both students and teachers?
For additional information should I keep them in separate tables as ADD_TEACHERS and ADD_STUDENTS?

You may want to create a people table for the common data like name,email etc. You can then use a primary key column in this table, and if there has to be information specific to teacher (like course_instructor, head_teacher of class), then use that unique key from people as reference in your course_information table. Do the same for students too.

It sounds like your best route is to have a separate table for teachers and students. You'll have what is called a one-to-many relationship between teachers and students: one teacher, many students.
But that only covers one semester. When you consider other semesters, you have a many-to-many relationship between students and teachers.
In the end, you're best off with at least three tables: Teachers, Students, and teacher-to-student relationship.

First thing you have to do is Map the entity relationships (ER) and its attributes.then design the database and apply the normalization strategies.
In the proposed scenario students and teachers are different entities . and find out thier relationship
ONE student ONE TEACHER
MANY Students HAVE ONE TEACHER
MANY Students HAVE MANY TEACHERs
Then check out their attributes Example - Student(Name,Class,DOB)

It depends on how you are going to use the data. If you have a lot of use cases where you are interested in "persons", regardless of role, or if you have a lot of persons who are both teachers and students, you may want to learn the gen-spec design pattern, as it applies to relational tables.
See previous discussion.

Related

Relationships between 3 Entities in a ternary relationship

we are tasked with creating a database which has three entities team, user, course. A course will have multiple students and multiple teams in it. A student and professor can belong to many courses. However, a user with the type of student can only belong to one team in a specific course, but they can belong to other teams in different courses. We are currently trying to figure out how to display this relationship. We are also leaning towards teams being a weak entity which depends on course. So far we have two versions of how we believe the entities and relationships will look like. Would someone be able to tell if we are on the correct track, the weak entity is throwing us off. We also are a bit confused on the cardinality for the ternary relationship.
We only put primary keys in the diagram to simplify it.
A user has the following attributes: name, primary key(userID), userType(either admin, student,teacher), and email.
A course has the following attributes: course name, primary key(course id), start date, and end date.
A team is a weak entity with the following attributes: course id, team number. Primary key(course id, team number).
Thank you to anyone who may be able to help.
IMO, the course table should not have both team and user linked to it, only team should be linked to it, to specify what course is the team for. My ERD diagram would look something similar to this :
Team_member is an associative entity used to solve the many-to-many relationship between team and user, since each user can belong to many teams, and each team can have many members, so it should have a composite key made up of user_id and team_id, to record each member within a team, and team should have a foreign key of course_id to specify its course.

What is the best way to maintain shared fields between tables in database?

I want to create a database for school management system. The database has two tables contain shared fields like Students and Teachers.
For example, Student table has fields(id, name, phone, class), and Teacher table has fields(id, name, phone, department).
Is it better to make: a table called Person which has fields(id, name, phone), Student table has fields(id, person_id, class), and Teacher table has fields(id, person_id, department).
Which of the two ways is better?
Giving a direct answer to this question might be opinion based. There is no generally best strategy to design database.
Theoretical example: if there is a large amount of data you might want to think about performance: what and how you search and joins.
If you search mostly Students and Teachers you might not create Person table and you could search them easily. Then if you would like to search all Persons from db you would need to make two queries and a UNION between those and with fields that are common to both types of Person.
If you search also Persons more frequently then you might create Person table and implement Teacher and Student to have foreign key to Person. Then when searching two last mentioned you would need to make JOIN to Person.
In real life I do not know if in this use case there is really a big difference. More important is that you select some strategy and follow it in your future decisions in order to keep the desing clear.
However there might come situation where it is need to change the selected strategy still. So theoretically.
Related question here

Designing a good database

I have the following tree:
courses, that have many groups, each having multiple students.
So the drilled-down tree looks like this: courses -> groups -> students.
I think there are two ways to represent this:
1) students table that has group_id FK to groups; groups table that has course_id FK or:
2) first option plus students table having both group_id and course_id FKs so that I can have more freedom to fetch data without having to JOIN the "parent" table everytime.
One good example is to get all students that are part of a course (whatever the group). In this case, going with only the first option forces me to JOIN the groups table, which is not needed in that scope. So i tend to always choose the second option, even if the "main" table gets a few more columns of FKs.
How do you approach this?
The example gets more complicated if you add a couple more tables at the top of the courses table, like teachers (that teach courses) and schools (that has teachers). If you need to see all the students in a school, you need to join the groups, courses, teachers and schools.
Thank you!
LE: I am excluding many to many relationships from this example, those are treated differently.
LLE: And yes, if it sounds like convenience (aka performance)... it might be true :)
Personally, I try to keep a database as normalized as possible for clarity in the data model. So I would say if every student is going to be linked to the course through a group (no possibility of a student not in a group), than there should not be a relationship directly between students and courses. Don't sacrifice the clarity of your data model for having to write less SQL.
Also, you probably realize this, but you'll need linking tables for any many-to-many relationships. I'm not sure what kind of groups you're talking about, but if they can exist over multiple courses you'll need a Course --> CourseGroup (FK CourseID, FK GroupID) --> Group structure, and if students can belong to multiple groups you'll need Group --> GroupMembership (FK GroupID, FK StudentID)--> Student.
The addition of the course_id into the students table would be considered "denormalization" and is perfectly acceptable for exactly the reason you are trying to solve : "performance".
Denormalization Wiki
In computing, denormalization is the process of attempting to optimize the read performance of a database by adding redundant data or by grouping data
So yeah, your second option is doing just this ... attempting to improve performance by adding redundant data.

Can a relation has a relation with another relation

can we have some thing like following ER?
Is it a technical fault or not?
To define a relationship there should be entity by the help of them you can show relation. so it is impossible to make relation without entity.
In your case if you want to use 2 relationship there should be 1 entity between them.
Example of real life
suppose you have two relation teacher and student. you can not say like i am teacher and student of XYZ.
But you can say like i am teacher of Xyz and student of abc.
Typr of relationship
One-to-many relationships
The most common relationship used when creating relational databases. A row in a table in a database can be associated with one or (likely) more rows in another table. An example of a one-to-many relationship is a single order has many items on that order. And since relationships work both ways it is not uncommon to hear reference to many-to-one-relationships as well.
One-to-one relationship
A row in a table is associated to one and only one row in another table. An example of a one-to-one relationship is a person can have one social security number and a social security number can only be assigned to one person.
In most cases there is no need for a one-to-one relationship as the contents of the two tables can be combined into one table.
Many-to-many relationships
When one or more rows in a table are associated with one or more rows in another table. An example of a many-to-many relationship is a table of customers who can purchase many different products and a table of products that can be purchased by many different customers.

Clarification about storing courses in database

suppose if i need to take different college details and store courses offered by them into databases.Assume number of courses are different for different colleges.how table should be designed to store courses.
here these courses should be able retrieved for further processing
can any one suggest idea for this..
You can start with 2 tables, 1 for Institution (the university/college), and 1 for Course. The Course table should have a foreign key institution_id to the Institution table.
This way you can have as many courses as you want for any college, and looking up courses for a college is as simple as doing a query on institution_id.
Naturally, this is only a start, you will probably have to expand on this. For example, you might want to have another table like College that has a a foreign key to Institution, to model the fact that sometimes universities have many sub-schools within them. You could also have Institution rows reference other Institution rows to model the same thing; what you want to do depends on the details.

Resources