In SQL Server, if a field is set to table a default value, it will generate in the system table sysobjects a default constraint.
If you want to delete this sets the default value of field (assuming the field name column1), implementation of the "ALTER TABLE table1 DROP COLUMN column1" error when will The object 'DF__xxxxxxxxxxx' is dependent on column 'column1'.
ALTER TABLE DROP COLUMN column1failed because one or more objects access this column.
So when you delete this field in the corresponding first system table to delete the default constraint, you can use the following script to delete:
- This script drops the default constraint which is generated by the setting of default value.DECLARE @ tablename VARCHAR (100), @ columnname VARCHAR (100), @ tab VARCHAR (100) SET @ tablename = 'CountryGroupEmailAndWaitAux'SET @ columnname = 'actionOfHasNoValidEmail'declare @ defname varchar (100) declare @ cmd varchar (100) select @ defname = nameFROM sysobjects so JOIN sysconstraints scON so.id = sc.constidWHERE object_name (so.parent_obj) = @ tablenameAND so.xtype =' D ' AND sc.colid = (SELECT colid FROM syscolumnsWHERE id = object_id (@ tablename) ANDname = @ columnname) select @ cmd = 'alter table' + @ tablename + 'drop constraint' + @ defnameif @ cmd is null print 'No default constraint to drop'exec (@ cmd)
Remove the default constraint in the corresponding post, run:
ALTER TABLE table1 DROP COLUMN column1
You can delete the field.