Thursday, February 16, 2012

Changing field length changes AllowNulls=True

(If this is in the wrong newsgroup, let me know and I'll move it.)
Using SQLDMO from a VB app to modify an existing field in a SQL 2000
database.
All the fields in my database have AllowNulls = False.
After changing a field size in the manner below, I look at the table in
Enterprise Manager and Allow Nulls is now True! This is fully repeatable.
Here's the code:
Dim oTable As sqldmo.Table
Dim oColumn As New sqldmo.Column
'skip the Set statements..
oTable.BeginAlter
oColumn.Length = pSize
oTable.DoAlter
I do not believe the version of SQLDMO matters as this happens on older as
well as newer versions.
Any ideas?
Thanks,
Jerry
I have not used DMO objects much, but in scripting when altering a field
size, if you don't specify not null in the alter it defaults to null. So in
your DMO could maybe set the field to not null before updating it.
Thanks!
Mohit K. Gupta
B.Sc. CS, Minor Japanese
MCTS: SQL Server 2005
"Jerry J" wrote:

> (If this is in the wrong newsgroup, let me know and I'll move it.)
> Using SQLDMO from a VB app to modify an existing field in a SQL 2000
> database.
> All the fields in my database have AllowNulls = False.
> After changing a field size in the manner below, I look at the table in
> Enterprise Manager and Allow Nulls is now True! This is fully repeatable.
> Here's the code:
> Dim oTable As sqldmo.Table
> Dim oColumn As New sqldmo.Column
> 'skip the Set statements..
> oTable.BeginAlter
> oColumn.Length = pSize
> oTable.DoAlter
> I do not believe the version of SQLDMO matters as this happens on older as
> well as newer versions.
> Any ideas?
> Thanks,
> Jerry
>
>

No comments:

Post a Comment