Results 1 to 5 of 5
  1. #1
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142

    Date As Primary Key

    I have a table with a [TimeCreated] field, datatype date/time, contains date AND TIME the record is created. This field is indexed (no duplicates). Any reason I shouldn't just use this field as the PK?

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    If you could insert multiple records using an Insert query , then you may get errors, as the datetime field may end up being the same.
    Not sure as I've never used it as a PK in Access.

    SQL Server timestamps are not actually a date time field, so that may be confusing you.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    No, in just using Access. Conflicting times shouldn't be a problem as there won't be any batch inserts. Field is already unique.

  4. #4
    turbofish is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    25
    As Minty pointed out, there is a risk of errors during inserting rows but there is also another issue. Date/time columns take up more space than an int or long integer which would slow up searches using the column as a primary key when you need to join it to another table and take up more space.
    The only time that I've found where a primary key on a date column/field makes sense was in a time dimension which is beyond the scope of this question.

  5. #5
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Ah, I had it in my head that long and date/time (double) both used 8 bytes, but it looks like long only uses 4 bytes. Thanks for the heads up.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 11-20-2018, 11:57 PM
  2. Replies: 7
    Last Post: 01-18-2018, 02:17 AM
  3. Replies: 7
    Last Post: 04-27-2016, 09:28 AM
  4. Replies: 4
    Last Post: 04-06-2016, 07:17 AM
  5. Replies: 3
    Last Post: 08-21-2012, 03:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums