Create Table

  • Comments posted to this topic are about the item Create Table

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • This was removed by the editor as SPAM

  • Good Information..

    --
    Dineshbabu
    Desire to learn new things..

  • Kapil, very good question. 🙂

    Thanks
    Vinay Kumar
    -----------------------------------------------------------------
    Keep Learning - Keep Growing !!!

  • Easy one to close off the week, thanks!

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Koen Verbeeck (4/26/2013)


    Easy one to close off the week, thanks!

    +1 - thanks for the question

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • I first focused on the reference to a unique constraint rather than the primary key, thinking that was the issue of the question. I almost got it wrong because of that, as I had first not given enough attention to the other details of the code.

    I guess that many people will get this question right for the wrong reasons. (Many people think that a foreign key should always reference the primary key).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Hugo Kornelis (4/26/2013)


    I first focused on the reference to a unique constraint rather than the primary key, thinking that was the issue of the question. I almost got it wrong because of that, as I had first not given enough attention to the other details of the code.

    I guess that many people will get this question right for the wrong reasons. (Many people think that a foreign key should always reference the primary key).

    Same happened with me, but suddenly i see the data type size and i got it. Actually i read this one few time ago, that's help me. 🙂

    Thanks
    Vinay Kumar
    -----------------------------------------------------------------
    Keep Learning - Keep Growing !!!

  • Can someone please point me towards the place where the documentation explains that a foreign key column must have the same length as the column that it references? I can't see it in the link to MSDN provided in the answer.

    The Create Table documentation here: does say that that both columns must both be of the same data type, but it doesn't mention length.

  • This is what I get for trusting that voice in my head that says, "No, that's way too obvious." :crazy:

    ron

    -----
    a haiku...

    NULL is not zero
    NULL is not an empty string
    NULL is the unknown

  • Thanks for good question.

    I just looked at the syntax, column name and column data type and then length of column.

  • Mick Gillatt (4/26/2013)


    Can someone please point me towards the place where the documentation explains that a foreign key column must have the same length as the column that it references? I can't see it in the link to MSDN provided in the answer.

    The Create Table documentation here: does say that that both columns must both be of the same data type, but it doesn't mention length.

    Sorry for that but I also didn't find that information that foreign key must have same length as referencing columns so in answer I placed the link of constraint.

    I found this situation when I working on a script so think of put it as a QOTD!!

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Thanks for the question..Kapil

  • Hugo Kornelis (4/26/2013)


    I first focused on the reference to a unique constraint rather than the primary key, thinking that was the issue of the question. I almost got it wrong because of that, as I had first not given enough attention to the other details of the code.

    I guess that many people will get this question right for the wrong reasons. (Many people think that a foreign key should always reference the primary key).

    nah, that one I had... I've had to do enough FK's to Unique constraints in my life to remember that lesson...

    I'm just glad that I re-read it... and noticed the different column sizes.



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • I was initially leaning toward the right answer for the right reason, then talked myself out of it, thinking that SQL Server would be able to handle it. :hehe:

    Of course, I also don't see why it can't implicitly handle the GROUP BY statement.


    Puto me cogitare, ergo puto me esse.
    I think that I think, therefore I think that I am.

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

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