On 11/11/01, Douglas L. Brown penned:
>I am kinda new to SQL and such and have the following question
>
>I have a table called (customer) which has a custNum column and is a PK
>it has a FK relationship to a table called cust_contacts and a column of
>custNum. when a user creates an account I generate a custNum and
>populate the cust_contacts table but I get a key constraint error
>because this table is a FK and not the PK..Should the table that holds
>the login information be the PK table?

The customer table must be populated first. Two ways to go about 
generating the custNum.

1. Identity field (SQL, Autnumber in Access) for custNum in customer. 
Insert new customer then grab the max(custNum) and insert it into the 
cust_contacts table along with any other info that goes in there.

2. Integer field for custNum in customer. You'll need to get the 
max(custNum) BEFORE inserting the record, add 1 and insert the new 
record with that value. Then insert the same new number into 
cust_contacts.

You should wrap either of these with a cftransaction to assure that 
the proper max(custNum) is written to the correct cust_contacts 
record in case two users are signing up simultaneously.
-- 

Bud Schneehagen - Tropical Web Creations

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ColdFusion Solutions / eCommerce Development
[EMAIL PROTECTED]
http://www.twcreations.com/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to