Datetime as Primary Key or Unique constraint?

Last post 10-07-2008 12:39 AM by FrankKalis. 1 replies.
Page 1 of 1 (2 items)
Active Topics My Discussions Unanswered Sort Posts: Previous Next
  • 10-06-2008 3:57 AM

    Datetime as Primary Key or Unique constraint?

    Hello,

     I have a table where I want to insert values for each day and each ID:

    Table: Availabilities

    HotelID (bigint)

    Day (datetime)

    Availability (smallint)

    to ensure that a hotel can only have one Availability Value for each day (e.g. 2008-06-10 00:00:00) I see two solutions:

    HotelID and Day as combined primary key or HotelID and Day as unique constrained. Note that a SP will ensure that only datetimes with time 00:00:00 can be inserted.

    How would you solve this?

    greetings

    Filed under: ,
  • 10-07-2008 12:39 AM In reply to

    Re: Datetime as Primary Key or Unique constraint?

    Wow, you must have really many hotels if you need to use a bigint as data type for HotelID!

    Without knowing the full specification here, I would tend to have a composite PRIMARY KEY here. A UNIQUE constraint would essentially achieve the same, with the exception that the constraint would accept NULL markers which wouldn't be what you want here, right?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Contributing Editor, Writer & Forum Moderator http://www.sql-server-performance.com
    Webmaster: http://www.insidesql.org
    View Frank Kalis's profile on LinkedIn

    XING
Page 1 of 1 (2 items)
Active Topics   My Discussions    Unanswered Posts


© 2000 - 2007 vDerivatives Limited All Rights Reserved.