Skip to main content
Inspiring
June 17, 2010
Question

How to set identity to the 1st record in cfquery

  • June 17, 2010
  • 2 replies
  • 648 views

Hi,

I need help with setting the identity to always start with 1 when new records are inserted.

My application is inserting records to Table A then at the end, all records in Table A are deleted.

When the next time this app. is ran, Table A is re-populated again and for certain reason the inserted record need to always start from 1.

The identity is set to automatic so I'm trying to find a way if I can reset the identity column before start inserting new records.

Is this doable?

This is not working:

<cfquery name="getRecs" datasource="myrec">

'identity', ', 0, '0'  //reset identity???

INSERT INTO Table

Select a,s,c from tableB where a='a'

</cfquery>

This topic has been closed for replies.

2 replies

Inspiring
June 18, 2010

assuming your db is sql server (it helps if you id your database when you ask

for help):

DBCC CHECKIDENT('tableA',RESEED,0)

0 because the db will +1 for the next INSERT.

Inspiring
June 17, 2010

Change the identity column so it's not automatic.

use select count(*) +1 from thetable as the identifier for new records.