Recent

Author Topic: MS SQL Server - how to reseed an Identity field counter  (Read 3342 times)

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
MS SQL Server - how to reseed an Identity field counter
« on: September 02, 2014, 11:20:45 am »
I'm working with an existing MS SQL Server database. The database uses Identity type fields for the primary keys.

I've written an app that imports data from a CSV file, but I need to reseed the primary key field to 0 when importing the data. Has anybody reseeded such a field type via SqlDB? Is it possible?

Anybody know if I can execute something like the following via SqlDB:
 
Code: [Select]
DBCC CheckIdent(<tablename>, RESEED, 0)
Alternatively, what about the ability to run this:
 
Code: [Select]
set identity_insert <table> on|offso I can populate the identity field with my own auto-increment number?

I would prefer the RESEED option, but either one would do really.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: MS SQL Server - how to reseed an Identity field counter
« Reply #1 on: September 02, 2014, 11:41:10 am »
IT would help if you told us which version of mssql you are using in mean time try executing the command
Code: [Select]
DBCC CHECKIDENT (mytable, RESEED, 0) where 0 (last parameter) is the last used number the next insert will have the value 0+1. Also check with online help to see if that requires SA access.
« Last Edit: September 02, 2014, 12:04:47 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: MS SQL Server - how to reseed an Identity field counter
« Reply #2 on: September 02, 2014, 12:46:20 pm »
Thanks Taazz. I'm using SQL Server 2004 up to SQL Server 2012.

For some reason I didn't think the DBCC commands was allowed outside of Microsoft SQL Server Management Studio, but it works perfectly via SqlDB.

My problem is now solved. :-)
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

KanVee04

  • Newbie
  • Posts: 1
WYSIWYG Editor
« Reply #3 on: September 02, 2014, 12:48:32 pm »
I am new pascal. Could please tell how to create a WYSIWYG Editor using pascal script.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: MS SQL Server - how to reseed an Identity field counter
« Reply #4 on: September 08, 2014, 10:08:41 pm »
Don't reply to an existing thread and change the subject line - nobody will see your question. Create a new topic in a relevant forum instead.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

 

TinyPortal © 2005-2018