Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2007
    Posts
    1

    Unanswered: Date primary key question!!

    I currently run a website that has different content each day. The content is saved in the database and the primary key is the date. I get the system date from the server and query for todays conent with that date variable. Currently the date field is a primary key and I chose to keep the field int(6) so the format is mmddyy. So I have one question:

    1)Should I change my date field to be of date type instead of int? The reason I chose int is because I thought it would make the database faster.


    I know some may say this won't make a difference, but this is for a class and I'm wanting the best choice for this date primary key type. I will be presentint this site to my teachers and don't want them to question why I chose int type instead of date if it doesn't make since.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    my money is on there being a high probability -- real soon -- of wanting to store more than one content per day

    i think date is the wrong primary key

    and yes, DATE is better than INTEGER for a date key
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    I would agree with Rudy on this. Date should almost NEVER be a primary key, purely because it is usually a supplimentary field and often occurs more than once. Use a nice auto incrementing id

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •