Create new column if it doesn't exist

Hello everybody,

today I just want to preserve simple sql which creates column, if it is not created yet in ms sql db. Important feature of this code is indempotency.

IF Col_length('APPayment', 'usrPOSkipped') IS NULL
      PRINT '[usrPOAllocated] will be created'

      ALTER TABLE appayment
        ADD usrposkipped BIT
      PRINT '[usrPOAllocated] already exists'

Few explanations. This code will create column usrPOSkipped in table APPayment.

No Comments

Add a Comment