tags:

views:

28

answers:

1

I would like to write a program like sales in which there's two table to insert i.e: SaleHeader Table and SaleDetails Table. These two tables have (one to many) relationship. When I insert to SaleDetails Table I need to get SaleHeaderID to insert at SaleDetails.

Now I am using storeprocedure to insert SaleHeader information and to get back SaleHeaderID and I use query statements to insert SaleDetail information.

Any one can advise me for more effective way to insert to those two tables (having one to many relationship) ? Help me! Thanks in advance all.

+1  A: 

One approach is to use a Guid for the SaleHeaderID. Then you can generate the new id in your stored procedure (using NEWID()) before inserting the header record, and then you will also know the id so you can use it for the details.

Fredrik Mörk
How about using SELECT IDENTITY() , because my SaleHeaderID is bigint Type? I would like to know is the other approach besides using stored procedure for SaleHeader Table
RedsDevils