When you use an SQL statement (Format: alter table [tablename] alter column [colname] [newdatatype]) in a SQL database to modify the field type of a table, an error is returned:
"*********************************
The object 'df _ ******* 'depends on the column 'column1 '.
***********************************
Because one or more objects access this column, Alter table ********* failed ."
According to the above prompt, search for the result online and find that the cause of this error is that the field to be modified has the default constraint. solution:
1. Find the name of the constraint for this field in the table (or based on the existing prompt and the object 'df __******')
Declare @ name varchar (50)
Select @ name = B. name from sysobjects B join syscolumns A on B. ID = A. cdefault
Where a. ID = object_id ('tablename ')
And a. Name = 'columname'
2. Delete existing constraints
Exec ('alter table tablename drop constraint' + @ name)
3. Run the script to modify the field type.
Based on the data query, it is found that all operations such as setting the field in the table to not null (not empty) and adding the default value (default value) to the field will add constraints to the field, after these constraints are added, a similar error occurs when you use an SQL script to modify the field type or delete a field. You need to find the existing constraints on the field and Delete the existing constraints, execute the modify/delete script again.
Reference:
1. When modifying the field type, the column classinfo_showtype is dependent, because one or more objects access this column.
2. SQL server: delete columns with default values from a table using SQL statements.