Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change field name with programming 2

Status
Not open for further replies.

poupou

Programmer
Jun 12, 2002
6
CA
I have 450 tables .dbf and i would like to rename field at the second podition like aaa* to aaa.

I won to do that because some field does't have the same name like aaa1 or aaa2 ...

Is't possible

Thanks
Sorry for my bad english

Redg
 
Look at the Alter Table command:
ALTER TABLE TableName1 ;
RENAME COLUMN FieldName4 TO FieldName5

Rick
 
Please test this program and make sure it isn't going to do anything nasty with your data before you use this!

Brian

With 450 tables you may want to write a prg like:

VarFieldNumbertoChange=2
VarNewFieldName="NewName"


CLOSE ALL
SET SAFETY OFF
ADIR(mytables, '*.Dbf')
for TblCount = 1 to ADIR(mytables, '*.Dbf')
VarTable=mytables(TblCount,1)
use &VarTable
IF DBF()#SYS(5)+SYS(2003)+"\TEMPSTUCT.DBF"
copy struct to tempstuct extended
use tempstuct
go Min(RECCOUNT(),VarFieldNumbertoChange) && will change last field if specified number is out of range
VarActName=alltr(field_name)
use &VarTable
IF VarActName#VarNewFieldName AND DBF()#SYS(5)+SYS(2003)+"\TEMPSTUCT.DBF"
alter table &VarTable rename column &VarActName to &VarNewFieldName
ENDIF
ENDIF
ENDFOR
SET SAFETY On
 
Just to be clear, the above program will rename _every_ 2nd column of _every_ 'dbf' in the directory in which it is run.

I just don't want you to have to go back and try to figure out what the original names were.

If size doesn't prohibit it, I strongly suggest running it on copies of the tables.

Or you could alter to program to retain each table's extended structure file so that you can reverse it if you need to.

Brian
 
Thanks a lot baltman !

I have just a litle problem. When I execute the code, I need to select manuelly the code page to continious the program(for each file in my folder). Is't possible to put some command in code to do that.

The line code where I need help is:

use &VarTable


Thanks

Redg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top