开发者

CREATE TRIGGER x BEFORE INSERT ON y IF q = ''

开发者 https://www.devze.com 2023-03-11 17:32 出处:网络
Following is a sample. I am trying to use BEFORE INSERT ON SET and have been to pages of google to look for help. This is the closest I can get:

Following is a sample. I am trying to use BEFORE INSERT ON SET and have been to pages of google to look for help. This is the closest I can get:

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;

And I know, I could do following, but then I have to explicitly call out the fields, besides I am kinda hung up on this.

CREATE TABLE user (alias TEXT, added TEXT DEFAULT (datetime('NOW','UTC')));


Well, in SQLite3 I do this to sort this similar issue:

CREATE TRIGGER [trigger_name]
AFTER INSERT
ON my_table
BEGIN UPDATE
      my_table SET my_date = datetime('now','localtime')      
      WHERE ROWID = NEW.ROWID;
END
0

精彩评论

暂无评论...
验证码 换一张
取 消