Reputation: 5543
I have a table with a column defined as
create table foo
(
edit_date datetime default (getdate()) not null
)
Yet the Default
property on the corresponding Microsoft.SqlServer.Management.Smo.Column
object is empty.
All of the other properties (e.g. Name
, DateType
, InPrimaryKey
, etc) are correct.
The documentation is a bit sparse so I'm wondering whether or not that property is even meant to be read.
Should the Column.Default
property be empty even when the column definition contains a default?
Upvotes: 2
Views: 1196
Reputation: 115
The default value on a column is held as contrainst against the column itself. If you want to get at the value then use the DefaultContrainst property. Under that you can then use the Text property to get the actual value.
DefaultConstraint constraint = column.DefaultConstraint;
string value = Constraint.Text;
Upvotes: 2