<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ca">
	<id>http://wiki.joanillo.org/index.php?action=history&amp;feed=atom&amp;title=Disparadors_%2F_triggers_a_MySQL</id>
	<title>Disparadors / triggers a MySQL - Historial de revisió</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.joanillo.org/index.php?action=history&amp;feed=atom&amp;title=Disparadors_%2F_triggers_a_MySQL"/>
	<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Disparadors_/_triggers_a_MySQL&amp;action=history"/>
	<updated>2026-08-30T00:32:16Z</updated>
	<subtitle>Historial de revisió per a aquesta pàgina del wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=Disparadors_/_triggers_a_MySQL&amp;diff=299070&amp;oldid=prev</id>
		<title>Joan: /* DROP TRIGGER */</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Disparadors_/_triggers_a_MySQL&amp;diff=299070&amp;oldid=prev"/>
		<updated>2022-05-16T14:28:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;DROP TRIGGER&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ca&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versió més antiga&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revisió del 14:28, 16 maig 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l89&quot; &gt;Línia 89:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 89:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{Autor}}, maig 2022&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;{&lt;/ins&gt;{Autor}}, maig 2022&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=Disparadors_/_triggers_a_MySQL&amp;diff=299062&amp;oldid=prev</id>
		<title>Joan: /* Introducció */</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Disparadors_/_triggers_a_MySQL&amp;diff=299062&amp;oldid=prev"/>
		<updated>2022-05-11T15:54:08Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Introducció&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ca&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versió més antiga&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revisió del 15:54, 11 maig 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Línia 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__TOC__&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__TOC__&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Introducció=&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Introducció=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;'''NOTA'''. Per crear ''triggers'' (igual que passava amb les ''functions'') s'ha de tenir permisos de ''SUPER''. Evidentment l'usuari ''root'' té aquests permisos, i per tant pots crear els teus triggers amb l'usauri ''root''. Si vols crear els triggers amb l'usuari ''alumne'' se li han d'atorgar els permisos:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;pre&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;mysql&amp;gt; GRANT SUPER ON *.* TO alumne@localhost&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/pre&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(aquesta sentència s'ha d'executar des de l'usuari ''root'', evidentment). Per crear procediments això no era necessari.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*https://www.mysqltutorial.org/mysql-triggers/&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;*https://www.mysqltutorial.org/mysql-triggers/&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A MySQL, un ''trigger'' és un procediment emmagatzemat que s'invoca automàticament en resposta a un event com ara un ''insert'', ''update'' o ''delete'' sobre una taula associada. Per exemple, pots definir un ''trigger'' que s'invoca autoàticament abans que una nova fila s'insereixi sobre una taula.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A MySQL, un ''trigger'' és un procediment emmagatzemat que s'invoca automàticament en resposta a un event com ara un ''insert'', ''update'' o ''delete'' sobre una taula associada. Per exemple, pots definir un ''trigger'' que s'invoca autoàticament abans que una nova fila s'insereixi sobre una taula.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=Disparadors_/_triggers_a_MySQL&amp;diff=299055&amp;oldid=prev</id>
		<title>Joan: /* Introducció */</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Disparadors_/_triggers_a_MySQL&amp;diff=299055&amp;oldid=prev"/>
		<updated>2022-05-11T13:18:24Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Introducció&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ca&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versió més antiga&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revisió del 13:18, 11 maig 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Línia 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__TOC__&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__TOC__&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Introducció=&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Introducció=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;*https://www.mysqltutorial.org/mysql-triggers/&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A MySQL, un ''trigger'' és un procediment emmagatzemat que s'invoca automàticament en resposta a un event com ara un ''insert'', ''update'' o ''delete'' sobre una taula associada. Per exemple, pots definir un ''trigger'' que s'invoca autoàticament abans que una nova fila s'insereixi sobre una taula.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A MySQL, un ''trigger'' és un procediment emmagatzemat que s'invoca automàticament en resposta a un event com ara un ''insert'', ''update'' o ''delete'' sobre una taula associada. Per exemple, pots definir un ''trigger'' que s'invoca autoàticament abans que una nova fila s'insereixi sobre una taula.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=Disparadors_/_triggers_a_MySQL&amp;diff=299040&amp;oldid=prev</id>
		<title>Joan: Es crea la pàgina amb «__TOC__ =Introducció= A MySQL, un ''trigger'' és un procediment emmagatzemat que s'invoca automàticament en resposta a un event com ara un ''insert'', ''update'' o...».</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Disparadors_/_triggers_a_MySQL&amp;diff=299040&amp;oldid=prev"/>
		<updated>2022-05-09T17:24:48Z</updated>

		<summary type="html">&lt;p&gt;Es crea la pàgina amb «__TOC__ =Introducció= A MySQL, un &amp;#039;&amp;#039;trigger&amp;#039;&amp;#039; és un procediment emmagatzemat que s&amp;#039;invoca automàticament en resposta a un event com ara un &amp;#039;&amp;#039;insert&amp;#039;&amp;#039;, &amp;#039;&amp;#039;update&amp;#039;&amp;#039; o...».&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pàgina nova&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
=Introducció=&lt;br /&gt;
A MySQL, un ''trigger'' és un procediment emmagatzemat que s'invoca automàticament en resposta a un event com ara un ''insert'', ''update'' o ''delete'' sobre una taula associada. Per exemple, pots definir un ''trigger'' que s'invoca autoàticament abans que una nova fila s'insereixi sobre una taula.&lt;br /&gt;
&lt;br /&gt;
A MySQL els triggers suporten events que s'invoquen en resposta a events tipus INSERT, UPDATE o DELETE.&lt;br /&gt;
&lt;br /&gt;
A MySQL només estan suportats els triggers a nivell de fila, no a nivell de sentència. Això vol dir que si un delete o update afecta a 10 files, s'executarà 10 vegades el trigger, un per cada fila afectada. Els triggers a nivell de sentència no estan suportats (això seria fer un delete que afecta a 10 files, però només s'executa un trigger).&lt;br /&gt;
&lt;br /&gt;
=Creació del trigger=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TRIGGER trigger_name&lt;br /&gt;
{BEFORE | AFTER} {INSERT | UPDATE| DELETE }&lt;br /&gt;
ON table_name FOR EACH ROW&lt;br /&gt;
trigger_body;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Treballarem amb la taula ''employees'' de la base de dades ''classicmodels''.&lt;br /&gt;
&lt;br /&gt;
Volem guardar els canvis que es facin en la taula ''employees''. És a dir, volem auditar aquesta taula. Creem la taula ''employees_audit'':&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE employees_audit (&lt;br /&gt;
    id INT AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;
    employeeNumber INT NOT NULL,&lt;br /&gt;
    lastname VARCHAR(50) NOT NULL,&lt;br /&gt;
    changedat DATETIME DEFAULT NULL,&lt;br /&gt;
    action VARCHAR(50) DEFAULT NULL&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
I ara creem el següent trigger:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TRIGGER before_employee_update &lt;br /&gt;
    BEFORE UPDATE ON employees&lt;br /&gt;
    FOR EACH ROW &lt;br /&gt;
 INSERT INTO employees_audit&lt;br /&gt;
 SET action = 'update',&lt;br /&gt;
     employeeNumber = OLD.employeeNumber,&lt;br /&gt;
     lastname = OLD.lastname,&lt;br /&gt;
     changedat = NOW();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SHOW TRIGGERS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Si ara fem un ''update'' sobre ''empleats'', veurem com s'ha fet una inserció sobre la taula d'auditació:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UPDATE employees SET lastName = 'Phan' WHERE employeeNumber = 1056;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT * FROM employees_audit;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=DROP TRIGGER=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP TRIGGER [IF EXISTS] [schema_name.]trigger_name;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE billings (&lt;br /&gt;
    billingNo INT AUTO_INCREMENT,&lt;br /&gt;
    customerNo INT,&lt;br /&gt;
    billingDate DATE,&lt;br /&gt;
    amount DEC(10 , 2 ),&lt;br /&gt;
    PRIMARY KEY (billingNo)&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Creem un trigger:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER $$&lt;br /&gt;
CREATE TRIGGER before_billing_update&lt;br /&gt;
    BEFORE UPDATE &lt;br /&gt;
    ON billings FOR EACH ROW&lt;br /&gt;
BEGIN&lt;br /&gt;
    IF new.amount &amp;gt; old.amount * 10 THEN&lt;br /&gt;
        SIGNAL SQLSTATE '45000' &lt;br /&gt;
            SET MESSAGE_TEXT = 'New amount cannot be 10 times greater than the current amount.';&lt;br /&gt;
    END IF;&lt;br /&gt;
END$$    &lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SHOW TRIGGERS;&lt;br /&gt;
&lt;br /&gt;
DROP TRIGGER before_billing_update;&lt;br /&gt;
&lt;br /&gt;
SHOW TRIGGERS;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{Autor}}, maig 2022&lt;/div&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
</feed>