Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog.

how to create a table with a datetime stamp in sql (mysql)

This one is easy and often comes in handy for logs in your web application. If you are using phpMyAdmin just create your table as your normally would and set the field that you would like to be a datetime stamp as a type of ‘timestamp’ and you’re done. Otherwise if you are doing this in the mysql shell use the following SQL statement as an example:

1
2
3
4
5
CREATE TABLE 'test' (
'id' TINYINT NOT NULL ,
'time' TIMESTAMP NOT NULL ,
PRIMARY KEY ( `'id' )
) TYPE = MYISAM ;

Remeber when using a timestamp it will update the timestamp everytime the record is modified.

Leave a Reply