Batch "alter table add column"

  • Hi,

    I have 50 databases that I need to issue the following SQL statement

    ALTER TABLE CUST ADD ADDRESS_2 VARCHAR(50)

    As I am constantly alter the table, is there any procedure I can speed up the process? Batch ?

    Suggestions? Thanks in advance.

  • Try this undocumented stored procedure

    master..sp_msforeachdb 'ALTER TABLE [?]..CUST ADD ADDRESS_2 VARCHAR(50)'

    if the table does not exist in current database, you will get an error for that database instead of creating the column.


    N 56°04'39.16"
    E 12°55'05.25"

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

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