Setting Default Values for Date Type Fields

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: date类型字段默认值设置

| username: 等一分钟

Is there a similar syntax in TiDB for the following MySQL 8 table creation statement?

CREATE TABLE `s22` (
      `CreateDate` date DEFAULT (curdate()) COMMENT '创建日期'
     );

This can be created in MySQL 8, but is there a similar syntax in TiDB?

| username: TIDB-Learner | Original post link

7.5+ is compatible with 8+, but versions lower than that do not support this syntax.

| username: 等一分钟 | Original post link

Sure, thanks!

| username: forever | Original post link

Can you try if now() is supported?

| username: TiDBer_bpfeWK9K | Original post link

DEFAULT CURRENT_TIMESTAMP, like this?

| username: 等一分钟 | Original post link

This is possible.

| username: 等一分钟 | Original post link

But default current_date doesn’t work.

| username: zhanggame1 | Original post link

Referring to the default current value and default current value of our business table, it automatically updates upon udpate:
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ‘Creation Time’,
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘Update Time’

| username: Kongdom | Original post link

Supported starting from version v6.6.0.

| username: DBAER | Original post link

This is supported, right?

| username: Aaronz | Original post link

Learned this.

| username: TiDBer_HErMeXDz | Original post link

Try using now().

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.