3

Possible Duplicate:
how to start counting from 1 after erase table in access ?

Hi all

What will be the query to reset auti_increment field in MS Access Database?

Community
  • 1
  • 1
Yugal
  • 1,635
  • 8
  • 21
  • 30

2 Answers2

8

You need to run "Compact and Repair Database"

Robert
  • 3,328
  • 2
  • 24
  • 25
2

You can find this information easily using Google, here's a link to the MS support article which describes the process:

How to reset an AutoNumber field value in Access

I haven't reproduced the info here as it's lengthy. There does not appear to be a magic, single, command to reset the counter.

Tony
  • 9,672
  • 3
  • 47
  • 75
  • How can we do this via using OleDb codes? –  Sep 20 '12 at 11:12
  • @HabipOĞUZ - You might do better to post a new question, linking to this, for a better answer. Where are you executing the OLE functions (VBA, .net code, somthing else)? Why do you need to do this at all? (see the comments in this question: http://stackoverflow.com/questions/4416619/how-to-start-counting-from-1-after-erase-table-in-access) and what have you tried? I Googled for a solution and found some info for a PowerShell script which uses OLE DB commands, you might be able to modify that: http://msmvps.com/blogs/richardsiddaway/archive/2010/01/04/change-autonumber-start.aspx – Tony Sep 20 '12 at 14:06
  • Thank you very much for your response. I didn't want to make the crowd with a new question. I am executing the OLE functions in .Net. I'm programming an annotation of the Turkish Criminal Code. It is a small project. It uses MS Access database named "data.accdb" in the program. Especially, while coding, when i removed all rows in the articles table, i wanted to set auto_increment column's value as 1. Shortly, in my test screen, i want to design a button, when i clicked the button, all rows in the articles table are deleted and auto_increment column's value is set 1. Sincerely yours. –  Sep 23 '12 at 13:31
  • But why does it matter what the ID field value is? Let the number grow while you are developing your application and if you want it reset when you release the first version you can create a new database from your model. You are going to have to deal with numbers not starting from 1 as soon as you perform your first upgrade, you will not be able to reset the counter at that time. – Tony Sep 23 '12 at 14:08
  • It does not matter. I coded a db class for operating Access db. It has methods like dbInsert(), dbUpdate(), dbFetchAll(), dbDelete() etc. I wanted to code a method named dbTruncate() like MySQL. Because my first programming experience is on PHP & MySQL. It is only curiosity. :) –  Sep 27 '12 at 07:07