nvarchar vs int :(

  • I use nvarchar field to identify records in a database table due to an Identity Field is used as Primary Key.

    My partner considers we must change our model to use the primary key as the way to identify my records but this is not a constant value. He told me this model has lot performance problems.

    I don’t think so, because this table doesn’t grow, it just has at most 100 rows.

    I want to know if with this model I could have significant performance problems.

    The problem is if I must change this model I need to change a lot code to fix this issue. I need a good reason to continue with my model because we are in the project timeline

    Thanks a lot [Smile]

  • are you saying that the primary key on your table is a nvarchar?

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • How about showing us what your are talking about? Could you post the DDL for the table and some sample data?

  • My table primary key is an int and it is a identity field, for this reason I using another column to identify the rows.

    Some thing like this:

    Table: Language

    Columns:

    LanguageId (int, pk)

    Code (nvarchar(30)) --> I am using this column

    My current database has 654 tables and i just need to manage one table in this way. 🙁

  • I want to know if I use this nvarchar column in sql queries, to identify the rows, has performance problems

    Thanks!

  • Sorry , I forgot the example

    LanguageId CodeDescriptionFrDescriptionEn

    195 de NULL German

    196 el NULL Greek

    197 en NULL English

  • Is the code column defined as nvarchar(2) or something else? If all your codes are 2 characters you should use nchar(2).

    Do you mean you are using the code column to define foreign key relationships to this table? Or, are you using it in WHERE clauses?

  • arluna (11/19/2008)


    I want to know if I use this nvarchar column in sql queries, to identify the rows, has performance problems

    Shouldn't, as long as it's indexed

    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
  • Yes, but I have a restriction about this; I just can manage 5 nvarchar sizes for the current project:

    S: 30, M:50, L:100,XL:250,XXL:2000, it’s a standard.

    This column is not a FK, I am using this column to identify rows in where clauses. I think it does not have a performance problem but I need a second opinion to defend my point of view

    Thank you!

  • Like Gail said, if you have it indexed properly there is no reason not to use it in a where clause.

  • Thanks a lot!

Viewing 11 posts - 1 through 11 (of 11 total)

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