Tuesday, February 14, 2012

Corrupted view

Some days ago I created a view on a sqlserver database, that returns the
price and some other infos of invoice items. everything worked fine.
Now, the view didn't return the same as when I created it. The price
column of the returned record set showed the invoice date instead of the
price and some other columns also contained wrong information.
After recreating the view everything was fine again.
How can this happen?
Cheers
FerdinandFerdinand,
Did someone change the underlying table definitions? If so, run
sp_refreshview 'viewname' to get the view resynchronized with the underlying
tables.
RLF
"Ferdinand Zaubzer" <ferdinand.zaubzer@.schendl.at> wrote in message
news:OkORyxYuHHA.4540@.TK2MSFTNGP05.phx.gbl...
> Some days ago I created a view on a sqlserver database, that returns the
> price and some other infos of invoice items. everything worked fine.
> Now, the view didn't return the same as when I created it. The price
> column of the returned record set showed the invoice date instead of the
> price and some other columns also contained wrong information.
> After recreating the view everything was fine again.
> How can this happen?
> Cheers
> Ferdinand|||The explanation was given by Russell.
I strongly suggest you remove any * from the selection list in the
view's definition. Apart from the side effects in the view when adding
columns to the specific table, it is considered a bad practice to use
SELECT * in views in production code.
Gert-Jan
Ferdinand Zaubzer wrote:
> Some days ago I created a view on a sqlserver database, that returns the
> price and some other infos of invoice items. everything worked fine.
> Now, the view didn't return the same as when I created it. The price
> column of the returned record set showed the invoice date instead of the
> price and some other columns also contained wrong information.
> After recreating the view everything was fine again.
> How can this happen?
> Cheers
> Ferdinand

No comments:

Post a Comment