Skip to main content

How to create a SQL server table column only if it doesn't already exist.

if col_length('<schema>.<table>', '<column>') is null
begin
    print 'Adding column <schema>.<table>.<column>';
    alter table <schema>.<table>
    add <column> varchar(255) null;
end;
else
begin
    print 'Column <schema>.<table>.<column> already exists';
end;