generate random student id in asp.net

  • Thread starter Thread starter Hmmm
  • Start date Start date
H

Hmmm

I'm developing a student management app and need to generate a random
8-digit student id.

What's the best approach to ensure uniqueness and yet not take so much
computing time?

thanks!
 
there's no intelligence to the number but it must be unique

i guess it's randomly generated but it must be unique in the database

OR

would one approach be to create a starting number in a table and just
increment it everytime I add a new student?
 
if it must be unique in the database, then use the database to generate it.

use a table with a int column specified as an identity field - e.g. some
kind of record_id. do your insert into the table and immediately pull the
@@IDENTITY.
e.g.
declare @myvar int
insert mytable (fname,lname) values ('joe','blow')
select @myvar = @@IDENTITY
 
Back
Top