Is a multi column primary key the best way to do this

  • Hello all,

    We have a project in which we have to keep track of change history. The Sql Server data is actually serving a .Net MDI application. The primary key for the Project table is a Guid. We also have a Version# column which is an Int.

    Can I combine these into a multi column primary key where the Int column is descending so that my data is automatically sorted with the most recent change first? If I do something like this, will I be forced to use Topx most of the time? Is there a better way to do this? Thanks for any ideas and/or suggestions.

  • Leave your GUID column as the unique primary key, but create it non-clustered.  Then, create a descending clustered index on your int column. 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • +1 for John's suggestion.

    Note that the clustered index isn't a guarantee that the data will be sorted, so you should still use an 'order by'. It should be much quicker though.

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

Viewing 3 posts - 1 through 2 (of 2 total)

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