BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

VIEWs are not updated correctly after altering underlying ta

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Richard Cox
Guest





PostPosted: Sun Oct 24, 2004 12:04 am    Post subject: VIEWs are not updated correctly after altering underlying ta Reply with quote



I have a view which depends on three tables. The select statement in the
view definition is something like

SELECT A.*, B.Name, C.StartDate FROM A Assignment INNER JOIN B.BusinessUnit
ON...

and so on.

If I add a new field to table A and then perform a SELECT on the view, I see
data values shifted one column to the right or left, so that, for example,
peoples names end up in the date of birth column. I fix the problem by
issuing an ALTER VIEW statement for the view (i.e. a statement which doesn't
modify the view at all, just restates its definition), but this seems rather
weak.

Do I really have to monitor the effect of every change I make to the
structure of the database and issue ALTER VIEW statements to "refresh" then?
Or is there some nifty command somewhere ("File | Refresh Views"? Smile )
which will do this for me?

Many thanks,

Richard Cox.


Back to top
Richard Cox
Guest





PostPosted: Sun Oct 24, 2004 12:07 am    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote



....oops, sorry, forgot to say that I am using MS SQL Server 2000.

<blush>


Back to top
Richard Cox
Guest





PostPosted: Tue Aug 23, 2005 8:16 pm    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote



Ah...this question was either:

a) too stupid to be worth a response, or
b) the answer is so fiendishly complex that noone can formulate it, or
possibly
c) I phrased it badly and noone can understand it.

Would someone take pity on me and let me know which?

Many thanks,

Richard Cox
richard underscore cox at traqs dot com


"Richard Cox" <rpcox (AT) traqs (DOT) com> wrote

Quote:
I have a view which depends on three tables. The select statement in the
view definition is something like

SELECT A.*, B.Name, C.StartDate FROM A Assignment INNER JOIN
B.BusinessUnit
ON...

and so on.

If I add a new field to table A and then perform a SELECT on the view, I
see
data values shifted one column to the right or left, so that, for example,
peoples names end up in the date of birth column. I fix the problem by
issuing an ALTER VIEW statement for the view (i.e. a statement which
doesn't
modify the view at all, just restates its definition), but this seems
rather
weak.

Do I really have to monitor the effect of every change I make to the
structure of the database and issue ALTER VIEW statements to "refresh"
then?
Or is there some nifty command somewhere ("File | Refresh Views"? Smile )
which will do this for me?

Many thanks,

Richard Cox.





Back to top
Kevin Frevert
Guest





PostPosted: Tue Aug 23, 2005 9:10 pm    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote

"Richard Cox" <rpcox (AT) traqs (DOT) com> wrote

Quote:
Ah...this question was either:

a) too stupid to be worth a response, or

No such thing as a stupid question.

Quote:
b) the answer is so fiendishly complex that noone can formulate it, or
possibly

Possible.

Quote:
c) I phrased it badly and noone can understand it.

Would someone take pity on me and let me know which?

d) Not enough info

What databatase are you using?
How does this issue relate to Delphi?

If your using MSSQL, you should never have to go back and 'refresh' a view
if one of the underlying table's structure changes. Oracle or Interbase,
someone else will need to jump in.

Good luck,
krf

Quote:
"Richard Cox" <rpcox (AT) traqs (DOT) com> wrote in message
news:417af182 (AT) newsgroups (DOT) borland.com...
I have a view which depends on three tables. The select statement in the
view definition is something like

SELECT A.*, B.Name, C.StartDate FROM A Assignment INNER JOIN
B.BusinessUnit
ON...

and so on.

If I add a new field to table A and then perform a SELECT on the view, I
see
data values shifted one column to the right or left, so that, for
example,
peoples names end up in the date of birth column. I fix the problem by
issuing an ALTER VIEW statement for the view (i.e. a statement which
doesn't
modify the view at all, just restates its definition), but this seems
rather
weak.

Do I really have to monitor the effect of every change I make to the
structure of the database and issue ALTER VIEW statements to "refresh"
then?
Or is there some nifty command somewhere ("File | Refresh Views"? Smile )
which will do this for me?



Back to top
Richard Cox
Guest





PostPosted: Tue Aug 23, 2005 10:33 pm    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote

Thanks for your reply Kevin.

Quote:
What databatase are you using?

I am talking about MS SQL 2000 - I replied to my own message giving that
information, having realised my original message missed it out.

Quote:
How does this issue relate to Delphi?

I infer that you think I should be asking this question elsewhere. The
question is only related to Delphi insofar as I was using Delphi at the time
I experienced the problem. I'll take the question to
microsoft.public.sqlserver.server.

Richard Cox.






"Kevin Frevert" <kevin (AT) workdrinkingdietcoke (DOT) com> wrote

Quote:
"Richard Cox" <rpcox (AT) traqs (DOT) com> wrote in message
news:430b83f5$1 (AT) newsgroups (DOT) borland.com...
Ah...this question was either:

a) too stupid to be worth a response, or

No such thing as a stupid question.

b) the answer is so fiendishly complex that noone can formulate it, or
possibly

Possible.

c) I phrased it badly and noone can understand it.

Would someone take pity on me and let me know which?

d) Not enough info

What databatase are you using?
How does this issue relate to Delphi?

If your using MSSQL, you should never have to go back and 'refresh' a view
if one of the underlying table's structure changes. Oracle or Interbase,
someone else will need to jump in.

Good luck,
krf

"Richard Cox" <rpcox (AT) traqs (DOT) com> wrote in message
news:417af182 (AT) newsgroups (DOT) borland.com...
I have a view which depends on three tables. The select statement in the
view definition is something like

SELECT A.*, B.Name, C.StartDate FROM A Assignment INNER JOIN
B.BusinessUnit
ON...

and so on.

If I add a new field to table A and then perform a SELECT on the view,
I
see
data values shifted one column to the right or left, so that, for
example,
peoples names end up in the date of birth column. I fix the problem by
issuing an ALTER VIEW statement for the view (i.e. a statement which
doesn't
modify the view at all, just restates its definition), but this seems
rather
weak.

Do I really have to monitor the effect of every change I make to the
structure of the database and issue ALTER VIEW statements to "refresh"
then?
Or is there some nifty command somewhere ("File | Refresh Views"? Smile )
which will do this for me?





Back to top
Martin Brekhof
Guest





PostPosted: Wed Aug 24, 2005 4:40 am    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote


"Richard Cox" <rpcox (AT) traqs (DOT) com> wrote

Quote:
Ah...this question was either:

view definition is something like

SELECT A.*, B.Name, C.StartDate FROM A Assignment INNER JOIN
B.BusinessUnit
ON...
I guess you should replace A.* with the exact fieldnames you need (which is

better pratice anyway).

hth,
Martin



Back to top
Kevin Frevert
Guest





PostPosted: Wed Aug 24, 2005 1:45 pm    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote

"Richard Cox" <rpcox (AT) traqs (DOT) com> wrote

Quote:
Thanks for your reply Kevin.

What databatase are you using?

I am talking about MS SQL 2000 - I replied to my own message giving that
information, having realised my original message missed it out.


Using Enterprise Manager to manage my views, I've never had to refresh
anything to make new fields appear, but in views I rarely issue a 'Select
A.*...'. Microsoft's newsgroups would be a good place to start or check
out..http://www.fulltextsearch.com and search on views, caching, and
execution plan (not sure the best way to enter the keywords). If this is a
problem, you cannot be the first one to run into it.

Good luck,
krf




Back to top
Richard Cox
Guest





PostPosted: Wed Aug 24, 2005 3:50 pm    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote

Whilst in process of creating a very detailed message for one of MS
newgroups, the cause of the problem dawned on me and I found a number of
references on the web - the cause of the problem is, as you say, using
"Select * from...". When the underlying tables change, the view goes with
the old metadata and still expects to find the columns at the original
ordinal position. If they have been rearranged, the data will simply be
wrong.

(If you delete a field from the underlying table, the view becomes
unusable.)

Generating a script for all views, sprocs and functions using Enterpise
Manager and running it should set everything right. Though I will, of
course, stop using "Select * from..." at once!

Many thanks for taking an interest.

Richard.


"Kevin Frevert" <kevin (AT) workdrinkingdietcoke (DOT) com> wrote

Quote:
"Richard Cox" <rpcox (AT) traqs (DOT) com> wrote in message
news:430ba441 (AT) newsgroups (DOT) borland.com...
Thanks for your reply Kevin.

What databatase are you using?

I am talking about MS SQL 2000 - I replied to my own message giving that
information, having realised my original message missed it out.


Using Enterprise Manager to manage my views, I've never had to refresh
anything to make new fields appear, but in views I rarely issue a 'Select
A.*...'. Microsoft's newsgroups would be a good place to start or check
out..http://www.fulltextsearch.com and search on views, caching, and
execution plan (not sure the best way to enter the keywords). If this is
a
problem, you cannot be the first one to run into it.

Good luck,
krf






Back to top
Richard Cox
Guest





PostPosted: Wed Aug 24, 2005 4:06 pm    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote

Yes, as you will see from my reply to Kevin, that was the cause. Thanks.

I wonder why it is considered better practice. Is it because DBMS's don't
handle it well, or because there is something more fundamentally wrong with
the practice? Should someone write (or has someone written) the article
"Create View ... as Select * From ... Considered Harmful"?

Richard.


"Martin Brekhof" <martin (AT) brekhof (DOT) nl> wrote

Quote:

"Richard Cox" <rpcox (AT) traqs (DOT) com> wrote in message
news:430b83f5$1 (AT) newsgroups (DOT) borland.com...
Ah...this question was either:

view definition is something like

SELECT A.*, B.Name, C.StartDate FROM A Assignment INNER JOIN
B.BusinessUnit
ON...
I guess you should replace A.* with the exact fieldnames you need (which
is better pratice anyway).

hth,
Martin




Back to top
Richard Cox
Guest





PostPosted: Wed Aug 24, 2005 4:13 pm    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote

Thanks, Brian. I see that my subject line wording was misleading, since the
question was not about views being updated, but rather the view definitions.

Richard.

"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote

Quote:

a) too stupid to be worth a response, or
b) the answer is so fiendishly complex that noone can formulate it, or
possibly
c) I phrased it badly and noone can understand it.

Would someone take pity on me and let me know which?
It is a very badly worded question.
Views in SQL server 2000 are updateable under some circumstances but I am
not
sure that addresses your question.
--
Brian Bushay (TeamB)
[email]Bbushay (AT) NMPLS (DOT) com[/email]



Back to top
Martin Brekhof
Guest





PostPosted: Thu Aug 25, 2005 5:35 am    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote

Quote:
I wonder why it is considered better practice.
Several issues come to mind:

- performance (select fieldname1, .. from a etc.) requires less parsing
- consistency: a view is a way to present data without requiring updates to
(for example) reports if the underlying database structure changes. Example:
a view presenting a person's data (surname, last name, address etc.) can
hide the fact that because of a developper or dba's decision the table the
view originally used has been split, moved, renamed etc.
- security/need to know: if not everyone needs to see/update all columns in
a table you can create one or more views with a limited exposure of the
contained data.

hth,
Martin



Back to top
Walter Prins
Guest





PostPosted: Sat Aug 27, 2005 8:37 pm    Post subject: Re: VIEWs are not updated correctly after altering underlyin Reply with quote


"Richard Cox" <rpcox (AT) traqs (DOT) com> wrote

Quote:
Yes, as you will see from my reply to Kevin, that was the cause. Thanks.

I wonder why it is considered better practice. Is it because DBMS's don't
handle it well, or because there is something more fundamentally wrong
with the practice? Should someone write (or has someone written) the
article "Create View ... as Select * From ... Considered Harmful"?

Your experience is actually one example of sorts of why it's considered
better. In general in queries you also don't want to use select * from ...
for more or less the same reason -- select * is vulnerable to changes to the
underlying table. I.e. if you add fields to a table against which you
execute select *, you'll get a different number of fields back. This may
break code that expects the original number of fields/layout. More or less
the same thing applies to view definitions on SQL server it seems, as you've
found out...



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.