?
Solved

change fieldname of a table

Posted on 2003-12-09
4
Medium Priority
?
264 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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