I am creating an asp.net site where a user submits some data which is inserted into table 1, and then I run a query to grab the ID of the entry that was then created from table 1 and then insert that ID into table 2. The issue is that if someone just happens to submit at the same time I could easily end up with incorrect data. I assume it is possible to lock table 1 until the data has been inserted into the table 2, but I am unsure how to do it. Can anyone provide some guidance? All my code is in a C# Code Behind file. I read that you could do it with something like the below, but if that works, how is it unlocked?
UPDATE table1 WITH (rowlock)