public static void enforceForeignKeyConstriants(Statement stmt) throws SQLException {
        
        /*
        String fk_Tools_LocationCode =
                "CONSTRAINT fk_Tools_LocationCode "+                
                "FOREIGN KEY(LocationCode) REFERENCES Locations(Code)"+
                "ON UPDATE RESTRICT ON DELETE RESTRICT;";
        */    
        String onDelete = "RESTRICT";
        String onUpdate = "RESTRICT";       
        
        String[] refTables  = {"Divisions", "Conditions", "Locations"};
        String refColumn = "Code";
        String table = "Tools";
        String column;
        String fkName;
        
        for (String refTable : refTables ) {
            column = refTable.substring(0, refTable.length()-1)+refColumn;
            fkName = table+"_"+column;
            
            String fki =
                    "CREATE TRIGGER fki_"+fkName
                   +" BEFORE INSERT ON "+table
                   +" FOR EACH ROW BEGIN " 
                   +" SELECT "
                   +    " RAISE(ROLLBACK,"
                   +    " 'insert on table \""+table+"\""
                   +    " violates foreign key constraint \"fk_"+fkName+"\"') "
                   +" WHERE "
                   +    " new."+column+" IS NOT NULL "
                   +    " AND"
                   +    " (SELECT "+refColumn+" FROM "+refTable+" WHERE "+refColumn+" = new."+column+") IS NULL;"
                   +" END;";                             

            String fku =
                "CREATE TRIGGER fku_"+fkName
               +" BEFORE UPDATE OF "+column+" ON "+table
               +" FOR EACH ROW BEGIN "
               +" SELECT "
               +    "RAISE(ROLLBACK, "
               +    " 'update on table \""+table+"\""
               +    " violates foreign key constraint \"fk_"+fkName+"\"') "
               +"WHERE "
               +    "new."+column+" IS NOT NULL "
               +    "AND "
               +    "(SELECT "+refColumn+" FROM "+refTable+" WHERE "+refColumn+" = new."+column+") IS NULL; "
               +"END;";        

            String updateAction;
            switch (onUpdate.toUpperCase()) {
                case "RESTRICT" :
                    updateAction =
                            "BEFORE UPDATE OF "+column+" ON "+refTable
                            +" FOR EACH ROW BEGIN "
                            +"SELECT "
                            + " RAISE(ROLLBACK, "
                            + " 'update on table \""+refTable+"\" violates foreign key constraint \"fk_"+fkName+"\"') "
                            +"WHERE "
                            + " (SELECT "+column+" FROM "+table+" WHERE "+column+" = new."+refColumn+") IS NOT NULL; "
                            +"END;";
                            break;
                    
                case "CASCADE" :                    
                    updateAction =
                            "AFTER UPDATE OF "+column+" ON "+refTable
                            +" FOR EACH ROW BEGIN "
                            +"UPDATE "+table+" SET new."+column+" = old."+refColumn+";"
                            +"END;";
                            break;
                            
                default : throw new IllegalArgumentException(onUpdate +": action not supported");                    
            }
            
            String fku2 = "CREATE TRIGGER fku2_"+fkName+" "+updateAction;
       
            String deleteAction;
            switch (onDelete.toUpperCase()) {
                case "RESTRICT" :
                    deleteAction =
                       " SELECT "
                       +    " RAISE(ROLLBACK, "
                       +    " 'delete on table \""+refTable+"\""
                       +    " violates foreign key constraint \"fk_"+fkName+"\"') "
                       +" WHERE"
                       +    " (SELECT "+column+" FROM "+table+" WHERE "+column+" = old."+refColumn+") IS NOT NULL; ";
                       break;
                            
                case "CASCADE"  :
                    deleteAction =
                       " DELETE from "+table+" WHERE "+column+" = old."+refColumn+";";
                       break;

                default : throw new IllegalArgumentException(onDelete +": action not supported");
            }
            
            String fkd =
                " CREATE TRIGGER fkd_"+fkName
               +" BEFORE DELETE ON "+refTable
               +" FOR EACH ROW BEGIN "
               + deleteAction
               +" END;";                
            
            stmt.executeUpdate(fki);
            stmt.executeUpdate(fku);
            stmt.executeUpdate(fku2);
            stmt.executeUpdate(fkd);
            
        }
    }