How to change existing column to a computed column

  • Hi,
    How to add a computed expression in an existing table column.

    Regards
    Binu

  • binutb - Friday, July 21, 2017 7:54 AM

    Hi,
    How to add a computed expression in an existing table column.

    Regards
    Binu

    You'll need to add a new column. AFAIK, you cannot modify an existing physical column to a computed column.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Phil Parkin - Friday, July 21, 2017 9:00 AM

    binutb - Friday, July 21, 2017 7:54 AM

    Hi,
    How to add a computed expression in an existing table column.

    Regards
    Binu

    You'll need to add a new column. AFAIK, you cannot modify an existing physical column to a computed column.

    Also note that, new column means new name and new values. You can't rename a computed column nor can you explicitly add values (e.g. INSERT <table>(<computed column>) VALUES ('123');).

    If the computed value is the same as the what's already in there then you could drop the column and recreate it as a computed column. If not then what you are asking is impossible as far as I know.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • binutb - Friday, July 21, 2017 7:54 AM

    Hi,
    How to add a computed expression in an existing table column.

    Regards
    Binu

    Normally you'll do that via a trigger, but you do need to elaborate further as the question is quite vague. 
    😎

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply