First of all, you don't need to modify anything in view. Any change in corresponding table will automatically reflect in your view.
If not, it might be because if a view is not created with schemabinding
, sp_refreshview
should be run when changes are made to the objects underlying the view that affect the definition of the view. Otherwise, the view might produce unexpected results when it is queried. SO as suggested by @Ralf, I +1 that answer, use sp_refreshview
to update view.
For your comment ALTER TABLE ALTER COLUMN Company failed because one or more objects access this column.
This is because some constraint or index is using that column you have to first drop that and then only you might be able to alter that column.
You can find related constraint using query:
select db_name() as CONSTRAINT_CATALOG
,t_obj.name as TABLE_NAME
,user_name(c_obj.uid) as CONSTRAINT_SCHEMA
,c_obj.name as CONSTRAINT_NAME
,col.name as COLUMN_NAME
,col.colid as ORDINAL_POSITION
,com.text as DEFAULT_CLAUSE
from sysobjects c_obj
join syscomments com on c_obj.id = com.id
join sysobjects t_obj on c_obj.parent_obj = t_obj.id
join sysconstraints con on c_obj.id = con.constid
join syscolumns col on t_obj.id = col.id
and con.colid = col.colid
where
c_obj.uid = user_id()
Drop any index and/or constraint on column & then try alter, it must work then.
Also refer answers to this question Drop a column from table problem (SQL Server 2008)
Hope it helps.