If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Duplicate key - Trigger

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-12-11, 08:31
kbum kbum is offline
Registered User
 
Join Date: Mar 2011
Posts: 12
Question Duplicate key - Trigger

Good morning. I'm having a big problem.
I'll try to explain the problem.
I am currently migrating a legacy system that has over 2000 tables.
The tables do not have sequence linked to the primary key. When an insertion is made, the application performs a "MAX (id)" and insert triggers. That's too bad, because the generation IDs are linked to the application and not the bank.
Our company, which is responsible for this migration is reshaping the entire database by removing inconsistent data, creating FK's.
The database has two tables, the current table (which is old table) and the new table (remodeled), and these two tables must contain the same data, because we will release the new system modules.
When launching a new module, both the old system as the new system may use a single table.
When recording in the table of old application, the data should also be recorded on the new table.
I'm passing the following problem:
When I do an insert for the current application and at the same time I do an insert in the old application, in the same table, the ID ends up being "lost."
Example:
Old app
Insert table in doc
Before trigger set id = max (id) +1
After insert trigger in new table => id = max (id +1)

Newapp
Insert table in doc
Before trigger set id = max (id) +1
After insert trigger in old table => id = max (id +1)

If the insert is done at the same time, there will be replication ids.
Remember that you can not put a SEQUENCE in the old table, because the moorings of the system are made via the JPA and not internally in the bank.
Has anyone gone through this problem? Do you have any possible solution to share?
Reply With Quote
  #2 (permalink)  
Old 04-12-11, 12:13
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I'm assuming that you don't really need consecutive IDs. You could allocate a pool of IDs for one of the tables, e.g. in the new app
Quote:
Before trigger set id = max (id) +1000001
Just make sure that the number is large enough to accommodate insertions in the old table.
Reply With Quote
  #3 (permalink)  
Old 04-12-11, 14:10
kbum kbum is offline
Registered User
 
Join Date: Mar 2011
Posts: 12
Question

Your idea would work if the data in a table were not synchronized, ie the old record in the table has a trigger that writes the same data in new table.
MAX takes the highest value and adds 1, ie, will give the same problem.
Reply With Quote
Reply

Tags
db2, duplicate, problem, trigger

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On