Solved

change fieldname of a table

Posted on 2003-12-09
4
257 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
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Stefaan earned 20 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
 
LVL 5

Expert Comment

by:delphized
ID: 9911329
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now