Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Identity

Author  Topic 

bob_carter
Starting Member

3 Posts

Posted - 2007-05-01 : 10:45:47
Hi,

My Question is, Ihave two table CustomersName and CustomerProducts.
in CustomersName i have 2 fields Cust_ID ,Names and in customerProducts i have 4 fields Product_ID,ProductName,Cust_ID.

I want know that How to use in Second table that Identity values is Genrated Automaticaly in First table.

Thanks in Advance

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-05-01 : 11:54:43
You need to manually get the ID of the row that you do an INSERT into via SCOPE_IDENTITY function and use it to INSERT into the other table.

Declare @CustID Int
INSERT INTO CustomersName (...)
VALUES (....)
SELECT @CustId = SCOPE_IDENTITY()
INSERT INTO CustomerProducts ( , Cust_Id)
VALUES (...., @CustId)


Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -