Re: Generating unique ID's automatically?
Posted in 1997
Yes! You can use stored procedurs and database triggers to accomplish this, provided of couse your database supports these features. Write your code & save it on the database side as a stored procedure & set a trigger to activate this code when, say an INSERT is performed. Good luck. Chaminda Peries On 13 Mar 1997, Ofer Inbar wrote: } Is there any way, other than using the SERIAL type, to have unique IDs } generated automatically? Say, for example, I create a procedure like: } } create nextID example() returning int; } define retUserID int; } select max( userID ) into retUserID from User; } return retUserID; } end procedure; } } ... can I somehow attach this procedure to the UserID field of the } User table, such that when someone enters a new row of values for the } User table and leaves out the ID, it'll be automatically generated? } } If not, is there another way? } } -- Cos (Ofer Inbar) -- cos@leftbank.com cos@cs.brandeis.edu } -- The Left Bank Operation -- lbo@leftbank.com http://www.leftbank.com/ } "Good literature is about Love and War." } "Junk fiction is about Sex and Violence." }