How to drop Default Constraint on a Table Column without knowing Constraint Name in MS SQL Server 2005
SQL developers create and drop default constraint on a database table column frequently. If the T-SQL programmers wants to drop a table column where a default constraint is defined, first the default constraint should be dropped. In order to drop default constraint on a column, SQL developers need to know the table and constraint name to use following Transact-SQL command:
Although it is a line of code to execute for deleting a SQL Server default constraint, if you do not know the name of the SQL constraint name it might be a problem. Especially if you create scripts to run unattendant, you must know the name of the SQL constraint somehow to build your SQL batches.
Following SQL Server stored procedure finds the default constraint name created on a table column and drop default constraint that is found. The "ALTER TABLE DROP CONSTRAINT" command is created dynamically and executed using the SQL sp_executesql stored procedure to delete default constraint.
After default constraint is dropped, SQL programmers can drop the table column unless any other SQL constraints are not defined on target column. For example if a SQL Check constraint if defined, using a similar stored procedure developers or database administrators can also drop check constraint defined on table column without knowing constraint name.