✅ Common Keys in Database Tables
I'm writing my database logic for creating my relative database. I'm trying to find a good way to link these three tables together through a common variable. For example: The principle receives a new student and they get enrolled. The students information will go into the students table, the students parents information will go in the parents table, and the student will get assigned to a teacher, or number of teachers, and the teachers information already exists for when they were added to the gradebook on hire. So if a teacher needs to see parent/student information or the principle needs to see what teacher is assigned to the student, what's a good way to link these three tables together so that I can just do one database call and have access to the all the information from all 3 tables?
24 Replies
Seems like it's time to learn about the "relational" part of "relational database"
Instead of having
ParentEmail
and all those other Parent
properties in the Student
, the Student
should have a foreign key to Parent
That way, you can use a JOIN
to get student info and related parent infook sounds great. how do I do it?
Here's a tutorial I found: https://blog.devart.com/types-of-relationships-in-sql-server-database.html
damn beat me to googling it
i had the link in my clipboard
👉😎👉
yea lol I'm lost
I was gonna use StudentName as the item that was shared between all 3 tables. So like student will have 1 name. Parent will be two individual entries for two separate kids and then teacher will have a list of students that I'll just add each new student's names to so that when I pull information, I can query all three databases and whatever. idk how to explain it or do it lol
You can want whatever you want
Relational databases won't conform to your wants
There's no "list", there's no "shared"
There are only foreign keys
what happens when 2 or more students have the same name?
a teacher ideally would have multiple students ...how does student name work then in your staff table?
there will be a pop up window that shows the list of students with the same first and last name with some small detailed information like addresses and parents names that will display and the teacher selects the student that want
Here's some pseudo-SQL
no i mean in terms of your program's logic
how would it know how to correlate the entires if there are duplicate names and the names are what you're trying to use to link things together?
Yeah
If there's Bob John in grade II and Bob John in grade III
And parent, Marie John has a son, Bob John
Which one is it?
That's why you need IDs, primary keys that are unique
So that grade II Bob John has ID 69, grade III Bob John has ID 420, and Marie John has a sone with ID 420
We now know which one it is
And foreign keys let us enforce it, so that we cannot assign Marie John a kid with ID 1234, if such a kid does not exist
I was originally going to use the students ID as each tables id for each entry. That way when the student was selected, I could use that to get the information, but I realized that I couldn't have multiple entries of the same teacher for each student in the teachers table, so then I thought about writing in the parents information and the teachers information and storing their names in the students table with the student. I honestly don't know. I've never tried to make a gradebook before.
but tbh, it's a gradebook. It only needs to house enough information about the student to just save their names and grades
Tell you what, forget C# for a moment
Start by learning SQL
Because it seems that's where your problem lies
No, not even SQL, just the relational database model
And how to model data
Download MySQL Workbench or something, it lets you create a database graphically
Connect tables together with lines and all
And generate code from that
Harvard, as always comes in clutch: https://www.harvardonline.harvard.edu/course/cs50s-introduction-databases-sql
Harvard Online
CS50's Introduction to Databases with SQL
An introduction to databases using a language called SQL in an online course from Harvard.
They have a free course in relational database basics
that one looks like a paid one thou
might only cost money for the certificate
afaik cs50 is free
Yeah, the course is free
ah yeah after enrolling I can access it
You only need to pay if you want the certificate
it was a bit of a hassle getting there
ok thanks