Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Changing col Text to Varchar(max)
Message
General information
Forum:
Microsoft SQL Server
Category:
Database management
Miscellaneous
Thread ID:
01676732
Message ID:
01676740
Views:
32
>>>>
>>>>       DECLARE @aaa varchar(200)
>>>>       SELECT  @aaa = OBJECT_NAME(constid) FROM sysconstraints WHERE OBJECT_NAME(Id) = 'YourTableName' AND OBJECT_NAME(constid) LIKE '%YourColumnName%'
>>>>       IF @aaa IS NOT NULL
>>>>          BEGIN
>>>>              SET @aaa = 'ALTER TABLE YourTableName DROP CONSTRAINT '+@aaa
>>>>              EXEC (@aaa)
>>>>          END
>>>>
>>>>
>>>>       ALTER TABLE YourTableName ALTER COLUMN ....
>>>>
>>>
>>>Borislav,
>>>
>>>Thank you very much! You code works. However the resulting column loses the default constraint and accepts NULL.
>>>Do I have to create the default constraint, after your code, and then Alter the column and remove the NULL?
>>
>>DROP constraint first if it exists, create not nullable column with the default constraint (you can use the same name for constraint as before)
>
>Thank you.

You could define your column with the ALTER TABLE command:
ALTER TABLE ... ALTER COLUMN .... varchar(max) NOT NULL CONSTRAINT DF_TableName_ColumName DEFAULT ''
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform