I'm trying to set the default value of a non nullable bit column using Microsoft's SMO (C#) but I get an error on table creation.
Currently what I have is
if (!string.IsNullOrWhiteSpace(dynamicColumn.DefaultValue))
{
column.Default = dynamicColumn.DefaultValue;
}
However when trying to create the table I get the following error:
One or more errors occured.
Create failed for Table'CustomDocument.TestDef9_Data'. An exception occurred while executing a Transact-SQL statement or batch. The default '((0))' does not exist.
I've tried ((0)), (0), and 0, and I get the same error every time.
Is there a different property I need to set on the column object or some other way to do it?
2条答案
按热度按时间2q5ifsrm1#
I was able to do it thusly (in powershell, but it's conceptually the same):
w41d8nur2#
You have to use
DefaultConstraint
property instead. Here a snippet