Solved

change fieldname of a table

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

24 Experts available now in Live!

Get 1:1 Help Now