2

Is it possible for SQLite to dynamically insert/update values in the row of a table based on other columns within that row? Best illustrated with a simple example

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

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

And have the table automatically fill in the third column with a combination of the other two:

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

1 Answer 1

1

You could use a 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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.