FK selection (an nvarchar(30) column or four int columns)

  • To make a long story short, I have to add a new table with an FK to an existing table. The existing table has a PK made up of 4 int columns (the largest value in any one of these is 4 digits), there is also an nvarchar(30) column in this table that is always unique. What would be the best thing to do, query performance wise, as far as a FK in my new table, using the 4 int columns or the nvarchar(30) as an FK?

  • It will probably not make much difference regarding performance.

    I expect the four int columns to be slightly faster.

  • Eric.Johns (6/24/2010)


    What would be the best thing to do, query performance wise, as far as a FK in my new table, using the 4 int columns or the nvarchar(30) as an FK?

    i would go with stefan but still for concrete results, test it with large volume data.

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Of course the best answer you'll get is "It Depends..." but anyway, How is the table indexed? If the default indexing (clustered on all four ints) is used, I'd expect using them as your fk would be your best bet. The reality is it's going to depend on the specifics of your data, and what your query patterns look like.



    Dan Guzman - Not the MVP (7/22/2010)
    All questions have to be prefaced by Server version and 'according to MS Docs' or 'my own personal opinion based on how much detail I felt like digging into at the time.'

  • Yes the default clustered index is on all 4 ints. I suspect this will be faster as stated. Thanks for the replies.

Viewing 5 posts - 1 through 4 (of 4 total)

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