Hi Phani, What is the point of generating a unique integer separate from the (unique) integer primary key?
If you use the primary key as your unique identifier, sqlite will take care of locating unused (deleted) ids when the maximum value is reached (according to the documentation; I have not tried it) Rgds, Simon On 30/08/2007, B V, Phanisekhar <[EMAIL PROTECTED]> wrote: > Sreedhar, > > I think u didn't read my mail properly. I want to generate unique id for > puid not for id (which is the PRIMARY KEY). Anyone knows how to generate > a undique ID for a column which is not PRIMARY KEY? Also, whenever I > reach the limit (max value), I should be able to use the values of > deleted rows. > > Regards, > Phani > > -----Original Message----- > From: Sreedhar.a [mailto:[EMAIL PROTECTED] > Sent: Thursday, August 30, 2007 2:22 PM > To: sqlite-users@sqlite.org > Subject: RE: [sqlite] How to generate Unique ID? > > Phani, > > Read the "auto increment" in Sqlite FAQ s it is the first one in the > list, > it will solve your problem. > > > Best Regards, > A.Sreedhar. > > -----Original Message----- > From: B V, Phanisekhar [mailto:[EMAIL PROTECTED] > Sent: Thursday, August 30, 2007 2:11 PM > To: sqlite-users@sqlite.org > Subject: [sqlite] How to generate Unique ID? > > Assume I have a table: > > Create table YYY (id Interger PRIMARY KEY, puid Unique integer) > > Id is the primary key. > > Puid is an unsque interger, whose values needs to be assigned by the > user. > > > > Currently my approach is get the maximum value of puid stored in the > table; > add 1 to it and uses this value as puid for any new row that needs to be > added. The problem occurs when I reach the max value. > Meanwhile, some rows might have been deleted. In case, when I reach the > maximum value I want to reuse the puids of the deleted rows for new rows > that are to be added. Currently SQLite uses some algorithm to generate a > unique rowid (even when it reaches the limit). I want to use the same > algorithm here also. I tried to understand the algorithm but couldn't. I > need a simple way by which I can generate a unique puid without writing > the > algorithm. > > > > > > Regards, > > Phani > > > > > > > > > ------------------------------------------------------------------------ > ----- > To unsubscribe, send email to [EMAIL PROTECTED] > ------------------------------------------------------------------------ > ----- > > > ----------------------------------------------------------------------------- > To unsubscribe, send email to [EMAIL PROTECTED] > ----------------------------------------------------------------------------- > > ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------