close all use customer excl && This add a field called ALTADDR1 fmodtable("ADD","CUSTOMER","ALTADDR1","C","100") && This modify a field called ALTADDR2 fmodtable("ALTER","CUSTOMER","ALTADDR2","C","200") && This DROP a field called ALTADDR fmodtable("DROP","CUSTOMER","ALTADDR","C")
*--------------------------------------------------------------- *-- Generic table maintenance *-- Current limitations: *-- *-- Parameters are as follow: *-- tcAction = ALTER;ADD;DROP *-- tcTableName, tcFieldName, tcFieldType *-- tcFieldLen1(for type C and N), tcFieldLen2(for type N) *-- *--| Currently limited to type C,N,I,L,D *--|Alter command only works for type C & N *--------------------------------------------------------------- FUNCTION fmodtable LPARAMETERS tcAction, tcTableName, tcFieldName, tcFieldType, tcFieldLen1, tcFieldLen2 LOCAL lFlag, lcFieldStru lFlag = .F. lcFieldStru = "" *-- Initialize table fields first DO CASE CASE tcFieldType == "C" lcFieldStru = tcFieldType + "(" + tcFieldLen1 + ")" CASE tcFieldType == "N" lcFieldStru = tcFieldType + "(" + tcFieldLen1 +","+ tcFieldLen2 + ")" CASE tcFieldType == "I" lcFieldStru = tcFieldType CASE tcFieldType == "D" lcFieldStru = tcFieldType CASE tcFieldType == "L" lcFieldStru = tcFieldType RETURN lcFieldStru ENDCASE DO CASE CASE tcAction == "ADD" SELECT &tcTableName FOR I = 1 TO FCOUNT() IF FIELD(I) == tcFieldName lFlag= .T. EXIT ENDIF ENDFOR IF !lFlag ALTER TABLE &tcTableName ADD COLUMN &tcFieldName &lcFieldStru ENDIF CASE tcAction == "ALTER" IF tcFieldType == "C" OR tcFieldType == "N" IF FSIZE(tcFieldName) <> VAL(tcFieldLen1) ALTER TABLE &tcTableName ALTER COLUMN &tcFieldName &lcFieldStru ENDIF ENDIF CASE tcAction == "DROP" ALTER Table &tcTableName Drop COLUMN &tcFieldName ENDCASE ENDFUNC