mysql 21.041sec 是多长时间
答案:1 悬赏:10 手机版
解决时间 2021-01-21 23:27
- 提问者网友:聂風
- 2021-01-21 04:54
mysql 21.041sec 是多长时间
最佳答案
- 五星知识达人网友:第四晚心情
- 2021-01-21 05:32
也就是你无法 设置某一列,默认值是 NOW () 这样的处理
假如需要 某列的默认值为 当前数据库时间,那么可以使用 TIMESTAMP 数据类型。插入的时候,忽略该列 即可。
dt TIMESTAMP
等价于
dt TIMESTAMP default CURRENT_TIMESTAMP ON UPDATe CURRENT_TIMESTAMP
create table testB (
id int PRIMARY KEY,
val varchar(10),
dt TIMESTAMP
);
INSERT INTO testB(id, val) VALUES(1, 'A');
INSERT INTO testB(id, val) VALUES(2, 'B');
SELECT
*
FROM
testB;
+----+------+---------------------+
| id | val | dt |
+----+------+---------------------+
| 1 | A | 2013-03-21 14:24:20 |
| 2 | B | 2013-03-21 14:24:21 |
+----+------+---------------------+
2 rows in set (0.00 sec)
UPDATe
testB
SET
val = 'C'
WHERe
id = 1;
SELECT
*
FROM
testB;
+----+------+---------------------+
| id | val | dt |
+----+------+---------------------+
| 1 | C | 2013-03-21 14:28:02 |
| 2 | B | 2013-03-21 14:24:21 |
+----+------+---------------------+
2 rows in set (0.00 sec)
假如仅仅需要 插入时记录时间, 更新的时候不需要, 那么需要修改表定义方式:
TIMESTAMP not null default CURRENT_TIMESTAMP
create table testC (
id int PRIMARY KEY,
val varchar(10),
dt TIMESTAMP not null default CURRENT_TIMESTAMP
);
INSERT INTO testC(id, val) VALUES(1, 'A');
INSERT INTO testC(id, val) VALUES(2, 'B');
SELECt
*
FROM
testC;
+----+------+---------------------+
| id | val | dt |
+----+------+---------------------+
| 1 | A | 2013-03-21 14:35:12 |
| 2 | B | 2013-03-21 14:35:13 |
+----+------+---------------------+
2 rows in set (0.00 sec)
UPDATe
testC
SET
val = 'CC'
WHERe
id = 1;
SELECT
*
FROM
testC;
+----+------+---------------------+
| id | val | dt |
+----+------+---------------------+
| 1 | CC | 2013-03-21 14:35:12 |
| 2 | B | 2013-03-21 14:35:13 |
+----+------+---------------------+
2 rows in set (0.00 sec)
假如需要 某列的默认值为 当前数据库时间,那么可以使用 TIMESTAMP 数据类型。插入的时候,忽略该列 即可。
dt TIMESTAMP
等价于
dt TIMESTAMP default CURRENT_TIMESTAMP ON UPDATe CURRENT_TIMESTAMP
create table testB (
id int PRIMARY KEY,
val varchar(10),
dt TIMESTAMP
);
INSERT INTO testB(id, val) VALUES(1, 'A');
INSERT INTO testB(id, val) VALUES(2, 'B');
SELECT
*
FROM
testB;
+----+------+---------------------+
| id | val | dt |
+----+------+---------------------+
| 1 | A | 2013-03-21 14:24:20 |
| 2 | B | 2013-03-21 14:24:21 |
+----+------+---------------------+
2 rows in set (0.00 sec)
UPDATe
testB
SET
val = 'C'
WHERe
id = 1;
SELECT
*
FROM
testB;
+----+------+---------------------+
| id | val | dt |
+----+------+---------------------+
| 1 | C | 2013-03-21 14:28:02 |
| 2 | B | 2013-03-21 14:24:21 |
+----+------+---------------------+
2 rows in set (0.00 sec)
假如仅仅需要 插入时记录时间, 更新的时候不需要, 那么需要修改表定义方式:
TIMESTAMP not null default CURRENT_TIMESTAMP
create table testC (
id int PRIMARY KEY,
val varchar(10),
dt TIMESTAMP not null default CURRENT_TIMESTAMP
);
INSERT INTO testC(id, val) VALUES(1, 'A');
INSERT INTO testC(id, val) VALUES(2, 'B');
SELECt
*
FROM
testC;
+----+------+---------------------+
| id | val | dt |
+----+------+---------------------+
| 1 | A | 2013-03-21 14:35:12 |
| 2 | B | 2013-03-21 14:35:13 |
+----+------+---------------------+
2 rows in set (0.00 sec)
UPDATe
testC
SET
val = 'CC'
WHERe
id = 1;
SELECT
*
FROM
testC;
+----+------+---------------------+
| id | val | dt |
+----+------+---------------------+
| 1 | CC | 2013-03-21 14:35:12 |
| 2 | B | 2013-03-21 14:35:13 |
+----+------+---------------------+
2 rows in set (0.00 sec)
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯