Should work, but you need to program the alter dynamically depending on # and names of missing columns plus dynamic check.
Often not worth the effort, as such changes should not happen often - KISS and a walk to coffee machine during runtime sufficient for most tables...
>Hi,
>
>I have a code in my VFP application that allows checking if a column exists in a table of a SQL Server database and then add it. The segment of the code that I execute from VFP is below:
>
>
>TEXT TO cSqlCommand TEXTMERGE NOSHOW
> IF NOT exists (select COLUMN_NAME from INFORMATION_SCHEMA.columns where table_name = '<<tcTableName>>' and column_name = '<<tcFieldName>>' )
> BEGIN
> alter table <<tcTableName>> add <<tcFieldName>> <<tcFieldType>> null
> SELECT CAST(1 AS bit) AS col_added
> END
> ELSE
> SELECT CAST(0 AS bit) AS col_added
>ENDTEXT
>
>
>The above works fine for one column.
>
>Now I now I need to add more than one column to a table. I could run the above code, with different values of the field name (tcFieldName) and I am sure it will work. But the table is fairly large - almost a million records. So, I am thinking that the above code executed more than one time will take longer (I don't really know how much longer though).
>
>I am thinking that it would be nice to add more than one column in one process. Is it possible? Can I "string" multiple "ALTER TABLE ... ADD " into one command?
>
>TIA