SET talk off
SET safe off
WAIT '正在进行字段改名,请稍候...' wind nowa
Clos all
USE 源表 alia a1 in 0
USE fname in 0
SELE fname
N=recc()-fcount('a1')
IF n#0
IF n>0
FOR i=1 to n
GO bott
Dele
PACK
ENDF
ELSE
FOR i=1 to -n
APPE blan
ENDF
ENDI
ENDI
SELE a1
COPY stru to nstru exte
GO top
USE nstru in 0
SELE nstru
COPY to nstru1
GO top
SCAN
SELE fname
IF len(allt(newname))>0
SELE nstru
REPL field_name with fname.newname
ENDI
SELE fname
Skip
SELE nstru
ENDS
CREA newtable1 from nstru
USE nstru1 in 0
SELE nstru1
APPE from nstru
SELE * dist from nstru1 into table nstru2
CREA newtable1 from nstru2
USE newtable1 in 0
SELE newtable1
APPE from 源表
SELE fname
GO top
SELE nstru
GO top
SCAN
SELE fname
IF len(allt(newname))>0
SELE newtable1
oldfield=allt(nstru.field_name)
newfield=allt(fname.newname)
REPL all &newfield. with &oldfield
ENDI
SELE fname
Skip
SELE nstru
ENDS
USE newtable1 in 0
SELE newtable1
APPE from newtable1
Clos all
RENA newtable1.dbf to 源表.dbf
Dele file nstru.dbf
Dele file nstru1.dbf
Dele file nstru2.dbf
Dele file newtable1.dbf
SET talk on
SET safe on
WAIT '字段改名成功!' wind time 2
RETU