0

I have this query:

 @db.execute("CREATE TABLE IF NOT EXISTS programs(programId INTEGER PRIMARY KEY NOT NULL 
     AUTOINCREMENT, programName TEXT NOT NULL, episodeName TEXT, UNIQUE(programName, 
     episodeName) ON CONFLICT IGNORE)")

Instead of ignoring this, what I'd like it to do is to insert the the data into a "Conflicts" table if there is a conflict in any one of my tables. How do I set up for this scenario? Obviously Id have to have the conflicts table created but what next?

Thanks

4

1 回答 1

1

你在找这个吗?

CREATE TABLE programs
(
  programId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 
  programName TEXT NOT NULL, 
  episodeName TEXT, 
  UNIQUE(programName, episodeName) ON CONFLICT IGNORE
);
CREATE TABLE program_dupes
(
  programId INTEGER, 
  programName TEXT, 
  episodeName TEXT 
);

扳机

CREATE TRIGGER tg_programs_insert
BEFORE INSERT ON programs
FOR EACH ROW
BEGIN
  INSERT INTO program_dupes (programId, programName, episodeName)
  SELECT programId, NEW.programName, NEW.episodeName
    FROM programs
   WHERE programName = NEW.programName 
     AND episodeName = NEW.episodeName;

END

这是SQLFiddle演示

于 2013-07-25T03:50:59.897 回答