>>>>The column had the DEFAULT set before I made the change of the column size. And I do prefer not to change the default. Do I understand correctly that the DEFAULT will stay the way it was before I change the size?
>>>>Thank you.
>>>
>>>In earlier versions of SQL Server I always got "Can not ALTER ... there is a constraint' something like this (can't remember the exact text).
>>>That is why I have this habit to remove default constraint, change the size and put the constraint back.
>>>Maybe MS changed this behavior lately and there is no more error, I don't know.
>>
>>Thank you for clarifying this point. Say, I have to remove the Default constraint before setting the new column size, how do I find out if the Column has a Default Constraint? And how would you remove it?
>
>
>
>DECLARE @colname nvarchar(200)
>DECLARE @sql nvarchar(200)
>SELECT @colname = MIN(sysobjcnstr.NAME)
> FROM sys.objects sysobj
>INNER JOIN sys.objects sysobjcnstr ON sysobj.object_id = sysobjcnstr.parent_object_id
>INNER JOIN sys.sysconstraints constraints ON constraints.constid = sysobjcnstr.object_id
>INNER JOIN sys.columns clmns ON clmns.object_id = sysobj.object_id
> AND clmns.column_id = constraints.colid
>WHERE sysobj.NAME ='YourTableName'
> AND clmns.NAME = 'YourColumnName'
>
>
>WHILE @colname IS NOT NULL
> BEGIN
> SET @sql = 'ALTER TABLE YourTableName DROP CONSTRAINT '+@colname
> print @sql
>
>
> SELECT @colname = MIN(sysobjcnstr.NAME)
> FROM sys.objects sysobj
> INNER JOIN sys.objects sysobjcnstr ON sysobj.object_id = sysobjcnstr.parent_object_id
> INNER JOIN sys.sysconstraints constraints ON constraints.constid = sysobjcnstr.object_id
> INNER JOIN sys.columns clmns ON clmns.object_id = sysobj.object_id
> AND clmns.column_id = constraints.colid
> WHERE sysobj.NAME='YourTableName'
> AND clmns.NAME = 'YourColumnName'
> AND sysobjcnstr.NAME > @colname
> END
>
Thank you very much!
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham