can i put the exact time of the data in my sql table?

In MySQL, you can store the timestamp when a record was craeted with an auto-initialized column.

create table mytable (
    id           int primary key auto_increment,
    username     varchar(50),
    password     varchar(50),
    created_ts   timestamp default current_timestamp
);

Then you insert intoi the table like so:

insert into mytable(username, password) values('foo', 'bar');

And created_ts is automatically initialized with the current date/time as of insertion time.

You can also track the point in time when a row was last changed with the on update clause:

create table mytable (
    id           int primary key auto_increment,
    username     varchar(50),
    password     varchar(50),
    created_ts   timestamp default current_timestamp,
    updated_ts   timestamp default current_timestamp on update current_timestamp
);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top