1

I have an Access database with almost 200 tables. I would like to rename the fields of many of these (to make it easier when I analyze the data in R). I've discovered that you can't simply rename fields in Access, but have to do it the hard way of adding a new column, transferring data, then dropping the old column.

Is there a way to do this for multiple tables (or multiple tables and columns) at once using SQL?

I tried this:

ALTER TABLE * FROM MSysObjects ADD COLUMN colname NUMBER

as well as this:

ALTER TABLE table1, table2, table3... ADD COLUMN colname NUMBER

but neither seem to work.

Is this possible at all? Does anyone know how to code this?

1 Answer 1

2

"Is there a way to do this for multiple tables (or multiple tables and columns) at once using SQL?"

No. That is beyond the capability of Access SQL. You will need to execute a series of statements, and each can only alter a single table.

You could create a VBA procedure to build and execute those statements. But, if you're willing to use VBA, consider simply renaming the columns via the DAO object model.

Here is a simple example from the Immediate window:

? CurrentDb.TableDefs("tblFoo").Fields("some_text").Name
some_text
CurrentDb.TableDefs("tblFoo").Fields("some_text").Name = "some_text2"
? CurrentDb.TableDefs("tblFoo").Fields("some_text2").Name
some_text2
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, Hans. Is it possible to do what I want in an actual SQL program (e.g. MySQL, SQLite)?
Perhaps, but I can't offer any help for those.
@Paul re: "Is it possible to do what I want in [some other database]?" - Generally speaking, no. At least I'm not aware of any databases that offer a "global update" feature to change the structure of database objects. (By the way, remember that you can accept an answer if you find it helpful. Accepted answers help others recognize that your question has been resolved.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.