How to use SQL statements to express: create a new field so that every time a new record is inserted, the current time is automatically marked?

WBOY
Release: 2016-08-18 09:16:11
Original
1169 people have browsed it

I found this expression on the Internet and implemented the above function on mysql (version 5.7) provided by local wamp

<code>alter table account.users add column reg_time datetime not null default now();</code>
Copy after login
Copy after login

But I am using the same SQL statement on the server side

<code>alter table users add column reg_time datetime not null default now();</code>
Copy after login
Copy after login

But it prompts: Invalid default value for 'reg_time'
The server mysql version is 5.0
What should I do?

Reply content:

I found this expression on the Internet and implemented the above function on mysql (version 5.7) provided by local wamp

<code>alter table account.users add column reg_time datetime not null default now();</code>
Copy after login
Copy after login

But I am using the same SQL statement on the server side

<code>alter table users add column reg_time datetime not null default now();</code>
Copy after login
Copy after login

But it prompts: Invalid default value for 'reg_time'
The server mysql version is 5.0
What should I do?

<code>ALTER TABLE `users`
ADD COLUMN `reg_time`  timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP</code>
Copy after login

sqlserver uses getdate()
mysql which should correspond to now()

timestamp timestamp type field has two attributes: automatic update insertion time and modification time

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template