Rename mdb table

StewartBW 1,145 Reputation points
2024-05-29T04:01:30.4533333+00:00

Hello

I use Access Database Engine and OleDbReader to work with mdb and accdb files, need to rename a table:

ALTER TABLE <table name> RENAME TO <new table name>

OleDbException, anyway using ADE?

Thanks

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,995 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,732 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 31,976 Reputation points Microsoft Vendor
    2024-05-29T05:36:29.5066667+00:00

    Hi @StewartBW ,

    Access does not support the RENAME TABLE SQL command.

    You can work around this limitation by using a combination of SQL statements to create a new table, copy the data from the old table, and then drop the old table.

    1. Use SELECT * INTO {newTableName} FROM {oldTableName} WHERE 1 = 0 statement to create a new table with the same structure as the old table but without copying any data.
    2. Use INSERT INTO {newTableName} SELECT * FROM {oldTableName} statement to copy all data from the old table to the new table.
    3. Use DROP TABLE {oldTableName} statement to remove the old table from the database.

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.