Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

change fieldname of a table

Posted on 2003-12-09
4
Medium Priority
?
265 Views
Last Modified: 2010-04-05
Hi,

is there any way that I can change a field name in  database table in runtime ?

Im using DBBase IV as my database table

I use :
         TableData.open;
         for i :=0 to TableData.FieldCount -1 do
           begin
                 TableData.Fields[i].FieldName := ShareID[i];
           end;

thanks alot ;)
0
Comment
Question by:allie910
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Stefaan earned 60 total points
ID: 9910301
I think you will have to issue an SQL Command for that.  Also I don't think there will be an easy way to modify the name of the column by itself.  I think you will have to do it in different steps :

First :

ALTER TABLE <TableName> ADD <NewFieldName> <DataType> ...

This will create a new column in your table with the new field name.  Next you will have to copy all the data from your old field into the new field :

UPDATE <TableName> SET <NewFieldName> = <OldFieldName>

Now you have copied all the old data into the new column, you can delete the old column from your table :

ALTER TABLE <TableName> DROP COLUMN <OldFieldName>

Depending on your Database that SQL Command might vary, but it should look similar to what I typed out.  As you see reneaming a field in your database itself will be a 3 step proces.

Regards,


Stefaan
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9910414
told i already in a previous q, stefaan

allie, go here
http://info.borland.com/devsupport/bde/bdeapiex/dbidorestructure.html

and read example 3

btw. a fieldname cannot be a number

meikl ;-)
0
 
LVL 3

Expert Comment

by:Stefaan
ID: 9910431
Bah, didn't see the DBase thingie, well using BDE API calls is a bad idea anyway, since BDE isn't really supported anymore :-P

But if it helps him out, then it should be good.  Otherwise, it would be a good idea to skip the BDE stuff.

Regards,


Stefaan
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question