Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Foreign Key Constraints

Author  Topic 

shootdaj
Starting Member

3 Posts

Posted - 2009-12-08 : 00:03:25
This question is more about mathematical relations in general and not about SQL specifically, but it applies to SQL. My question is:

Let's say a foreign key(FK) exists in relation R1 and FK references the primary key of R2. I understand that the domain of FK and the domain of the primary key of R2 are supposed to be the same. Does this imply that if there is a row in R2 that is NOT referenced by FK in R1, it is a violation? Or can R2 have any number of PK's without it actually being referenced.

In other words, if a PK exists in a reference table, does it HAVE to be referenced by a FK, given that the FK in the another table refers to the PK of the reference table?

Thanks,
Anshul

X002548
Not Just a Number

15586 Posts

Posted - 2009-12-08 : 00:16:37
I read these...and my mind hurts

You talk about CONSTRAINTS


CONSTRAINTS...must be enforced...

So if the SET of data has the possibility to POSSIBLY CONSTRAIN the data, then Yes.

BUT, Unless you ENFORCE the CONSTRAINT

IT JUST DOESN'T MATTER

http://www.youtube.com/watch?v=g3S_k1dRbXY

Say it with me

IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER
IT JUST DOESN'T MATTER






Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

shootdaj
Starting Member

3 Posts

Posted - 2009-12-08 : 00:43:40
I mean in the technical definition of a foreign key, what are the constraints? I know that referential integrity constraint must hold for a foreign key in which the thing being referenced must exist. My question is does it also hold the other way around?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-08 : 00:56:33
A parent (PK) must exist in order for a child (FK) to exist, but a parent does not have to have a child.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

shootdaj
Starting Member

3 Posts

Posted - 2009-12-08 : 02:09:13
Thank you that's what I was looking for.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-08 : 11:06:14
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -