Truncate Table in MS Access 2007

jack123

New member
Local time
Today, 20:30
Joined
Jun 22, 2009
Messages
7
Hi All,

I am developing Windows Application using C#.net with MS ACCESS 2007 as my Database. During Development I have entered so many records in my database.I am having tables with datatype as AutoNumber..

Now my requirement is I want truncate tables I mean I want to delete all records and reset autonumber values..

In sql server database, Truncate keyword is there to truncate the tables...

But in MS Access I could not find this keyword...

So, Please any one tell me how to truncate tables in MS ACCESS 2007..

Thanks in advance..
 
In Access you would need to execute a delete query:

Delete * FROM YourTableName

and then to compact you can use a variation of this code (not sure what it would be in .NET but you use the DAO.DbEngine.
Code:
Public Function CompactDb()
Dim strDbNameOld As String
Dim strDBNameNew As String

strDbNameOld = "YourPathAndNameToTheFileYouWantToCompact"

        DBEngine.CompactDatabase strDBNameOld, strDBNameNew
        Kill strDBNameOld
        Name strDBNameNew As strDBNameOld
End Function
 

Users who are viewing this thread

Back
Top Bottom