Changing the size of a column referenced by a schema-bound view in SQL Server

Viewed 447655

I'm trying to change the size of a column in sql server using:

ALTER TABLE [dbo].[Address]
ALTER COLUMN [Addr1] [nvarchar](80) NULL

where the length of Addr1 was originally 40.

It failed, raising this error:

The object 'Address_e' is dependent on column 'Addr1'.
ALTER TABLE ALTER COLUMN Addr1 failed because one or more objects access 
this column.

I've tried to read up on it and it seems that because some views are referencing this column and it seems that SQL Server is actually trying to drop the column that raised the error.

Address_e is a view created by the previous DB Administrator.

Is there any other way I can change the size of the column?

6 Answers
ALTER TABLE [table_name] ALTER COLUMN [column_name] varchar(150)

here is what works with the version of the program that I'm using: may work for you too.

I will just place the instruction and command that does it. class is the name of the table. you change it in the table its self with this method. not just the return on the search process.


view the table class

select * from class

change the length of the columns FacID (seen as "faci") and classnumber (seen as "classnu") to fit the whole labels.

alter table class modify facid varchar (5);

alter table class modify classnumber varchar(11);

view table again to see the difference

select * from class;

(run the command again to see the difference)


This changes the the actual table for good, but for better.

P.S. I made these instructions up as a note for the commands. This is not a test, but can help on one :)

Related