First isolate the default value constraint name for the field, and then delete the default value constraint based on the default value constraint name
Declare @constraintName varchar( $)Select @constraintName =B.name fromsyscolumns a,sysobjects bwherea.ID=object_id('Tb_kysubproject') andb.ID=A.cdefault andA.name='Final_belong_programme' andB.name like 'df%'SELECT @constraintNameexec('ALTER TABLE tb_kysubproject drop constraint'+@constraintName)
Attention:
1.sql constraint prefix pk, UK, DF, CK, FK:
PK is primary key abbreviation, PRIMARY KEY constraint
UK is a unique key abbreviation, the only constraint
CK is a check abbreviation, checking constraints
FK is the foreign abbreviation, the primary foreign key relationship
DF is the default abbreviation, and defaults are constrained
2.syscolumns
cdefault :int the default value ID of the column.
ID:int the Table object ID that the column belongs to, or the stored procedure ID associated with the parameter.
Name :sysname The names of column names or procedure parameters.
3. object_id function
The function returns the ID value of the specified object
SQL Server Deletes the default value constraint for a table