Generally, I can think of two ways to genereate this type of primary key.
One is using database auto counter, this will depending on database.

Another way is your keep tracking the latest number in the database,
everytime when you need a new key, get that number and increase it by one or
multiple in one transaction.   The second approach is requires more database
work, and if there is a lot of insert, you might want to consider the
performance issue.

 

 

Leon

 

  _____  

From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of Jon Liu
Sent: Tuesday, November 18, 2008 10:23 AM
To: [email protected]
Subject: [DotNetDevelopment] Re: Auto-generating a primary key

 


Right, primary key values are unique.  So what I am saying is I want to auto
generate the Id like a counter.  Example, when I insert an entry, I'd like
it to generate EntryId=1, then on the next insertion, EntryId=2, then
EntryId=3 so on and so forth...



On Tue, Nov 18, 2008 at 7:19 AM, KeidrickP <[EMAIL PROTECTED]> wrote:


I don't understand your question.
A primary key should be a unique identifier for a record in your table.
What info is your weblog app tracking?


On Tue, Nov 18, 2008 at 9:12 AM, Jon Liu <[EMAIL PROTECTED]> wrote:
> i want to generate an alphnumeric value for the primary key "EntryId" for
a
> webblog app I'm building.  If not "BigJ1", how would you go about just
> generating an incremental numeric Id for EntryId?
>
> On Tue, Nov 18, 2008 at 7:00 AM, KeidrickP <[EMAIL PROTECTED]> wrote:
>>
>> I agree with Stephen. What exactly are you trying to accomplish?
>>
>> On Tue, Nov 18, 2008 at 7:18 AM, Stephen Russell <[EMAIL PROTECTED]>
>> wrote:
>> >
>> > Please don't do this.  An ID should be not only unique, but have NO
>> > VALUE.
>> > You are imparting value as "BigJ" and that is very wrong.  Appending
the
>> > #
>> > 1,2,3 does not make it correct.
>> >
>> >
>> > .........................
>> > Stephen Russell -
>> > Senior Visual Studio Developer, DBA
>> >
>> > Memphis, TN
>> > 901.246-0159
>> >
>> >
>> >
>> > -----Original Message-----
>> > From: [email protected]
>> > [mailto:[EMAIL PROTECTED] On Behalf Of BigJ
>> > Sent: Monday, November 17, 2008 10:51 PM
>> > To: DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web
>> > Services,.NET Remoting
>> > Subject: [DotNetDevelopment] Auto-generating a primary key
>> >
>> >
>> > I see a formula section, but not sure how to go about it.  I basically
>> > have an primary key called "EntryId" and I want to consist of  UserId
>> > +unique counter, so if UserId="BigJ", and it's my first entry, then
>> > EntryId="BigJ1" and the next entry would be BigJ2 etc....any insight
>> > as to how to accomplish this? I know there is a formula field and I am
>> > looking into it, but any insight or simple examples are apreciated, as
>> > I left my SQL book at home lol...Thanks...
>> >
>> > No virus found in this incoming message.
>> > Checked by AVG - http://www.avg.com
>> > Version: 8.0.175 / Virus Database: 270.9.4/1790 - Release Date:
>> > 11/17/2008
>> > 8:48 AM
>> >
>> >
>> >
>
>

 

Reply via email to