Renaming a column without breaking the scripts and stored procedures

前端 未结 5 1526
清歌不尽
清歌不尽 2020-12-20 16:11

I want to modify a column name to new name present in a table

but here problem i want to manually modify the column name present in Triggers

5条回答
  •  一生所求
    2020-12-20 16:51

    This suggestion relates to Oracle DB, however there may be equivalent solutions in other DBMS's.

    A temporary solution to your issue is to create a pseudocolumn. This solution looks a little hacky because the syntax for a pseudocolumn requires an expression. The simplest expression I can think of is the case statement below. Let me know if you can make it more simple.

      ALTER TABLE <> ADD (
       <> AS (
        CASE
          WHEN 1=1 THEN <>.<>
        END)
      );
    

    This strategy basically creates a new column on the fly by evaluating the case statement and copying the value of <> to <>. Because you are dynamically interpolating this column there is a performance penalty vs just selecting the original column.

    The one gotcha is that this will only work if you are duplicating a column once. Multiple pseudocolumns cannot contain duplicate expressions in Oracle.

    The other strategy you can consider is to create a view and you can name the columns whatever you want. You can even INSERT/UPDATE/DELETE (execute DML) against views, but this would give you a whole new table_name, not just a new column. You could however rename the old table, and name your view the same as your old table. This also has a performance penalty vs just accessing the underlying table.

提交回复
热议问题