Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12

Discussione: MySQL trigger

  1. #1

    MySQL trigger

    questo è li mio trigger nel file esempio2.sql
    codice:
    delimiter //
    
    create trigger insert_tipo
    after insert on Utenti
    for each row 
    begin 
    	if (utenti.tipo <> 'user') or (utenti.tipo <> 'admin') then
    		set utenti.tipo = 'user';
    	end if;
    end; 
    
    // delimiter ;
    questo è l'output
    codice:
    mysql> source /home/daniele/Desktop/workspace/wkssql/esempio2.sql
    ERROR 1193 (HY000): Unknown system variable 'tipo'
    ERROR 1064 (42000): 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' at line 1
    dove sbaglio?

    p.s. l'attributo tipo esiste

  2. #2
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    dov'è il codice php??
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  3. #3
    in questa sezione sta scritto discussioni su php e mysql

  4. #4

    Re: MySQL trigger

    questo è li mio trigger nel file esempio2.sql l'ho midificato ma non cambia la situazione
    codice:
    delimiter //
    
    create trigger insert_tipo
    after insert on Utenti
    for each row 
    begin 
    	if (utenti.tipo <> 'user') or (utenti.tipo <> 'admin') then
    		update utenti set utenti.tipo = 'user';
    	end if;
    end; 
    
    // delimiter ;
    questo è l'output
    codice:
    ERROR 1064 (42000): 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 'update utenti set utenti.tipo = 'user'' at line 6
    ERROR 1064 (42000): 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 'end if' at line 1
    ERROR 1064 (42000): 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 'end' at line 1
    dove sbaglio?

    p.s. l'attributo tipo esiste

  5. #5
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120

    Re: Re: MySQL trigger

    http://database.html.it/guide/lezione/2456/i-triggers/
    codice:
    delimiter //
    
    create trigger insert_tipo
    before insert on Utenti
    for each row 
    begin 
    	if (new.tipo <> 'user') or (new.tipo <> 'admin') then
    		set new.tipo = 'user';
    	end if;
    end; 
    
    // delimiter ;

  6. #6
    prima lo avevo fatto così ma dà più errori.....

  7. #7
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Originariamente inviato da danielinux80
    prima lo avevo fatto così ma dà più errori.....
    ...e postarli???

  8. #8
    ERROR 1064 (42000): 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 'end if' at line 1
    ERROR 1064 (42000): 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 'end' at line 1
    ERROR 1064 (42000): 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' at line 1

  9. #9
    Originariamente inviato da luca200
    ...e postarli???
    fatto....

  10. #10
    scusate ma un trigger da console come lo avvio? io ho messo il codice in un file .sql e l'ho avviato da console è corretto oppure c'è un altro modo?

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.