View column datatypes

  • How does SQL 2005 decide what datatype to give a column?

    I want SQL to use unicode data types, but it uses varchar instead of nvarchar for the view.

    Can I force it to use nvarchar?

  • Hi ;

    I suggest this :

    CREATE VIEW [Students_vw] (NAME , Surname)

    AS

    SELECT CAST([Name] AS NVARCHAR(50)) , CAST([Soyad], AS NVARCHAR(50))

    FROM Students

  • The data type of columns in a view will be the data type of the columns in the underlying table, unless there's a CAST/Convert used.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • If the data type of the underlying table is VARCHAR, why would you want to double the size of the returned data in the view and wreck any of your indexes? You do not have a possibility of having anything not supported by the underlying data type.

  • Yes, you can force a view to use a different data type than the underlying table. The question is, why would you? It won't gain you anything at all in this case.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply