SQL Server, VIEW has mixed up data -
my team , using microsoft sql server 2014 - standard edition (64-bit)
we have created views do, work(ed) while coding , testing.
then suddenly, 1 of our qa noticed data in application mixed up, example, description data in name field, name sex supposed be, etc.
we cheched data in tables , correct, checked view, querying view select * view , realized view had data mixed up.. next logic step check view queries, our surprise queries correct. happening?
well, question, why data in view corrupt or mixed if queries within view correct , working long time?
we altered view, not modifying , fixed issue.
but, need know cause of data corruption, because don't want monitor , alter views time.
view code requested
alter view [dbo].[pvvclient] select * table inner join table 2 on.....
the first thing came mind table(s) has changed , raised behavior, think schemabinding can avoid kind of issues
when put * in column list of view , underlying tables change view not automatically update include changed columns. in fact, if delete column can data mixed across columns. has been discussed , documented many times. aaron bertrand has great article covering topic. http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/10/bad-habits-to-kick-using-select-omitting-the-column-list.aspx
moral of story, avoid using select * unless select inside exists.
Comments
Post a Comment