Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Changing col Text to Varchar(max)
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Maintenance bases de données
Divers
Thread ID:
01676732
Message ID:
01676740
Vues:
31
>>>>
>>>>       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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform