Feckmore
Feckmore

Reputation: 4714

View changes nvarchars to varchars in SQL Server 2008

I have a view in a SQL Server 2008 db that simply exposes about 20 fields of one table to be consumed via ODBC to a client. When I tried to replicate this view in another database, the client could not consume the data source.

Then I noticed some weirdness. The columns in the view are shown, in SQL Server Management Studio, to be varchar(100), while the columns in the table are defined as nvarchar(100). There are no CAST or CONVERT statements in the view, it is a simple SELECT statement.

Example:

Table -> Columns:

Desc1 (nvarchar(100), null)

View -> SELECT TOP 100 PERCENT Desc1 FROM... Columns:

Desc1 (varchar(100), null)

Any ideas why the columns are defined as varchar in the view instead of nvarchar?

Upvotes: 1

Views: 112

Answers (3)

gbn
gbn

Reputation: 432271

One answer would be the view definition is out of date

Try sp_refreshview and consider WITH SCHEMABINDING

Upvotes: 3

SQLMenace
SQLMenace

Reputation: 135021

Run sp_refreshview and see if that fixes it, also take a look at how to make sure that the view will have the underlying table changes by using sp_refreshview

Upvotes: 2

user151323
user151323

Reputation:

That happens when somebody updates a table but forgets to update the view.

Update the view. Just open it in SSMS as UPDATE VIEW and run it.

Upvotes: 3

Related Questions