Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using AutoNumber/Identity Increment or Generating It Using Procedure

Status
Not open for further replies.

Adhie

Programmer
Mar 17, 2003
28
SG
Hi,

In SQL Server, one of the field, we set ID as primary key of the table. To make sure that field is unique there are 2 ways that I can approach:
(1) Set Identity as Yes, Identity Seed and Identity Increment as well, so we call it as Autonumber (same case in Access DB).
(2) We create a function to produce unique Id:

'---- Auto Number Increment ----
Function AutoNumInc(TableName, IncRec)
Set RSAutoNumInc = Server.CreateObject("ADODB.Recordset")
RSAutoNumInc.Open "SELECT Max("& IncRec &") AS MaxRec FROM "& TableName, Conn,3, 1, 0
If isNull(RSAutoNumInc("MaxRec")) Then
AutoNumInc = 1
Else
AutoNumInc = CInt(RSAutoNumInc("MaxRec")) + 1
End If
RSAutoNumInc.Close
Set RSAutoNumInc = Nothing
End Function


Which one you think is the best way if we're going to create centralize database?

Thanks you,
Martin
[2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top