Feature #86
How to delete the default constraint for a column
0%
Description
I have found how to do this...
Replace text with your schema, table and column.
Code:
SELECT SCHEMA_NAME(t.schema_id) as [schema]
, t.name as [table], c.name as [column], d.name as [default_constraint]
, d.definition
FROM sys.tables t
JOIN sys.default_constraints d on d.parent_object_id = t.object_id
JOIN sys.columns c on c.object_id = t.object_id and c.column_id = d.parent_column_id
WHERE t.name = 'ENTITY' and t.schema_id = schema_id('dbo') and c.name = 'CREDIT_LIMIT'
This will return something like this...
@schema table column default_constraint definition
dbo ENTITY CREDIT_LIMIT DF_ENTITYCREDIT_L_01D345B0 ((0))@
Next, parse those results in DataFlex and build a sSQL statement to remove the default constraint
@Move "ALTER TABLE %1.%2 DROP CONSTRAINT %3" to sSQL
Move (SFormat(sSQL, sSchema, sTable, sConstraint)) to sSQL@
Lastly, execute the sSQL string.