Foreign key

  • Comments posted to this topic are about the item Foreign key

    Igor Micev,My blog: www.igormicev.com

  • Good question. Thanks for submitting.

    http://brittcluff.blogspot.com/

  • Well my answer was declared to be incorrect, so went to read the explanation, following the link given ..... nada / nothing / not a word to support what is deemed the correct answer.

    So went and entered the code in SQL 2008R2, triple checked what I had entered and it matched what was given in the question. When pressing the F5 key for SSMS (2008R2) .. and again using SSMS checked after the error message and what do you know ... what was shown did NOT match what was give as the correct answer.

    Hmmmmmmmmmmm

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Good Question.

  • Good One.

    If Table2 declared as following than all 3 tables created without any issue.

    create table Table2

    ( id_tb2 int primary key references table1(id_tb1),

    value2 varchar(100))

    Thanks

  • I wasn't paying enough attention to detail here.

    Table2's int column was just an int and nothing else. :hehe:

    Time to go to bed for me.

    Thank you for the question.

    I still see documentation around that never mentions unique constraints only PKs that can be used in a FK reference, even though we know that both can be used.

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

  • Nice and trick question,thank you.

    “When I hear somebody sigh, ‘Life is hard,’ I am always tempted to ask, ‘Compared to what?’” - Sydney Harris

  • Yeah, tricky question that bled me to death 🙂 I knew that creation of the third table would have some issues but I still voted for three being created and dropping some warning. Obviously, creating the table and the constraint at the same time does not equal to creating the table and adding the constraint after. Though the error message is slightly misleading here. It warns about being unable to create constraint but does not mention anything for the table itself. The devil is in the details.

    Good question 😉

  • i actually tried this on my database..

    My second table was not created..

    still it is showing incorrect answer 🙁

  • Good one.

    Raunak J

  • bitbucket-25253 (5/17/2012)When pressing the F5 key for SSMS (2008R2) .. and again using SSMS checked after the error message and what do you know ... what was shown did NOT match what was give as the correct answer.

    That's odd. I've just run this using SSMS 2012 against both a 2008R2 and a 2012 SQL server and it *did* match the answer given on both platforms. Could the SSMS version make a difference here? Don't have SSMS 2008 available to test!

    (Note that I'm talking Express editions in all cases here, just in case edition might make a difference as well).

    [EDIT] OK, this was bugging me, so I found a machine running SQL 2005 Standard Edition and ran the test again. Exactly the same result. :ermm: I'm baffled as to why you're getting something different.

  • Nice Question. Thought there was a catch to the question and had to think carefully.

    Have just run the test on a 2012 instance and got the same result - 2 tables created and the error that the third table needs to reference a unique or primary key contraint.

  • Good question!

    This one takes us back to the basics, and requires the reader to read and think carefully - and after you think through it, you realize that there is really nothing much to it.

    I enjoyed working my way through the question. Thank-you!

    Thanks & Regards,
    Nakul Vachhrajani.
    http://nakulvachhrajani.com

    Follow me on
    Twitter: @sqltwins

  • deepty21 (5/18/2012)


    i actually tried this on my database..

    My second table was not created..

    still it is showing incorrect answer 🙁

    You may have missed something...

    Thanks

  • Nice question, thanks.

Viewing 15 posts - 1 through 15 (of 38 total)

You must be logged in to reply to this topic. Login to reply