I have created a web form with the following values
- first name
- last name
- address line 1
- address line 2
- city
- state
- contact1
- contact2
- email id
- password
- confirm password…
Upon clicking the submit button, a stored procedure savedata is invoked.
The fields name, address and contacts are saved into table personal_details, while email and password are stored into login_detail.
The table personal_details has columns user_id int identity(1,1) pk…
Same user_id int identity(1,1) fk is defined in login_detail table…
Now, is it possible that 2 users 1 and 2 submit the form at the same time and user1’s personal details get pushed in table and then user2’s personal details get pushed.
Generating id as 1 and 2 respectively…
but for login details user2 data get pushed first then user1…generating ids 1 and 2… which are wrong….
Is there any other method to get the same ids for both the tables?
thanks
And this is my first question…sorry if I am not able to frame it properly…
You should perform the following sequence of steps in a single transaction to ensure the atomicity of this save operation:
personal_detailstable.login_detailstable with the user_id as the one obtained in the previous step.Also, it doesn’t seem appropriate to “vertically partition” the details of a user across two tables when there is a one-to-one correspondence between records in these two tables. You could just have a single table unless there are attributes of a user that carry multiple values for a single user id i.e. one-to-many relationship.