473,394 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Trigger

I use MySQL 5.1 for Win and develop client app.

I want to create BEFORE UPDATE trigger with this conditions:
-If the value wich is coming is, let say less then 0 then can not be accepted for store in the field on that row.
-to generate some err code or to initialize some condition to produce me info on the client side, by the other words-to gime mi info about it.

Thank's!
Oct 19 '08 #1
3 2698
Atli
5,058 Expert 4TB
Hi.

That sounds like fun, but I fail to see a question.
What exactly is it that you are having problems with?

We are more than happy to help you out, but you are going to have to try this yourself first. We won't do the work for you.

I suggest you check out the manual page on Trigger syntax and go from there.

Let us know if you have any specific problems we can help you get through.
Oct 19 '08 #2
Fair enough, perhaps my Q. was misty so here is again:
(before update)

Now I use this:

Expand|Select|Wrap|Line Numbers
  1. BEGIN
  2. IF NEW.thnum =0 THEN
  3. SET NEW.thnum=null;
  4. END IF; 
  5. END
and this generate err in my client app because field thnum can not be null. By other words, my intetion is to get some err to warn user that 0 is forbiden and this is the only way I find to do it.
I want, instead "SET NEW.thnum=null;" to find the way to IGNORE update but I can't find it.
MySql 5.xxx don't support warnings (raise error) by now so I must use workarround.
Oct 19 '08 #3
Atli
5,058 Expert 4TB
Ahh ok I see. So the problem is getting an error message from you trigger to your client application.

Technically, that isn't possible. As you say, MySQL 5.x doesn't support any sort of RaisError functionality like many of the other SQL servers do.

But to get around that, you could always do something you know will cause an error, and make that error include your message.

For example, if I did this:
Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER myTable_BeforeInsert
  2. BEFORE INSERT ON myTable
  3. FOR EACH ROW
  4. BEGIN
  5.     IF NEW.value <= 0 THEN
  6.         CALL `error`.`Value can not be zero or less.error`();
  7.     END IF;
  8. END;
  9.  
It would produce this error:
Expand|Select|Wrap|Line Numbers
  1. ERROR 1305 (42000): PROCEDURE error.Value can not be zero or less.error does not exist
This includes my message between the "error." and ".error" strings, which can easily be extracted and used.

It's not pretty, but it gets the job done :)
Oct 19 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matik | last post by:
Hello to all, I have a small question. I call the SP outer the DB. The procedure deletes some record in table T1. The table T1 has a trigger after delete. This is very importand for me, that...
6
by: Scott CM | last post by:
I have a multi-part question regarding trigger performance. First of all, is there performance gain from issuing the following within a trigger: SELECT PrimaryKeyColumn FROM INSERTED opposed...
9
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
6
by: Mary | last post by:
We are developing a DB2 V7 z/OS application which uses a "trigger" table containing numerous triggers - each of which is activated by an UPDATE to a different column of this "trigger" table. When...
0
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
0
by: JohnO | last post by:
Thanks to Serge and MarkB for recent tips and suggestions. Ive rolled together a few stored procedures to assist with creating audit triggers automagically. Hope someone finds this as useful as...
1
by: deepdata | last post by:
Hi, I am creating a trigger in DB2 express version. When i use the following syntax to create trigger CREATE TRIGGER USER_PK_TRIGGER BEFORE INSERT On users REFERENCING NEW As N FOR EACH...
9
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger,...
7
by: Shane | last post by:
I have been instructed to write a trigger that effectively acts as a foreign key. The point (I think) is to get me used to writing triggers that dont use the primary key(s) I have created the...
11
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.