I have a MySQL table where I need to store the TIMESTAMP from when the row was created (registration TIMESTAMP). How do I create a field that is only TIMESTAMPed when it is created, and never when the row is updated?
            Asked
            
        
        
            Active
            
        
            Viewed 520 times
        
    0
            
            
        - 
                    possible duplicate of [mysql timestamp only on create](http://stackoverflow.com/questions/817396/mysql-timestamp-only-on-create) – Pekka Jan 09 '11 at 17:55
3 Answers
1
            
            
        when you create the table you put the default value of the column to be current_timestamp(). Somewhere along these lines.
create table `x` (
  id integer auto_increment not null, 
  timestamp TIMESTAMP default current_timestamp
  data CHAR(100)
);
and you don't set the field on insert/updates.
 
    
    
        Mihai Toader
        
- 12,041
- 1
- 29
- 33
0
            
            
        Whenever you create a new row simply add the TIMESTAMP to it. ALternatively you make it the default
CREATE TABLE your_table(name VARCHAR32, your_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
 
    
    
        DrColossos
        
- 12,656
- 3
- 46
- 67
0
            
            
        On the MySQL INSERT statement, I passed a value of NOW() which records the current time.
 
    
    
        user547794
        
- 14,263
- 36
- 103
- 152