SQL Server: Views that use SELECT * need to be recreated if the underlying table changes -
is there way make views use select * stay in sync underlying table.
what have discovered if changes made underlying table, columns selected, view needs 'recreated'. can achieved simly running alter view statement.
however can lead pretty dangerous situations. if forgot recreate view, not returning correct data. in fact can returning messed data - names of columns wrong , out of order.
nothing pick view wrong unless happened have covered test, or data integrity check fails. example, red gate sql compare doesn't pick fact view needs recreated.
to replicate problem, try these statements:
create table foobar (bar varchar(20)) create view v_foobar select * foobar insert foobar (bar) values ('hi there') select * v_foobar alter table foobar add baz varchar(20) select * v_foobar drop view v_foobar drop table foobar
i tempted stop using select * in views, pita. there setting somewhere perhaps fix behaviour?
you should stop using select *. can lead "pretty dangerous" situations.
however, alternative, can make views schema bound. way won't able change underlying table without re-creating view.
Comments
Post a Comment