473,403 Members | 2,323 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,403 software developers and data experts.

trigger fire at not null columns

hi gurus,
here is the problem
i have a table with 2 columns first one is the primary key
with small int next one is integer
then i need a trigger with out using sequence or identity that when i
insert a second column the first column should be fired with and number
next onward it should be incremented

Nov 12 '05 #1
4 1156

"narayana" <va***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
hi gurus,
here is the problem
i have a table with 2 columns first one is the primary key
with small int next one is integer
then i need a trigger with out using sequence or identity that when i
insert a second column the first column should be fired with and number
next onward it should be incremented

I just read your question twice and I don't understand what you are trying
to do. Can you clarify the question?

Also, what operating system are you using and what version of DB2 are you
running?

Rhino
Nov 12 '05 #2
Rhino wrote:
"narayana" <va***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
hi gurus,
here is the problem
i have a table with 2 columns first one is the primary key
with small int next one is integer
then i need a trigger with out using sequence or identity that when i
insert a second column the first column should be fired with and number
next onward it should be incremented


I just read your question twice and I don't understand what you are trying
to do. Can you clarify the question?

Also, what operating system are you using and what version of DB2 are you
running?

Rhino

Taking some guesses....

CREATE TABLE T(c1 NOT NULL SMALLINT PRIMARY KEY, c2 INTEGER);
CREATE TRIGGER trg1 NO CASCADE BEFORE INSERT ON T
REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL
WHEN (n.pk IS NULL)
SET n.pk = (SELECT COALESCE(MAX(pk), 0) + 1 FROM T);

Should work as long as only single rows are inserted.
For multirow need to use the counter function in sqllib/samples/c

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3
this thing i want in windows 2000 OS DB2 v 8.2

waiting for result

Nov 12 '05 #4
Not sure if this is what you want BUT you could try ..

CREATE FUNCTION GET_NEXT_PK_ID()
RETURNS SMALLINT
LANGUAGE SQL
READS SQL DATA
NO EXTERNAL ACTION
DETERMINISTIC
RETURN SELECT DISTINCT CASE
WHEN MAX(COL1) IS NULL THEN 1
WHEN MAX(COL1) = 0 THEN 1
ELSE MAX(COL1)+1
END
FROM TABLE_NAME ;

INSERT INTO TABLE_NAME (COL1, COL2) VALUES (GET_NEXT_PK_ID(), 123);

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Lauren Quantrell | last post by:
I have never written a trigger before and now am seeing the light. Is there a way to write a trigger so that if a user changes any column in a single row on one table then the trigger will write...
5
by: Neil Rutherford | last post by:
During testing of an application, i noticed a difference between SQL 2000 and SQL 7, both with identical config. In a nutshell: A table has a trigger for UPDATE and DELETE. When a column in the...
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,...
5
by: William of Ockham | last post by:
Hi, I was asked to recreate a new clean database for our developers because the current one they use is not entirely up to date. So I created a new database and I run into the followin strange...
4
by: Alexander Pope | last post by:
I am using db2 udb v8.2 AIX I have created trigger, however I am not confident it meets industry standards. If I make it fail, I cant tell from the message where it is failing. what can I add to...
3
by: teddysnips | last post by:
I need a trigger (well, I don't *need* one, but it would be optimal!) but I can't get it to work because it references ntext fields. Is there any alternative? I could write it in laborious code...
2
by: mob1012 via DBMonster.com | last post by:
Hi All, I wrote last week about a trigger problem I was having. I want a trigger to produce a unique id to be used as a primary key for my table. I used the advice I received, but the trigger is...
13
by: dennis | last post by:
Hello, I'm having trouble solving the following problem with DB2 UDB 8.2. I need to create a trigger that performs certain extra constraint validations (temporal uniqueness). One of the tables...
5
by: furulo | last post by:
Hi, The following trigger does fire if the column has a NULL or if a NULL is updated to the column. Any ides how to fix this? AFTER UPDATE ON <table name> REFERENCING NEW AS n OLD AS o
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.