Loading ...

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.

Be the first to rate this post

  • Currently 0.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5