How to restart counting from 1 after erasing table in MS Access?

前端 未结 6 2089
栀梦
栀梦 2020-11-27 04:39

I have table in MS Access that has an AutoNumber type in field ID

After inserting some rows, the ID has become 200

6条回答
  •  感情败类
    2020-11-27 05:13

    I am going to Necro this topic.

    Starting around ms-access-2016, you can execute Data Definition Queries (DDQ) through Macro's

    Data Definition Query


    ALTER TABLE  ALTER COLUMN  COUNTER(1,1);
    
    
    
    1. Save the DDQ, with your values
    2. Create a Macro with the appropriate logic either before this or after.
    3. To execute this DDQ:
      • Add an Open Query action
      • Define the name of the DDQ in the Query Name field; View and Data Mode settings are not relevant and can leave the default values

    WARNINGS!!!!

    1. This will reset the AutoNumber Counter to 1
    2. Any Referential Integrity will be summarily destroyed

    Advice

    • Use this for Staging tables
      • these are tables that are never intended to persist the data they temporarily contain.
      • The data contained is only there until additional cleaning actions have been performed and stored in the appropriate table(s).
      • Once cleaning operations have been performed and the data is no longer needed, these tables are summarily purged of any data contained.
    • Import Tables
      • These are very similar to Staging Tables but tend to only have two columns: ID and RowValue
      • Since these are typically used to import RAW data from a general file format (TXT, RTF, CSV, XML, etc.), the data contained does not persist past the processing lifecycle

    提交回复
    热议问题