J.J.Baxter - My place on the web - interests, hobbies, thoughts & ruminations
Home / Blog
Books
Links
Images
Aug Sep-2010 Oct
SMTWTFS
2930311234
567891011
12131415161718
19202122232425
262728293012
3 4 5 6 7 8 9
Reset Calendar
Snorg Girls
Programming Tips
Sherlock Holmes
Mythbusters
Gallipoli
Nova Science Now
Ajax Loading Images
The Girls of Dr. Who
Keratosis Pilaris (KP)
Amazing Water
Buy me a drink? I'll have a Cappuccino, thanks.
Random Images
Random Link
Wrecked Exotic Cars
Random Book
Gullivers Travels
by Jonathan Swift






All Rights Reserved 2008
JJBaxter.com

J.J.Baxters Development Tips & Snippets
backBack
 Start an IDENTITY field at a chosen number (SQL : 05-Jul-2007)
I needed to start an IDENTITY field at a set value. Took a bit of searching but this does the trick - ASP code

'Create the table
sSQL = "CREATE TABLE certificates ( " & _
          "cert_id INT IDENTITY (1,1) NOT NULL," & _
          "user_id INT DEFAULT 0 NOT NULL," & _
          "cert_type VARCHAR(15) DEFAULT '' NOT NULL," & _
          "cert_type_id VARCHAR(15) DEFAULT '' NOT NULL," & _
          "industry VARCHAR(15) DEFAULT '' NOT NULL," & _
          "date_first_print DATETIME DEFAULT '1900-01-01 00:00:00' NOT NULL," & _
          "date_last_print DATETIME DEFAULT '1900-01-01 00:00:00' NOT NULL," & _
          "date_cert_issued DATETIME DEFAULT '1900-01-01 00:00:00' NOT NULL)" & _
oCon.execute(sSQL)
' turn on identity insert
oCon.execute("SET IDENTITY_INSERT certificates ON")
' insert my starting value -1 - I want to start at 10000
oCon.execute("INSERT INTO certificates (cert_id) VALUES (9999)")
' turn off identity insert
oCon.execute("SET IDENTITY_INSERT certificates OFF")
' now delete my seed record
oCon.execute("DELETE FROM certificates")
' the next record to be inserted will have an identity of 10000!


Easy, when you know how.
Ref Link: http://msdn2.microsoft.com/En-US/library/aa259221(SQL.80).aspx