Click here to Skip to main content
15,884,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear

All,

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
Comments
Shanalal Kasim 14-Nov-12 0:18am    
RefNumber is Student Table column?
Which table count your taking?
Maria Vinod 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.
SoumenBanerjee 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

In change your sql like below

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


Or

Set Identity

Refer: http://msdn.microsoft.com/en-us/library/aa933196(v=sql.80).aspx[^]
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900