Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
i am using sql server 2008 for the database. i have to increment index manually whenever record is inserted or updated in table.for this first i search for the index from the table using select after this increment it by 1 and update the record in the table,so i have doubt that when more then 10 pc are connected via LAN or WAN at that time for updating or inserting record this will be work or not ? any other way to do this ?
Posted 12-Nov-12 22:27pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can set an automatic increment: Look at the column definition and find the property "Identity Specification"
Expand it, and set "(Is Identity)" to "Yes"
  Permalink  
Comments
Jigar Sangoi at 13-Nov-12 4:40am
   
but problem is that i have to count total record inserted or updated for each day so for the next day it starts from previous index not from 0
Jigar Sangoi at 13-Nov-12 4:43am
   
also this has to be done when record is accepted
OriginalGriff at 13-Nov-12 4:55am
   
:laugh:
You have to tell people these things!
There is no automatic way to do that, the best thing I can suggest is that you use a stored procedure as this will be performed at the server, and should not be interruptible unlike a "select...check...write" operation which as you rightly suspect will be subject to intermittent problems in a multiuser environment.
 
Personally, I would try to avoid this: I would be tempted to look at generating it "on the fly" by storing the insert date and time stamp and working it out on a daily basis from that if it was possible.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can use IDENTITY [ ( seed , increment ) ] Property
 
Refer: IDENTITY (Property)[^]
  Permalink  
Comments
Jigar Sangoi at 13-Nov-12 4:45am
   
but problem is that i have to count total record inserted or updated for each day so for the next day it starts from previous index not from 0,also this has to be done when record is accepted
Shanalal Kasim at 13-Nov-12 4:52am
   
so you want, every day index start with zero?

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

  Print Answers RSS
0 Kornfeld Eliyahu Peter 275
1 Maciej Los 214
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 163
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 13 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