SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Foreign key


Foreign key

Author
Message
Igor Micev
Igor Micev
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 6952 Visits: 5129
Comments posted to this topic are about the item Foreign key

Igor Micev,
SQL Server developer at Seavus
My blog: www.igormicev.com
M&M
M&M
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4137 Visits: 3909
Answer sounds ambigous. Please clarify on the answer explanation.

M&M
Carlo Romagnano
Carlo Romagnano
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5826 Visits: 3340
Another tricky and bad worded question.
In the earlier versions of any DBMS, the foreign key was implemented thru triggers.
So the answer should be "YES, implemented by trigger."
Or change the question: a CONSTRAINT FOREIGN KEY could reference a table in another database?
Example:
ALTER TABLE XXX ADD CONSTRAINT FK_XXX_NNN FOREIGN KEY(a)
REFERENCES ANOTHERDB.dbo.NNN(a)
In this case the answer is NO.

I run on tuttopodismo
kaspencer
kaspencer
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2536 Visits: 843
Be careful!

The question did not mention SQL Server.
I believe that you can use a trigger in Oracle (wash your mouth out, Spencer!) to permit a foreign key to reference a remote or external database.

Only when we get to the explanation does SQL Server come into it.

(OK, before hundreds of respondents criticise me, I know what this website is called.)

Happy Easter!

Ken.

You never know: reading my book: "All about your computer" might just tell you something you never knew!
lulu.com/kaspencer
Hugo Kornelis
Hugo Kornelis
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13123 Visits: 12162
I flipped a coin and ended up lucky. Two answers can both be considered correct.

No, a foreign key constraint can not be created across databases. If you refer to the actual constraint of that name, as supported by SQL Server.
Yes, a foreign key constraint can be enforced across databases using triggers. If you refer to the actual meaning of the constraint in a logical model.

With just the "yes" and "no" answers and a slight rewording of the question to prevent the ambiguity, this would have been a great question. With this wording *and* the presence of both "no" and "yes, with a trigger" in the answers, the question tries to trick people into giving the wrong answer. I assume that this was not the intention of the author - but it does have that effect!


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Igor Micev
Igor Micev
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 6952 Visits: 5129
Hi All,
Yes, I agree with some members that the question is a bit ambiguous, but I put the third option to make the question “ambiguous” i.e. to make you think a bit more about. Just review the first note on the following link http://msdn.microsoft.com/en-us/library/ms175464.aspx.
I also put a sqlservercentral post to clarify the third option of this QotD: http://www.sqlservercentral.com/Forums/Topic157655-8-1.aspx#bm157658
Yes, the question is about SQL server by default, if it was for Oracle or another database, it would have been appointed.
The question is inspired by practice, and I didn’t have any intention to put ambiguity in answering it.


Thank You
IgorMi

Igor Micev,
SQL Server developer at Seavus
My blog: www.igormicev.com
Thomas Abraham
Thomas Abraham
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3089 Visits: 2255
Igor, thanks for the question. Made me think. Maybe it was easier for me, as I answered the question in my head, before being presented with the three possible answers.

For those of you for which it will be a holiday, Happy Easter.

Please don't go. The drones need you. They look up to you.
Connect to me on LinkedIn
Jack Corbett
  Jack Corbett
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23850 Visits: 14905
Hugo Kornelis (4/6/2012)
I flipped a coin and ended up lucky. Two answers can both be considered correct.

No, a foreign key constraint can not be created across databases. If you refer to the actual constraint of that name, as supported by SQL Server.
Yes, a foreign key constraint can be enforced across databases using triggers. If you refer to the actual meaning of the constraint in a logical model.

With just the "yes" and "no" answers and a slight rewording of the question to prevent the ambiguity, this would have been a great question. With this wording *and* the presence of both "no" and "yes, with a trigger" in the answers, the question tries to trick people into giving the wrong answer. I assume that this was not the intention of the author - but it does have that effect!


+1. I went with no because I don't consider enforcing referential integrity through a trigger a foreign key, but the question could have been worded better to make it less ambiguous.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Jaroslav Pfauser
Jaroslav Pfauser
Right there with Babe
Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)

Group: General Forum Members
Points: 716 Visits: 100
There are 3 options(Yes, No, Yes by using triggers) and you can check only one of them.
So if it will be Yes by using triggers than also Answer Yes is correct. So Third option can't be correct, because in that case the first option is also correct.

So it reduce options on No and "Yes but without using triggers" (Yes-Yes by using triggers).
And from those 2 options it was easy to choose the correct one.
sestell1
sestell1
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2768 Visits: 3469
Ugh, should have gone with my first impulse, but then I thought it was a trick since you can create a foreign key type of relationship across databases with triggers.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search