lundi 1 février 2016

SQL lite create Trigger to add row on a historic table

String SQL = "CREATE TRIGGER "+ TRIGGER_CONTACT_HISTORY+
            " UPDATE OF "+CONTACT_COL+ " ON "+ CONTACT_TABLE+
            " WHEN "+CONTACT_COL+" = 1"+
            " BEGIN "+
            "INSERT INTO "+CONTACT_HISTORY_TABLE+
            " ( "+CONTACT_HISTORY_REF_ID_CONTACT+
            ") SELECT "+CONTACT_ID+" FROM "+CONTACT_TABLE+
            " WHERE "+ CONTACT_ID+ " = old."+CONTACT_ID+
            "; END";

Hi everybody, I'm looking to create a trigger that can populate a Historic table when a specific column is update in a specific value. For example in CONTACT_TABLE the column CONTACT_COL is update to value 1 and I would like that the HISTORIC_TABLE take a insert with the some information of this contact updated.. How can I do that ? Thank you for your help

Aucun commentaire:

Enregistrer un commentaire