minecraftplayer1234
minecraftplayer1234

Reputation: 2227

SQL Relationships in code

Okay. So I've got to do a database of a school, and I'm obligated to work with relationships to every table I create. So far I've got few tables and a few relationships, like this: I've got Classrooms table including ID and ClassroomNumber (like 101, 203 etc.). In another Subjects table I've got SubjectName and ClassroomID and a Relationship like this:

enter image description here

In code (C#) I Select values from Classrooms table, but I have to use join/where, so I add where s.ClassroomID = c.ID (s and c defined before). Okay, it works. But my question is different. Why am I obligated to use Relationships? What are they for? Join and where are working without relationships, so why?

Upvotes: 0

Views: 255

Answers (2)

user853710
user853710

Reputation: 1767

It's for ensuring data integrity. Making sure that less shit data gets into the DB. Also to have a structure DB that also other people can easy understand.

Don't question it. You need them. You want them. In a DWH you don't, but in a Transactional DB you DO.

Upvotes: 3

Nate Anderson
Nate Anderson

Reputation: 690

Foreign keys are indexes based on the relationship between the tables/columns . This becomes very important the larger your table gets. If you attempted to join two tables with millions of records and had no indexes in place the query would take significantly longer to complete.

Upvotes: 1

Related Questions