Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to set identity to the 1st record in cfquery

Participant ,
Jun 17, 2010 Jun 17, 2010

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>

TOPICS
Getting started
595
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2010 Jun 17, 2010

Change the identity column so it's not automatic.

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 17, 2010 Jun 17, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources