以下是一个示例。我正在尝试使用BEFORE INSERT ON SET并访问谷歌页面以寻求帮助。这是我能得到的最接近的:
CREATE TABLE user (alias TEXT, added TEXT);
CREATE TRIGGER user_insert_time
BEFORE INSERT ON user
FOR EACH ROW
BEGIN SET new.added = (datetime('NOW','UTC')));
END;
OR
CREATE TRIGGER user_insert_time
BEFORE INSERT ON user
FOR EACH ROW BEGIN
IF (new.added = '')
THEN SET new.added = (datetime('NOW','UTC')));
END;
而且我知道,我可以跟随,但是我必须明确地召唤出这些领域,除此之外我还有点挂了。
CREATE TABLE user (alias TEXT, added TEXT DEFAULT (datetime('NOW','UTC')));
答案 0 :(得分:2)
好吧,在SQLite3中,我这样做是为了解决这个类似的问题:
CREATE TRIGGER [trigger_name] AFTER INSERT ON my_table BEGIN UPDATE my_table SET my_date = datetime('now','localtime') WHERE ROWID = NEW.ROWID; END