blogspot visit counter

Wednesday, 18 September 2013

Timestamp in mysql

Timestamp in mysql
TimeStamp : -
The TIMESTAMP data type is the only way to have MySQL automatically set the time when a row was inserted and/or updated. DATETIME columns can’t do this.
TIMESTAMP columns are identical to DATETIME columns with one important exception — they can be set to take the current time value when a row is created or updated.


Note  -  If you want to use a timestamp  column then  set Defalut as shown



create table using timestamp as shown below

CREATE TABLE IF NOT EXISTS `user_tab` (
  `x` varchar(200) NOT NULL,
  `y` varchar(200) NOT NULL,
  `id` varchar(200) NOT NULL,
  `usertime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)

GUI  structure as  shown below





Note - if you set defaut  as a timestamp then don not use the time stamp column name at the time of insertion  it automaticlay insert the time in timestamp column

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...