Problems with defining triggers

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Problems with defining triggers
# 1  
Old 06-11-2009
Problems with defining triggers

I am running the example from the following webpage:
MySQL :: MySQL 5.0 Reference Manual :: 12.1.11 CREATE TRIGGER Syntax
and the problem is that triggers cannot be defined for some reason:
Code:
CREATE DATABASE IF NOT EXISTS triggertest;
USE triggertest;
CREATE TABLE test1(a1 INT);
CREATE TABLE test2(a2 INT);
CREATE TABLE test3(a3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
CREATE TABLE test4(
  a4 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  b4 INT DEFAULT 0
);

delimiter |

CREATE TRIGGER testref BEFORE INSERT ON test1
  FOR EACH ROW BEGIN
    INSERT INTO test2 SET a2 = NEW.a1;
    DELETE FROM test3 WHERE a3 = NEW.a1;
    UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1;
  END;
|

delimiter ;

and the result is:
Code:
Error: 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 testref BEFORE INSERT ON test1 FOR EACH ROW BE' at line 1

The database is initially empty, no other tables or triggers. What is the exact problem here and how do I fix it? Thanks in advance.

Code:
# mysql -v
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 164
Server version: 5.1.28-rc FreeBSD port: mysql-server-5.1.28_1

# 2  
Old 09-26-2009
The problem seems to have to do with the web form used. The code is correct and should be used within the mysql prompt/shell itself.
# 3  
Old 09-26-2009
I would also encourage you to use the manual for your version of mysql.

MySQL :: MySQL 5.1 Reference Manual :: 12.1.19 CREATE TRIGGER Syntax
# 4  
Old 09-26-2009
Yes, thanks for pointing that out.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Defining variable problem

Hi I'd say I'm having this weird problem where my script isn't taking the value off a variable or printing it. My code is like this: set count_C= `grep -c C mols` set count_H= `grep -c H mols` set count_O= `grep -c O mols` sed -i '7,7 s/$/ $count_C $count_O $count_H/g' input It... (8 Replies)
Discussion started by: saleheen
8 Replies

2. Shell Programming and Scripting

Main script triggers second and it has to run at specific interval

Hi Friends, I am newbie to shell programming and I am stuck trying to accomplish following task.We use Bamboo CI which executes script1 passing parameters. This Main script executes script2 as backend process as part of one of it statements. Task of script2 is to essentially check whether a... (0 Replies)
Discussion started by: aditya206
0 Replies

3. Programming

Problem defining a struct

I have the following code and getting the compilation errors baseLib/DynBaseObj.h:80: error: expected constructor, destructor, or type conversion before ‘(' token baseLib/DynBaseObj.h:89: error: expected constructor, destructor, or type conversion before ‘(' token baseLib/DynBaseObj.h:101:... (0 Replies)
Discussion started by: kristinu
0 Replies

4. UNIX for Dummies Questions & Answers

Help with defining PATH

Hi All, I have a trivial question but I dont know how to solve it. So basically I'm working on a USB key and I have a directory with some scripts which I use to work on files present in other directories within the USB or sometimes on the main harddisk too. The problem is every time I have to... (3 Replies)
Discussion started by: pawannoel
3 Replies

5. UNIX for Dummies Questions & Answers

Defining an alias FreeBSD

I have defined this alias as quick way to find out which mount point to use for a USB drive after inserting it: # alias da='dmesg | grep da | grep MB' However, when invoking it, it states the following: # da da: Command not found. Can someone explain what is the issue here and how it can be... (3 Replies)
Discussion started by: figaro
3 Replies

6. Programming

Defining the inputStream object

Question regarding extend issue What is the reason behind defining the inputStream object in this way... InputStream inputStream = new FileInputStream("c:\\input.txt"); I know that FileInputStream extends InputStream, is there anything else ? I mean we could have define it like ... (0 Replies)
Discussion started by: yahyaaa
0 Replies

7. Shell Programming and Scripting

defining variables

Hey all, I was wondering if someone would take a look at this script I'm working on. I don't know if i have the syntax correct for my variables and if the for loop is written correctly. any assistance would be greatly appreciated. #!/usr/bin/bash ###########################################... (12 Replies)
Discussion started by: em23
12 Replies

8. AIX

defining a printer in qconfig

I've got a modified samba script (named it winprint) that I can use to print out to a to a shared Win Network printer from an AIX machine. This is a modification of the samba provided smbprint script changed to work under AIX as the backend for a queue. It does not read a config file I can print... (0 Replies)
Discussion started by: matheeq
0 Replies

9. UNIX for Dummies Questions & Answers

Defining Variables

I'm trying to define a variable named sin I already have a variable named cos, which has the value "hello" I want sin to have the value of "hellothere", so sin would be something like sin = $cos & "there" but I'm not sure that I know the syntax. Can anyone help? :confused: (4 Replies)
Discussion started by: sailorliones
4 Replies
Login or Register to Ask a Question