List:General Discussion« Previous MessageNext Message »
From:SGreen Date:June 9 2004 9:01pm
Subject:Re: A Table with a timestamp as transaction date and primary key...
View as plain text  
TIMESTAMP has a resolution of only 1 second. Not good enough as a primary
key for most applications. You may want an auto_incrementing int field (or
bigint depending on the size of your data) and make that your primary key.

Only the first TIMESTAMP column is automatically updated with the update
date. If you want to have a static date/time field you can use a datetime
field and populate it with the  NOW() function during insert. Unfortunately
all default values must be constants or you could set the default of the
column to be the NOW() function and not have to ever reference that column
in an INSERT statement.

The fine manual covers your situation fairly well. I suggest you start at :
http://dev.mysql.com/doc/mysql/en/DATETIME.html and follow the links to the
rest of the articles describing TIMESTAMPS and their uses and drawbacks.

Yours,
Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine




                                                                                          
                               
                      "Scott Fletcher"                                                    
                               
                      <SFletcher@abcoa.        To:       <mysql@stripped> 
                                        
                      com>                     cc:                                     
                                  
                                               Fax to:                                    
                               
                      06/09/2004 04:24         Subject:  A Table with a timestamp as
transaction date and primary key...  
                      PM                                                                  
                               
                                                                                          
                               
                                                                                          
                               




I read some articles that the use of SQL's TIMESTAMP in a table is use
for recording the actual date/time that the row was inserted and for
row(s) that is/are updated.  I'm a little troubled by that because I
want a table with a timestamp in the first column to be the transaction
date which can be done by insert and that the timestamp not be altered
with the SQL update of any sort.  I also want the TIMESTAMP to be a
primary key.   So, what is my options?  Thanks...





Thread
A Table with a timestamp as transaction date and primary key...Scott Fletcher9 Jun
  • Re: A Table with a timestamp as transaction date and primary key...gerald_clark9 Jun
Re: A Table with a timestamp as transaction date and primary key...SGreen9 Jun