473,416 Members | 1,736 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,416 software developers and data experts.

same trigger problem

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 still not working correctly. Here is my
code:

create trigger emp_update_id
BEFORE update on emp_update
REFERENCING NEW AS N for each row
SET unique_id = Generate_unique();

This works, but here's what happens when I try to input data into the table:

------------------------------ Commands Entered ------------------------------

insert into emp_update (empno, text)
values ('000050', 'update entry'), ('000060', 'update entry');
------------------------------------------------------------------------------

insert into emp_update (empno, text) values ('000050', 'update entry'),
('000060', 'update entry')
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=2,
TABLEID=2, COLNO=0" is not allowed. SQLSTATE=23502

SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=2,
TABLEID=2, COLNO=0 " is not allowed.

Explanation:

One of the following occurred:

o The update or insert value was NULL, but the object column
was declared as NOT NULL in the table definition.
Consequently:

- NULL values cannot be inserted into that column.

- An update cannot set values in that column to NULL.

- A SET transition-variable statement in a trigger cannot set
values in that column to NULL.

o The update or insert value was DEFAULT, but the object column
was declared as NOT NULL without WITH DEFAULT in the table
definition. Consequently:

- A default value of NULL cannot be inserted into that
column.

- An update cannot set default values of NULL in that column.

- A SET transition-variable statement in a trigger cannot set
default values of NULL in that column.

o The column name list for the INSERT statement omits a column
declared NOT NULL and without WITH DEFAULT in the table
definition.

o The view for the INSERT statement omits a column declared NOT
NULL and without WITH DEFAULT in the base table definition.

If the value for "<name>" is of the form "TBSPACEID=n1,
TABLEID=n2, COLNO=n3", then the column name from the SQL
statement was not available when the error was issued. The values
provided identify the tablespace, table, and column number of the
base table that does not allow NULL value.

Federated system users: this situation can be detected by the
federated server or by the data source. Some data sources do not
provide the appropriate values for "<name>". In these cases the
message token will have the following format: "<data
source>:UNKNOWN", indicating that the actual value for the
specified data source is unknown.

The statement cannot be processed.

Note: Under some circumstances, the token "<name>" may not be
filled in (sqlerrmc field of the SQLCA not filled in).

User Response:

Correct the SQL statement after examining the object table
definition to determine which columns of the table have the NOT
NULL attribute and do not have the WITH DEFAULT attribute.

If the value for "<name>" is of the form "TBSPACEID=n1,
TABLEID=n2, COLNO=n3", you can determine the table name and
column name using the following query:
SELECT C.TABSCHEMA, C.TABNAME,
C.COLNAME
FROM SYSCAT.TABLES AS T,
SYSCAT.COLUMNS AS C
WHERE T.TBSPACEID = n1
AND T.TABLEID = n2
AND C.COLNO = n3
AND C.TABSCHEMA = T.TABSCHEMA
AND C.TABNAME = T.TABNAME
The table and column identified by this query may be the base
table of a view for which the SQL statement failed.

Federated system users: if the reason is unknown, isolate the
problem to the data source failing the request (see the problem
determination guide for procedures to follow to identify the
failing data source) and examine the object definition for that
data source. Remember that the defaults (NULL and NOT NULL) are
not necessarily the same between data sources.

sqlcode : -407

sqlstate : 23502

SQLCODE: -407
Being new at this - I imagine that this means that because it is a primary
key it cannot be left null so the trigger won't work - Can anyone help me to
reword this or have any ideas about what to do in its place? Thanks for the
help.

--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums....m-db2/200607/1
Jul 24 '06 #1
2 4949
INSERT trigger, not UPDATE trigger :-)

CREATE TABLE T(pk VARCHAR(13) FOR BIT DATA NOT NULL PRIMARY KEY,
c1 INT);
CREATE TRIGGER TRG BEFORE INSERT ON T
REFERENCING NEW AS N FOR EACH ROW
SET N.pk = GENERATE_UNIQUE();
SELECT pk FROM NEW TABLE(INSERT INTO T(c1) VALUES (1), (2), (3), (4));
PK
-----------------------------
x'20060724131726776837000000'
x'20060724131726831227000000'
x'20060724131726831297000000'
x'20060724131726831308000000'

4 record(s) selected.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Jul 24 '06 #2
thank you so much
Serge Rielau wrote:
>INSERT trigger, not UPDATE trigger :-)

CREATE TABLE T(pk VARCHAR(13) FOR BIT DATA NOT NULL PRIMARY KEY,
c1 INT);
CREATE TRIGGER TRG BEFORE INSERT ON T
REFERENCING NEW AS N FOR EACH ROW
SET N.pk = GENERATE_UNIQUE();
SELECT pk FROM NEW TABLE(INSERT INTO T(c1) VALUES (1), (2), (3), (4));
PK
-----------------------------
x'20060724131726776837000000'
x'20060724131726831227000000'
x'20060724131726831297000000'
x'20060724131726831308000000'

4 record(s) selected.
--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums....m-db2/200607/1
Jul 24 '06 #3

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

Similar topics

1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
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,...
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...
12
by: Bob Stearns | last post by:
I am trying to create a duplicate prevention trigger: CREATE TRIGGER is3.ard_u_unique BEFORE UPDATE OF act_recov_date ON is3.flushes REFERENCING NEW AS N FOR EACH ROW MODE DB2SQL WHEN...
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...
1
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
2
by: dean.cochrane | last post by:
I have inherited a large application. I have a table which contains a hierarchy, like this CREATE TABLE sample_table( sample_id int NOT NULL parent_sample_id int NOT NULL ....lots of other...
1
by: degno84 | last post by:
hi.. i have a problem with this simple trigger! I wont to insert a row in the same table where I update a value. The trigger is that: CREATE OR REPLACE TRIGGER LOG_SPOSTAMENTI_NEW_DEST AFTER...
22
by: DreamersDelight | last post by:
Hi, I'm stuck on this problem and I can't find a sollution. I'm going to try and explain this step by step. 1 After certain rows get updated with a certain value. I don't know wich rows in...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.