Sreekala C
Sreekala C

Reputation: 85

Alter column Datatype

I have a table dbo.ExceptionMessage and now I want to change the column datatype nvarchar(100) to nvarchar(MAX). I used alter query for changing this

ALTER TABLE dbo.ExceptionMessage ALTER COLUMN   Address nvarchar(MAX)

and while excecuting this query it shows some error like.

The object 'DF_ExceptionMessage_Address' is dependent on column 'Address'.

ALTER TABLE ALTER COLUMN Address failed because one or more objects access this column.

How can we solve this...

Upvotes: 5

Views: 3395

Answers (4)

shylesh krishna
shylesh krishna

Reputation: 86

thiz help you to alter

   alter table TableName 

     alter column ColumnName nvarchar(200);

Upvotes: 0

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28413

you try first:

ALTER TABLE <tablename> DROP CONSTRAINT <Con_Name>;

And Then Do your Alter

ALTER TABLE dbo.ExceptionMessage ALTER COLUMN   Address nvarchar(MAX)

Again Add Constraint

Upvotes: 0

Amit Bisht
Amit Bisht

Reputation: 5136

First Delete all Constraint Like this

ALTER TABLE TableName DROP CONSTRAINT [DF__TableName__ColumnName__FieldName] 

and then perform change

ALTER TABLE dbo.ExceptionMessage ALTER COLUMN   Address nvarchar(MAX)

then re enter the constraints

Upvotes: 7

user1162766
user1162766

Reputation:

You have to find out which type of constraint DF_ExceptionMessage_Address is, drop it, alter the column type and then re-create the constraint if you need it.

Upvotes: 1

Related Questions