What is the DDL to rename a column in MS Access? Something along the lines of:
alter table myTable rename col1 to col2
which does not work for MSAccess 2000 format databases. I'm using OLEDB or ADO.NET with a MSAccess 2000 format db but would be grateful of any hint at the syntax or a suggestion as to how to achieve this using ADO.NET in some other way.
To rename a field in a table in Access, open the table containing the field to rename in design view. Then click into the “Field Name” column of the field that to rename and type a new name. Then click the “Save” button in the Quick Access toolbar to save your structural modifications.
Rename: RENAME command is used to change the name of the table or a database object. RENAME old_table_name To new_table_name; Example: Rename testable to test_table; Below is the screenshot for renaming the table from testtable to test_table.
You select the table with ALTER TABLE table_name and then write which column to rename and what to rename it to with RENAME COLUMN old_name TO new_name .
Rename a column using table designer. In Object Explorer, right-click the table to which you want to rename columns and choose Design. Under Column Name, select the name you want to change and type a new one. On the File menu, select Save table name.
I do not believe you can do this, other than by appending a new column, updating from the existing column and then deleting the 'old' column.
It is, however, quite simple in VBA:
Set db = CurrentDb
Set fld = db.TableDefs("Table1").Fields("Field1")
fld.Name = "NewName"
I am at home and can't test this at the moment, but I think this should work. This site has information about it.
ALTER TABLE thetable ALTER COLUMN fieldname fieldtype
Edit I tested this a bit and oddly enough, you can't rename a column that I can find. The ALTER COLUMN
syntax only allows for changing type. Using SQL, it seems to be necessary to drop the column and then add it back in. I suppose the data could be saved in a temporary table.
alter table test drop column i;
alter table test add column j integer;
My solution, simple but effective:
Dim tbl as tabledef
set tbl = currentdb.TableDefs("myTable")
tbl.fields("OldName").name = "Newname"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With