Solved

change fieldname of a table

Posted on 2003-12-09
4
260 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

772 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