Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2004
    Messaggi
    110

    Problema creazione Trigger mysql

    Salve a tutti, premesso che non sono afferatissimo in materia di trigger, vi descrivo il mio problema:

    sto usando phpmyadmin su un server remoto con mysql 5.0.22, e ho creato il seguente trigger:

    codice:
    DELIMITER $$
    CREATE TRIGGER chiesa_insert
    AFTER INSERT ON jos_chiesa
    FOR EACH ROW
    BEGIN
             INSERT INTO jos_territorio(id, id_territorio, genere, utente) VALUES (NULL, NEW.id, NEW.genere, NEW.utente);
    END;
    $$
    e phpmyadmin mi stampa il seguente messaggio:

    Errore query SQL:
    DELIMITER $$ CREATE TRIGGER chiesa_insert
    AFTER INSERT ON jos_chiesa
    FOR EACH
    ROW
    BEGIN INSERT INTO jos_territorio( id, id_territorio, genere, utente ) VALUES ( NULL , NEW.id, NEW.genere, NEW.utente ); $$

    Messaggio di MySQL: Documentazione #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$ CREATE TRIGGER chiesa_insert AFTER INSERT ON jos_chiesa FOR EACH' at line 1
    Allora ho tolto il delimiter e i due $$ sia all'inizio che alla fine. Risultato:

    Errore

    query SQL:

    CREATE TRIGGER chiesa_insert AFTER INSERT ON jos_chiesa
    FOR EACH
    ROW
    BEGIN
    INSERT INTO jos_territorio( id, id_territorio, genere, utente )
    VALUES (
    NULL , NEW.id, NEW.genere, NEW.utente
    );

    Messaggio di MySQL: Documentazione
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO jos_territorio( id, id_territorio, genere, utente )
    VALUES (
    NULL ' at line 4
    Se provo a creare un semplice trigger così fatto:

    codice:
    CREATE TRIGGER chiesa_insert
    AFTER INSERT ON jos_chiesa
    FOR EACH ROW
    BEGIN
    END;
    il trigger viene correttamente creato.

    Suppongo che a questo punto la sintassi sbagliata stia nella insert, ma sinceramente non capisco dove stia sbagliando.

    Qualcuno ha qualche idea? Vi ringrazio anticipatamente.

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2004
    Messaggi
    110
    Ho notato che anche inserendo una semplice tabella come la seguente:

    codice:
    CREATE TABLE `jos_prova` (
      `nome` varchar(255) NOT NULL,
      PRIMARY KEY  (`nome`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    e definendo poi il trigger come segue:

    codice:
    CREATE TRIGGER nome_db.chiesa_insert AFTER INSERT ON nome_db.jos_chiesa
    FOR EACH ROW
    BEGIN
    INSERT INTO nome_db.jos_prova VALUES (`asd`);
    END;
    il risultato è sempre lo stesso:

    [QUOTE]
    query SQL:

    CREATE TRIGGER aveddhi_.chiesa_insert AFTER INSERT ON aveddhi_.jos_chiesa
    FOR EACH
    ROW
    BEGIN
    INSERT INTO aveddhi_.jos_prova
    VALUES (
    `asd`
    );

    Messaggio di MySQL: Documentazione
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO aveddhi_.jos_prova VALUES (`asd`)' at line 5

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.