Create New Column If It Doesn T Exist
13 February 2017
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.