add column

  • Hi

    I want to have a query in a stored procedure which will check a table if it has the columns ,column1 and column2. If it has the 2 columns then do nothing but if it doesn't then add the 2 columns with nvarchar type,size(20) and set its default value to "start".

    thanks a lot

  • if not exists(select * from sysobjects t join syscolumns c on t.id = c.id where t.name = 'tablename' and t.xtype = 'U' and c.name in ('column1','column2'))
    
    alter table tablename add column1 nvarchar(20), column2 nvarchar(20)

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

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