none
CHANGE FIELD NAME IN A TABLE PROGRAMATICALLY RRS feed

Answers

  • If you want your coffee sweet put sugar into your coffee mug, don't water your coffee plants with sugared water.

    That's why I said "that should be clear besides all other consequences of renaming." 

    Obviously you're not aware as you even don't know name rules.

    This is not a name, this is what you'd likely want as a caption. Well, there is the caption property of grid column headers and you set that, that's not bound to any rules like unalloweed characters for names.

    Besides, even if that was an allowed name. you'll not get happy with changing field names as code will not find field fy1 anymore, you'd just be destroying your application.

    You want to display data for march 2015, then query that and you can query SELECT fy1 as 2015_03 from yourtable where somedatefield between date(2015,3,1) and date(2015,3,31), for example, but don't alter the table just because field names are the default captions, captions are an independent property and you set them how you like or need them, don't rename table fields. A typical table contains data throughout all history of an application - unless you intentionally limit its data to one month. But you don't write code for every month, instead you write code running at any time and thus you don't design tables with monthly column names. That's the job of header captions, label captions or excel header row captions, in short the job of any UI, not the data tables.

    Bye, Olaf.


    Thursday, May 2, 2019 8:22 AM

All replies

  • Following.
    Wednesday, May 1, 2019 10:12 AM
  • ALTER TABLE tablename RENAME COLUMN oldname TO newname

    Btw the intellisense tiptext of ALTER TABLE doesn't show that, as ALTER TABLE is complex, just as all SQL commands are and can't be covered in a simple tip text syntax diagram.

    Like any table alteration that needs exclusive access and rewrites the whole table, therefore it is nothing you should do regularly in an application on large tables, but that should be clear besides all other consequences of renaming.

    Bye, Olaf.

    Wednesday, May 1, 2019 11:51 AM
  • ALTER TABLE tablename RENAME COLUMN oldname TO newname  

    I tried this. But 'syntax error' message comes?

    Alagappan S


    S.Alagappan

    Wednesday, May 1, 2019 1:48 PM
  • Show us the exact code you tried. If it's what you showed us, then you need to go back substitute in the name of your table and the old and new column names.

    To do this, you'll need to open the table in EXCLUSIVE mode.

    Also, you do realize that changing a field name breaks any code that uses that name, right? If this is a cursor or other temporary table, shouldn't be a problem, but for a permanent table, changing field names should only happen in maintenance code that runs in conjunction with an update to the application.

    Tamar

    Wednesday, May 1, 2019 8:22 PM
    Moderator
  • ALTER TABLE BUDGET_ANNUAL.DBF RENAME COLUMN FY1 TO 2015/03

    I used the above code. Still syntax error occurs. I also tried after opening the table in EXCL mode and without opening the table. Is it required to enclose the field name and the table name in quotes? That also I tried. The table is not used anywhere else. This is the first testing program

    Thanks for suggestions

    Alagappan S


    S.Alagappan

    Thursday, May 2, 2019 5:06 AM
  • ALTER TABLE BUDGET_ANNUAL.DBF RENAME COLUMN FY1 TO 2015/03

    Follow field's name rule....

    ALTER TABLE BUDGET_ANNUAL.DBF RENAME COLUMN FY1 TO FY_2015_03

    Thursday, May 2, 2019 6:45 AM
  • If you want your coffee sweet put sugar into your coffee mug, don't water your coffee plants with sugared water.

    That's why I said "that should be clear besides all other consequences of renaming." 

    Obviously you're not aware as you even don't know name rules.

    This is not a name, this is what you'd likely want as a caption. Well, there is the caption property of grid column headers and you set that, that's not bound to any rules like unalloweed characters for names.

    Besides, even if that was an allowed name. you'll not get happy with changing field names as code will not find field fy1 anymore, you'd just be destroying your application.

    You want to display data for march 2015, then query that and you can query SELECT fy1 as 2015_03 from yourtable where somedatefield between date(2015,3,1) and date(2015,3,31), for example, but don't alter the table just because field names are the default captions, captions are an independent property and you set them how you like or need them, don't rename table fields. A typical table contains data throughout all history of an application - unless you intentionally limit its data to one month. But you don't write code for every month, instead you write code running at any time and thus you don't design tables with monthly column names. That's the job of header captions, label captions or excel header row captions, in short the job of any UI, not the data tables.

    Bye, Olaf.


    Thursday, May 2, 2019 8:22 AM
  • Thank you Olaf. Even as I knew naming rules, I forgot, thanks to my age 87. As suggested by you, I will not change the Table field name. I have already completed the program without that.Thanks again

    Alagappan S


    S.Alagappan

    Friday, May 3, 2019 3:49 AM