473,785 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change column name?

JustJim
407 Recognized Expert Contributor
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 5006
Jim Doherty
897 Recognized Expert Contributor
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 Recognized Expert Contributor
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 Recognized Expert Contributor
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 Recognized Expert Contributor
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 Recognized Expert Contributor
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 Recognized Expert Specialist
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 Recognized Expert Contributor
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
3448
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 ( @foobar = 'foobar') INSERT INTO LogTable (LogText) values ('Found foobar')
1
2305
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 table with the changed column name, do I have to do something like 'set integrity off'?
3
13425
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 I am having is that when I change the query all the column widths remain the same. This doesn't look very good. I can't figure out a way to set the column widths. I have tried.. Subform.controls(Name of Column).columnwidth = IntColumnWidth
0
2664
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 CompanyName, ContactName, and ContactTitle columns from the Customers table in the Northwind database. Whenever the value of ContactTitle equals "Owner" we will change the font color to red. We can do this by using an ItemTemplate where we have...
6
10681
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 data on the datasource. It simply gets the first name and last name of an instructor and displays it in the grid. I have two major problems.... One, it doesn't display in the column until the row is saved, (Even after calling a refresh on the...
3
18741
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 manually however my query doesn't seem to do the job? requesting assistance from anyone is appreciated thank you! DECLARE @sSQL AS VarChar(500), -- SQL Statement @sTableName AS VarChar(100) -- TableName DECLARE CursorTable CURSOR FOR SELECT FROM...
2
7989
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 I've done for test purposes is use a text input file for the table field lookup properties. I thought that I'd start first by just changing the 'Display Control' property. Thanks to Allen Browne for some ideals per...
3
15024
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> (2)DataAcquisizione <Is DateTime>
0
4352
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 "Promena". I change content of property "Promena" from "Origin text" to "Changed text" using thread but content of label is still the same - databinding isn´t working according to my vision. Does somebody know, please, why content of label doesn´t change...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10324
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9949
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.