2014-12-02 106 views
2

SQLite是否有可能基於該行內的其他列動態插入/更新表中某行的值?一個簡單的例子基於列值動態更新SQLite行

CREATE TABLE family(first TEXT, last TEXT, full TEXT *magical specification); 

INSERT INTO family (first,last) VALUES ('foo','bar') 

最佳圖示,並且該表在第三列自動填寫與其他兩個組合:

first  last   full 
--------- ------------ ----------- 
    foo   bar   foo bar 

回答

1

你可以使用一個trigger

CREATE TRIGGER family_full 
AFTER INSERT ON family 
FOR EACH ROW 
WHEN NEW.full IS NULL 
BEGIN 
    UPDATE family 
    SET full = first || ' ' || last 
    WHERE rowid = NEW.rowid; 
END;