Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 21st, 2005, 03:27 PM
janosch3 janosch3 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 2 janosch3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 32 sec
Reputation Power: 0
trigger

hello,
i have a entity with two key-attributes and one attribute 'number'.
if i make an insert and the the two keys exit already, the 'number' should be incremented and the insert-command should not be executed. if the keys don't exist the insert should be executed.
is there a possibility to do that with a trigger?

IF(OLD.KEY1 == NEW.KEY1)
UPDATE ... increment number
ELSE ... drop command

?????????

thanx

Reply With Quote
  #2  
Old November 22nd, 2005, 05:37 AM
SilverDB's Avatar
SilverDB SilverDB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Romania
Posts: 173 SilverDB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 45 m 53 sec
Reputation Power: 5
Send a message via Yahoo to SilverDB
the best way to do that is to check the existence before inserting the row ... but if for any reason you can't do that you can try yhis aproach:
let's suppose you have a table "TABLE1" that has the following data:

FIELD1|FIELD2|FIELD3
1 2 NUMBER (this is the number that you want to increment)

create a store procedure that takes 2 parameters (the table's fields that need the existence check)

execute procedure FIND_DUPLICATES(field1,field2);

the procedure code:
Code:
if (SELECT COUNT(*) FROM TABLE1 WHERE FIELD1=:field1 and FIELD2=:field2=1) then //IF THERE IS ALREADY 1 ROW WITH THOSE VALUES
  UPDATE TABLE1 SET NUMBER=NUMBER+1 WHERE FIELD1=field1 and FIELD2=field2;
else //IT SHOULD INSERT THE ROW
  INSERT INTO TABLE1(FIELD1,FIELD2,FIELD3) VALUES(:field1,:field2,1);

the above code is written entirely out of my head (i don't have a firebird server available right now) but it should give you an idea on how to code the logic on this one.
If you need further help don't hesitate to ask,
Good luck.
__________________
If i've been helpful, please add to my reputation.
My unfinished site: http://www.dever.ro

Reply With Quote
  #3  
Old November 22nd, 2005, 10:55 AM
janosch3 janosch3 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 2 janosch3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 32 sec
Reputation Power: 0
ok, thanx a lot, i try to make your suggestion work.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > trigger


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT