Rename mdb table

StewartBW 1,805 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

Developer technologies VB
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    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.

    2 people 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.