is there TRUNCATE in Access?

后端 未结 9 1469
滥情空心
滥情空心 2021-01-04 03:19

I have a table in an Access database with an autonumber field.

When I delete all the records from the table, the autonumber remembers the last number.

Does A

9条回答
  •  隐瞒了意图╮
    2021-01-04 03:27

    Access SQL does not have anything like TRUNCATE TABLE.

    You can use an ADO connection to execute a DDL statement which resets the autonumber field's "seed" value. So you could do this with VBA code, and not have to use compact & repair to reset the autonumber.

    This example code first deletes all rows from my tblFoo table, and then resets the seed value for the id autonumber field.

    Dim strSql As String
    strSql = "DELETE FROM tblFoo;"
    CurrentProject.Connection.Execute strSql
    strSql = "ALTER TABLE tblFoo ALTER COLUMN id COUNTER (1, 1);"
    CurrentProject.Connection.Execute strSql
    

提交回复
热议问题