Saturday, January 23, 2010

mysql : insert timestamp automatically

If you want to generate timestamp automatically in your table,
save a field as timestamp, and default valur is CURRENT_TIMESTAMP.

CREATE TABLE `news` (
`nid` int(10) NOT NULL auto_increment,
`ntitle` varchar(255) NOT NULL default '',
`ctime` timestamp NOT NULL default CURRENT_TIMESTAMP,
`active` int(1) NOT NULL default '0',
`ndesc` text NOT NULL,
PRIMARY KEY (`nid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

2 comments:

  1. alter table product_slide add ctime timestamp NOT NULL default CURRENT_TIMESTAMP;

    ReplyDelete
  2. mysql> alter table suppliers change pdate pdate timestamp not null default CURRENT_TIMESTAMP;

    ReplyDelete