Contents tagged with Create column

  • 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   BEGIN       PRINT '[usrPOAllocated] will be created'       ALTER TABLE appayment         ADD usrposkipped BIT   END ELSE   BEGIN       PRINT '[usrPOAllocated] already exists'   END 

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