472,811 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 software developers and data experts.

Problem With View and Changing Field Length

I had a strange situation with a view in SQL 7, that I could use some input
on.

I had a very simple view -- select a, b, c from table1 where x=y and z=q.
Field a in table1 originally was varchar 70. A long time ago I changed it to
varchar 95.

I used this view as an ODBC linked table in an Access MDB. Recently, there
was one row which has a value in field a that was more than 70 characters
long. This caused an error when the view as opened in the MDB file: "string
data, right truncation (#0)"

I went to the view in SQL Server, and displayed the row fine. So I delete
the link to the view in Access, compacted the Access database, and recreated
the link. Same results. The row showed #Error in the linked view, and the
message box with the truncation error would come up.

I went into SQL Server, took the SQL from the view and created a new view. I
linked the new view in Access, and it worked fine. No error.

So it seems that, somehow, view was holding onto the old field length, even
though it was using the new field length when displayed. But when the view
was linked, it used the old field length.

Is there something I could have or should have done short of recreating the
view? Any idea why the view used the old field length when it was linked,
but used the new field length when it was opened directly?

Thanks!

Neil
Jun 27 '08 #1
6 6944
Is there something I could have or should have done short of recreating
the view? Any idea why the view used the old field length when it was
linked, but used the new field length when it was opened directly?
View meta data are stored at the time the view is created so subsequent
changes to the underlying objects won't be reflected in the view. After
making changes to tables referenced by views, you'll need to either recreate
the views or execute sp_refreshview against the views to sync the meta data.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"Neil" <no****@nospam.netwrote in message
news:hi****************@nlpi065.nbdc.sbc.com...
>I had a strange situation with a view in SQL 7, that I could use some input
on.

I had a very simple view -- select a, b, c from table1 where x=y and z=q.
Field a in table1 originally was varchar 70. A long time ago I changed it
to varchar 95.

I used this view as an ODBC linked table in an Access MDB. Recently, there
was one row which has a value in field a that was more than 70 characters
long. This caused an error when the view as opened in the MDB file:
"string data, right truncation (#0)"

I went to the view in SQL Server, and displayed the row fine. So I delete
the link to the view in Access, compacted the Access database, and
recreated the link. Same results. The row showed #Error in the linked
view, and the message box with the truncation error would come up.

I went into SQL Server, took the SQL from the view and created a new view.
I linked the new view in Access, and it worked fine. No error.

So it seems that, somehow, view was holding onto the old field length,
even though it was using the new field length when displayed. But when the
view was linked, it used the old field length.

Is there something I could have or should have done short of recreating
the view? Any idea why the view used the old field length when it was
linked, but used the new field length when it was opened directly?

Thanks!

Neil
Jun 27 '08 #2

"Dan Guzman" <gu******@nospam-online.sbcglobal.netwrote in message
news:u7****************@flpi150.ffdc.sbc.com...
>Is there something I could have or should have done short of recreating
the view? Any idea why the view used the old field length when it was
linked, but used the new field length when it was opened directly?

View meta data are stored at the time the view is created so subsequent
changes to the underlying objects won't be reflected in the view. After
making changes to tables referenced by views, you'll need to either
recreate the views or execute sp_refreshview against the views to sync the
meta data.
Thanks. Good to know. Is there a way to run sp_refreshview against all
views, sort of as a global refresh? Or is there a feature in EM that might
do this? Thanks.
Jun 27 '08 #3
Neil (no****@nospam.net) writes:
Thanks. Good to know. Is there a way to run sp_refreshview against all
views, sort of as a global refresh? Or is there a feature in EM that might
do this? Thanks.
SELECT 'EXEC sp_refreshview ' + quotename(name)
FROM sysobjects
WHERE type = 'V'

Copy result into a query window and run it.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 27 '08 #4
Thanks, Erland! Just curious, as more of a theoretical point: why, do you
suppose, SQL Server doesn't reset the metadata when a table's structure has
changed? Seems that if the table structure has changed, the old meta data is
no longer valid. So why not automatically change it?

Thanks.
"Erland Sommarskog" <es****@sommarskog.sewrote in message
news:Xn**********************@127.0.0.1...
Neil (no****@nospam.net) writes:
>Thanks. Good to know. Is there a way to run sp_refreshview against all
views, sort of as a global refresh? Or is there a feature in EM that
might
do this? Thanks.

SELECT 'EXEC sp_refreshview ' + quotename(name)
FROM sysobjects
WHERE type = 'V'

Copy result into a query window and run it.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx

Jun 27 '08 #5
Neil (no****@nospam.net) writes:
Thanks, Erland! Just curious, as more of a theoretical point: why, do
you suppose, SQL Server doesn't reset the metadata when a table's
structure has changed? Seems that if the table structure has changed,
the old meta data is no longer valid. So why not automatically change
it?
I think my answer to that question is that you should put this
suggestion on Connect:
http://connect.microsoft.som/SqlServer/Feedback
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 27 '08 #6

"Erland Sommarskog" <es****@sommarskog.sewrote in message
news:Xn**********************@127.0.0.1...
Neil (no****@nospam.net) writes:
>Thanks, Erland! Just curious, as more of a theoretical point: why, do
you suppose, SQL Server doesn't reset the metadata when a table's
structure has changed? Seems that if the table structure has changed,
the old meta data is no longer valid. So why not automatically change
it?

I think my answer to that question is that you should put this
suggestion on Connect:
http://connect.microsoft.som/SqlServer/Feedback
Ah, so it's not a question of some deep technological mystery, but more of a
deep MS mystery. :-) Thanks!
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Christopher Benson-Manica | last post by:
Why would this code... Date.prototype.addDays=function( days ) { this.setDate( this.getDate()+days ); } ....break the Date constructor? If I don't include it, everything is fine. If I do,...
20
by: Neil | last post by:
I have an Access 2000 MDB file with a SQL 7 back end. I have a main table with 50,000 records; and I have a selections table with 50,000 records for each machine that uses the database (about...
2
by: Sara | last post by:
The problem: Conditional formatting bold, red when field Value < date() sets the field background to white - always - whether condition is met or not. I want the field unfilled and just red/bold...
4
by: Mal Reeve | last post by:
Hello, I have a report that has only 2 levels of grouping. The detail section is simply 1 large block for a memo field. I am finding that on some occasions the report errors and generates...
10
by: db2group88 | last post by:
hi, we are using db2 v8.2 EE on windows, with jcc driver. try to create a join view, after that i check the syscat.columns table, for those decimal field use COALESCE method, all the length become...
3
by: settyv | last post by:
Hi, I need to generate PDF stream when i click on Linkbutton in datagrid ..At present i hardcoded the DMS Id and now it is working.But i need to pass DMS ID when click linkbutton.How can i do...
2
by: John | last post by:
Hi Everyone, I have a question about dynamically changing the length of a varchar(n) field, in case the value I'm trying to insert is too big and will give a "truncated" error, but before the...
17
by: radio1 | last post by:
Configuration: Access 2002 and SQL Server 2000 using a .ADP Project. I would VERY MUCH appreciate anyone's input into this problem I'm having. I have a form in Access that does not permit...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.