Subject | trigger primary key problem during record copy |
---|---|
Author | intellekta |
Post date | 2006-01-30T11:44:14Z |
Hello,
i have many tables in the database and i use a trigger to get unique ids
IF (NEW.ID IS NULL) THEN
NEW.ID = GEN_ID(GEN_TABLE1_ID,1);
for "normal" inserts like the following this works fine
insert (ID, FIELD1) values (10,'Value');
insert (FIELD1) values ('Value');
often i must copy a record in the same table
INSERT INTO TABLE1 SELECT * FROM TABLE1 WHERE ID = :RECORDTOCOPYID;
in this case i need the trigger like this
-- without IF (NEW.ID IS NULL) THEN
NEW.ID = GEN_ID(GEN_TABLE1_ID,1);
or is there a easy way to copy one record with all fields, except the
primary key field ID, using a generic SP for all tables?
Thanks in advance
Uwe Cramer
i have many tables in the database and i use a trigger to get unique ids
IF (NEW.ID IS NULL) THEN
NEW.ID = GEN_ID(GEN_TABLE1_ID,1);
for "normal" inserts like the following this works fine
insert (ID, FIELD1) values (10,'Value');
insert (FIELD1) values ('Value');
often i must copy a record in the same table
INSERT INTO TABLE1 SELECT * FROM TABLE1 WHERE ID = :RECORDTOCOPYID;
in this case i need the trigger like this
-- without IF (NEW.ID IS NULL) THEN
NEW.ID = GEN_ID(GEN_TABLE1_ID,1);
or is there a easy way to copy one record with all fields, except the
primary key field ID, using a generic SP for all tables?
Thanks in advance
Uwe Cramer