Strange Behaviour

  • While executing the following commands

    -- Set 1

    alter table employee add test varchar(10)

    update employee set test = 'abc'

    go

    I get the error

    "Invalid column name 'test'"

    The following works fine....

    -- Set2

    alter table employee add test varchar(10)

    go

    update employee set test = 'abc'

    go

    But now, if I drop the column using

    -- Set 3

    alter table employee drop column test

    go

    and try to execute Set 1 that is,

    alter table employee add test varchar(10)

    update employee set test = 'abc'

    go

    I don't get the error I was getting before. Why?

  • Schema evaluation happens during parsing time, not execution time (just like in any other programming language).

    So, there is nothing stange in this behaviour.

    P.S. Altering table schema on fly is one of the worst practices known in database development.

    Avoid it by any means.

    If you are absolutely sure it's the only way to go ask some some experienced DB developer how to build a correct solution.

    _____________
    Code for TallyGenerator

Viewing 2 posts - 1 through 1 (of 1 total)

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