-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: foreign key issue in one transaction, please help
PostPosted: Tue Jul 15, 2008 11:01 pm 
Newbie

Joined: Sun Jun 22, 2008 10:08 pm
Posts: 4
Hey guys,

I'm having problem getting the scenario below working in one transaction.

Assume:
Table #1 - "salesTable"
Table #2 - "salesHistory"

salesTable has the following composite ID (customerId, salesId)
note# customerId is known before hand, salesId is generated (+1) during each insert.

salesHistory has the same composite ID (customerId, salesId)
I need the salesId in the salesHistory to be the same as the salesTable's salesId.

How can I do that in one transaction, so that the salesHistory's saleId can get the generated id from the salesTable?

thx so much,
George


Top
 Profile  
 
 Post subject: Re - foreign key issue in one transaction, please help
PostPosted: Wed Jul 16, 2008 11:27 am 
Newbie

Joined: Sun May 18, 2008 1:21 pm
Posts: 13
George

There are two ways to do this.

1. First get the newly generated SalesId its basically by OutParamenter or Identity. and now you have both CustomerId and Salesid for your Sales HIstory table.


2. Database Triggers.

Create a Trigger which fires on Insert of ever new record of first table and in that tirgger you can get CustomerId , newly generated salesId and can easily post it to SalesHistory Table.

_________________
Zafar Ullah

Lead/Architect
www.lmkr.com
www.apextechnologies.ca
Blog
http://barchitect.blogspot.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.