If the default value of a column is set when a table column is added dynamically,
If you use the alter table tablename drop column columnname statement, an error is returned,
For example:
"Message 5074, level 16, status 1, 1st row object 'df _ tb_salarypar _ AA _ 7db89c09 'depends on column 'A '.
Alter table drop column AA failed because one or more objects access this column in message 4922, level 16, status 9, and 1st ."
The default constraint exists.
What we need to do now:
1. Find the constraint name for this column in the table.
Declare@ NameVarchar (50) -- Name of the constraint corresponding to the column
Select @ name = B. name from sysobjects B join syscolumns A on B. ID = A. cdefault
Where a. ID = object_id ('Tablename') -- Table name
And a. Name ='Columname'-- Column name
2. Delete the constraint and delete the column.
Exec ('alter tableTablenameDrop constraint '+@ Name)
Exec ('alter tableTablenameDrop ColumnColumname')