I am working on e-commerce
application, I have three tables in DB
- Customer
- Order
- Order Details
Order Details
information about individual products and OrderId
that is primary key of Order
and I have 2 Stored Procedures
- InsertIntoOrderAndCustomer
- InsertIntoOrderDetails
as InsertIntoOrderAndCustomer
is called from ADO.Net
it will generate autoid
OrderId
in Order
and I need to use that id in as a parameter to InsertIntoOrderDetails
but I am worried if multiple orders are being placed then parameter value may be wrong. Can I lock C#
code so that only one order will be placed at a time? If yes, then how?
I am worried about
2 Persons placing order
Execution could be,
Person A places order
- Insert data into Orders table for Person A - It will generate id automatically
IDENTITY
(of course only once).
Mean while Person B places order then
- Insert data into Orders table for Person B - It will generate id automatically
IDENTITY
(different one).
then insert data into product details
table with AutoId IDENTITY
in Orders table.
While inserting into product details
I am getting auto id using MAX
of SQL Server
and this will give me 101, as in above scenario.
Is there possibility that second insert put IDENTITY
of Order
of Person B (i.e 101) and other data of Person A
? it worries me.