Click here to Skip to main content
13,048,035 members (96,323 online)
Rate this:
Please Sign up or sign in to vote.
See more:


I am going to insert one record into the database (ex: table name : Student) by using a web application, here when am going to insert i will generate one RefNumber basing on the count of records +1 in that table and this RefNumber also inserted into the Student table. Fine, Here my problem is when two users accessing the same table going to insert a record into the Student table that RefNumber is missing to generate. So the problem is Same RefNumber is allocated to the two Students. Please let me know, how to handle two users accesing same table at same time.

I hope you all understand my problem. If anybody have an idea about this kind of issue let me know, it may helpful to me.

In Advance

Thanks and Regards,

Maria Vinod Bheemisetty
Posted 13-Nov-12 18:12pm
Shanalal Kasim 14-Nov-12 0:18am
RefNumber is Student Table column?
Which table count your taking?
Maria Vinod Bheemisetty 14-Nov-12 0:36am
Yes, RefNumber is also one of the column of "Student" table, am getting the count of the same table +1 as RefNumber and inserting this RefNumber updating in the same table.
Soumen_Banerjee 14-Nov-12 0:44am
You can set RefNumber as Auincremented rather than count of records +1
__TR__ 14-Nov-12 0:52am
You can use the IDENTITY Property[^] to auto generate numbers.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In change your sql like below

Insert into student (RefNumber ) values ((Select count(RefNumber)+1 from student))


Set Identity


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100