Access中有TRUNCATE吗? [英] is there TRUNCATE in Access?

查看:87
本文介绍了Access中有TRUNCATE吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Access数据库中有一个带有自动编号字段的表.

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.

Access是否与SQL Server的TRUNCATE TABLE MyTbl类似?

Does Access have something similar to SQL Server's TRUNCATE TABLE MyTbl?

如果没有,在删除表的记录后如何从1开始?

If not, how to start with 1 after I delete the table's records?

推荐答案

Access SQL没有类似TRUNCATE TABLE的东西.

Access SQL does not have anything like TRUNCATE TABLE.

您可以使用ADO连接执行DDL语句,该语句将重置自动编号字段的"seed" 值.因此,您可以使用VBA代码执行此操作,而不必使用紧凑的&修复以重置自动编号.

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.

此示例代码首先从我的 tblFoo 表中删除所有行,然后为 id 自动编号字段重置种子值.

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

这篇关于Access中有TRUNCATE吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆