Creating a conditional alter table script?

  • I have a need to alter a table with a SQL script, which may have been previously modified. The concern is to first check to see if a field has been previously been added to a table.

    Due to some loosely controlled versioning issues, the end user may have all ready added the new table

    What I need is the syntax to check if the field "IncludeQuestion" in the table "T_Customize" exists, an if not create the field.

    I can handle the alter table script as well as creating indexes and such. My only concern is to test to see if I need to run the alter script.

    Any help would be greatly appreciated!

    John

  • If exists(select * from information_schema.column where table_name='T_Customize' and column_name='IncludeQuestion')

    alter statement

  • Thanks ever so much! 

    You've made my day.

    John

  • Hi,

    What is the "information_schema" in "information_schema.column". Can someone provide an example.

    Thanks

  • It's a VIEW.

    Refer to the Books OnLine (BOL), use the Index tab and enter INFORMATION_SCHEMA. You'll see a whole list of these views.

    -SQLBill

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

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