Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL SQL-Server
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 13-Nov-12 18:12pm
Comments
Shanalal Kasim at 14-Nov-12 0:18am
   
RefNumber is Student Table column?
Which table count your taking?
Maria Vinod Bheemisetty at 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 at 14-Nov-12 0:44am
   
You can set RefNumber as Auincremented rather than count of records +1
__TR__ at 14-Nov-12 0:52am
   
You can use the IDENTITY Property[^] to auto generate numbers.

1 solution

Rate this: bad
good
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))
 
Or
 
Set Identity
 
Refer: http://msdn.microsoft.com/en-us/library/aa933196(v=sql.80).aspx[^]
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 364
1 Nirav Prabtani 268
2 _Amy 185
3 CHill60 170
4 Sergey Alexandrovich Kryukov 166
0 OriginalGriff 8,004
1 Sergey Alexandrovich Kryukov 7,017
2 Maciej Los 4,039
3 Peter Leow 3,738
4 CHill60 2,912


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2014
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