473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Change column name?

JustJim
407 Expert 256MB
Hi

If all you can do with ALTER TABLE....ALTER COLUMN is change the datatype/size then how do I change the name of a field?

I have several database files spread all over the state and some of the users (Darn users!) have changed a field from "Datum" to "MapDatum" and I need to change it back because it is causing problems with the front end.

I suspect that I'm going to have to determine if the field MapDatum exists and if it does, make a new column, copy all the data over and drop the old column.

Is there any way to just change the name in code? Otherwise it's probably going to be quicker (but nowhere near as elegant) to open each database, open the table in design view and change it there!

Jim
Jan 31 '08 #1
7 4974
Jim Doherty
897 Expert 512MB
Hi

If all you can do with ALTER TABLE....ALTER COLUMN is change the datatype/size then how do I change the name of a field?

I have several database files spread all over the state and some of the users (Darn users!) have changed a field from "Datum" to "MapDatum" and I need to change it back because it is causing problems with the front end.

I suspect that I'm going to have to determine if the field MapDatum exists and if it does, make a new column, copy all the data over and drop the old column.

Is there any way to just change the name in code? Otherwise it's probably going to be quicker (but nowhere near as elegant) to open each database, open the table in design view and change it there!

Jim
This will loop 'all' tables seeking the offending field and change it for the 'current' database Jim..... but I'm a little confused as to the 'all over the state' bit you speak about where is the table located obviously this code below does not target external databases in any logical sweep merely the current one?

Expand|Select|Wrap|Line Numbers
  1.  Dim db As DAO.Database 
  2. Dim tbl As DAO.TableDef
  3. Dim fld As DAO.Field
  4. Set db = CurrentDb()
  5. For Each tbl In db.TableDefs
  6. For Each fld In tbl.Fields
  7.      If fld.Name = "MapDatum" Then fld.Name = "Datum"
  8. Next
  9. Next
  10.  
Regards

Jim :)
Feb 1 '08 #2
JustJim
407 Expert 256MB
This will loop 'all' tables seeking the offending field and change it for the 'current' database Jim..... but I'm a little confused as to the 'all over the state' bit you speak about where is the table located obviously this code below does not target external databases in any logical sweep merely the current one?

Expand|Select|Wrap|Line Numbers
  1.  Dim db As DAO.Database 
  2. Dim tbl As DAO.TableDef
  3. Dim fld As DAO.Field
  4. Set db = CurrentDb()
  5. For Each tbl In db.TableDefs
  6. For Each fld In tbl.Fields
  7.      If fld.Name = "MapDatum" Then fld.Name = "Datum"
  8. Next
  9. Next
  10.  
Regards

Jim :)
That will do nicely thanks Jim. "All over the state" means just that, on computers all over the state of Victoria, Australia. It's a front end/back end setup where the back ends are located on each and every users C:\ drive!

Please, don't look at me like that, I didn't design it.

The back ends do get sent in to the head office periodically and this is coming up soon so I'm writing a little fixer-upper code for the poor woman who administers this mess.

Thanks for the code, I was actually getting pretty close. I can cut down one of the loops because I know what table I'm going to look at.

Jim
Feb 1 '08 #3
Jim Doherty
897 Expert 512MB
That will do nicely thanks Jim. "All over the state" means just that, on computers all over the state of Victoria, Australia. It's a front end/back end setup where the back ends are located on each and every users C:\ drive!

Please, don't look at me like that, I didn't design it.

The back ends do get sent in to the head office periodically and this is coming up soon so I'm writing a little fixer-upper code for the poor woman who administers this mess.

Thanks for the code, I was actually getting pretty close. I can cut down one of the loops because I know what table I'm going to look at.

Jim
Fine..merely interested kinda knew you'd have no problem overall

Jim :)
Feb 1 '08 #4
JustJim
407 Expert 256MB
Fine..merely interested kinda knew you'd have no problem overall

Jim :)
All installed, debugged and delivered. I get paid next Thursday and I hope it's the last I see of that application.

How come I never get the jobs where you get to design an application from scratch? You know, all the 1NF, 2NF, 3NF stuff I learned in uni?

Ah well...

Jim
Feb 1 '08 #5
Jim Doherty
897 Expert 512MB
All installed, debugged and delivered. I get paid next Thursday and I hope it's the last I see of that application.

How come I never get the jobs where you get to design an application from scratch? You know, all the 1NF, 2NF, 3NF stuff I learned in uni?

Ah well...

Jim
Hahaha yes seems a million miles away I guess
Feb 1 '08 #6
missinglinq
3,532 Expert 2GB
I get paid next Thursday and I hope it's the last I see of that application.
Can you say "Not a chance in the world!" JustJim?

I knew you could!

Linq ;0)>
Feb 1 '08 #7
JustJim
407 Expert 256MB
Can you say "Not a chance in the world!" JustJim?

I knew you could!

Linq ;0)>
Not even one tiny little chance in all the world? Sheesh!
Feb 2 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Dave C. | last post by:
Hello, I have created the following trigger: CREATE TRIGGER tr_UDFTest ON UserDefinedFields FOR INSERT, UPDATE AS DECLARE @foobar varchar(100) SELECT @foobar= foobar FROM inserted IF (...
1
by: ibm_97 | last post by:
DB2 8.2 on AIX Hi, I'd like to change a column's name in a table which is part of replication. This column is identity column (generated always). 1. Since DB2 will drop and recreate the...
3
by: A Clark | last post by:
I have a subform that displays a datasheet. There are a couple of different queries that can be displayed in the datasheet. The queries are available in a combo box on the main form. The problem...
0
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the...
6
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the...
3
by: ymcj | last post by:
Hi, I'm trying to change the column name - date to Sdate in all the tables in my database. As i have many to change so i tried to search all tables and have it change automatically rather than...
2
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
3
by: kjqua | last post by:
Hi all, I am newbie in c# and i have a question regarding DataGridView I have a Table with 3 Columns (0)IdLeggiSeriale <Is Primary key> (1)ValoreSeriale <Is Integer>...
0
by: Czechtim | last post by:
Hello, I have problem with databinding. I created small application using structure that I need to demonstrate problem. I need to change content of label when changing content of property...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.