How to Sort this, Get Next Record ID when Many users inserting and different Districts
-
Rec_ID Rec_Name Dist_ID 1 A 1 2 B 1 1 AA 2 2 AB 2 3 C 2 How can i write a Insert sql script for this table, eg: i should insert Rec_ID 3 while inserting Record for Dist_ID 1 and also Rec_ID 4 for Dist_ID 2, Suppose if many users inserting from different places, how to handle this situation. what is the best method? I have following 2 ideas, which is right idea or is there any other method to implement this 1) Select Max(Rec_ID) for the district, suppose if 2 people inserting at the same time will be a issue. 2) Put a Lock in the Stored Procedure
-
Rec_ID Rec_Name Dist_ID 1 A 1 2 B 1 1 AA 2 2 AB 2 3 C 2 How can i write a Insert sql script for this table, eg: i should insert Rec_ID 3 while inserting Record for Dist_ID 1 and also Rec_ID 4 for Dist_ID 2, Suppose if many users inserting from different places, how to handle this situation. what is the best method? I have following 2 ideas, which is right idea or is there any other method to implement this 1) Select Max(Rec_ID) for the district, suppose if 2 people inserting at the same time will be a issue. 2) Put a Lock in the Stored Procedure
-
-
I Cannot set it as Identity column, because based on the District ID should get the Next Rec_ID
In which case I do not understand what you are trying to do. Can you specify exactly what you need with a before and after example - thanks.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
-
Rec_ID Rec_Name Dist_ID 1 A 1 2 B 1 1 AA 2 2 AB 2 3 C 2 How can i write a Insert sql script for this table, eg: i should insert Rec_ID 3 while inserting Record for Dist_ID 1 and also Rec_ID 4 for Dist_ID 2, Suppose if many users inserting from different places, how to handle this situation. what is the best method? I have following 2 ideas, which is right idea or is there any other method to implement this 1) Select Max(Rec_ID) for the district, suppose if 2 people inserting at the same time will be a issue. 2) Put a Lock in the Stored Procedure
Wrong order. Insert the records in the dependent tables first, and get their identity. Then insert the REC using the identities you fetched. Inserting data in multiple tables, appearing as a single atomic operation would require a "transaction".
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
I Cannot set it as Identity column, because based on the District ID should get the Next Rec_ID
-
Rec_ID Rec_Name Dist_ID 1 A 1 2 B 1 1 AA 2 2 AB 2 3 C 2 How can i write a Insert sql script for this table, eg: i should insert Rec_ID 3 while inserting Record for Dist_ID 1 and also Rec_ID 4 for Dist_ID 2, Suppose if many users inserting from different places, how to handle this situation. what is the best method? I have following 2 ideas, which is right idea or is there any other method to implement this 1) Select Max(Rec_ID) for the district, suppose if 2 people inserting at the same time will be a issue. 2) Put a Lock in the Stored Procedure
And if the workload isn't too heavy you could use a Web Service (WCF or similar) to provide a single access point so the clients don't actually touch the database. The service could then perform the actions one-by-one.
You'll never get very far if all you do is follow instructions.