I am updating some code removing a relationship from some terms we have with credit limits. To do this I get to update the database!
The new schema will add a column for CreditLimitCode which will be the same as the old column TermsCodeId without that columns keys. I need to leave TermsCodeId intact for the time being so a rename is not possible.
I attempted the answer for this SO question but that give me syntax errors because CreditLimitCode does not exist and I do not like the default being added.
IF COL_LENGTH('CreditApp.dbo.CreditLimit', 'CreditLimitCode') IS NULL
BEGIN
ALTER TABLE CreditApp.dbo.CreditLimit ADD CreditLimitCode VARCHAR(6) NOT NULL DEFAULT (0)
UPDATE CreditApp.dbo.CreditLimit SET CreditLimitCode = CreditTermsId WHERE CreditLimitCode = 0
PRINT 'Added CreditLimitCode to CreditLimt'
END
I am not sure a trigger for after insert here would be correct because I am altering the table not inserting rows.