0

我在 SQLite 数据库中创建的这张表:

CREATE TABLE [tickets] (
[id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
[coupon_id] INTEGER  NULL,
[size] FLOAT  NULL,
[phone] VARCHAR(10)  NULL,
[date] DATE DEFAULT CURRENT_DATE NULL,
[time] TIME DEFAULT CURRENT_TIME NULL,
[product] TEXT  NULL
);

现在我在mysql中转换这个表

CREATE TABLE tickets (
id INTEGER  PRIMARY KEY AUTO_INCREMENT NOT NULL,
coupon_id INTEGER  NULL,
size FLOAT  NULL,
phone VARCHAR(10)  NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL,
time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL,
product TEXT  NULL
);

INSERT INTO "tickets" VALUES(429,9,18.16,'949-893-5032','2010-11-30','17:46:39','Kids’ Kups Berry Interesting™');
INSERT INTO "tickets" VALUES(430,9,12.04,'847-188-1359','2010-11-25','10:54:00','Raspberry Collider™');
INSERT INTO "tickets" VALUES(431,9,14.1,'204-682-5560','2010-12-08','15:34:07','Celestial Cherry High™');

当我插入这些值时出现错误ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause.

我能够在 SQLite 中插入所有这些值,但我无法将所有这些值插入 MySQL。帮我?

4

2 回答 2

0

据我所知,MySQL 不允许这样做。如果要将当前时间插入到第二个字段中,请考虑在插入时使用触发器来更新记录。

DELIMITER $$
CREATE TRIGGER curtime BEFORE INSERT ON tickets FOR EACH ROW
BEGIN
SET NEW.time = CURRENT_TIMESTAMP();
END;
$$
DELIMITER ;
于 2011-11-08T09:33:26.880 回答
0

您可能想要转换

date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL,
time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL,

created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL,

并连接来自 SQLite 的值,或更改它们的类型

date date DEFAULT NULL,
time time DEFAULT NULL,

并使用触发器添加当前日期/时间。

于 2011-11-08T09:35:33.200 回答