Results 1 to 5 of 5

Thread: text data type

  1. #1
    Join Date
    Feb 2007
    Posts
    42

    Unanswered: text data type

    visual studio 2005 what is the differences between text, varchar and nvarchar data types in ms sql server? when and when not to use them?

  2. #2
    Join Date
    Mar 2007
    Location
    Holmestrand, Norway
    Posts
    332
    Varchar is a string of varying length, up to 8000 characters. Nvarchar is a unicode edition of Varchar, up to 4000 characters. Text is a CLOB (Character Large Object) that can contain up to 2GB of text, and the NText is a unicode edition that can hold 1G characters. Note however that SQL Server 2005 also have got (n)varchar(max) (also seen as n(varchar(-1)) which is a varchar-implementation of n(text). In SQL Server 2005 (n)text is deprecated, and you should use (n)varchar(max) instead.

    And now, It's time to be dead honest. If you do not know what the basic datatypes are and how they work, you most likely does not know the deatails of how primary keys work, clustered and nonclustered indexes and so on. Thus, It would actually be beneficial if you handed the creation of tables to someone posessing these skills. Otherwise, I'm afraid that you might get a solution performing poorly, and consuming a lot more space than neccessary.

  3. #3
    Join Date
    Feb 2007
    Posts
    42
    ok.. so, if i have basic info fields like email, name, address and the like, what is the appropriate data type to use? nvarchar? tnx for your help

  4. #4
    Join Date
    Mar 2007
    Location
    Holmestrand, Norway
    Posts
    332
    Basically, it depends. Should the database store names of people with english names only? If so varchar is the best choice. However, there are more obscure letters than a-z around the world, as i my last name Bangås or in an icelandic name like Þorvaldur. If you should take these in account as well, you'll have to go for navarchar. When it comes to address, the story repeats itself. There is no problem storing for instance London as the city, but the lovely Lithuanian town named Trakų is. For email addresses it should be fairly safe with varchar though, but some people have fairly long email addresses, so I think I would go for varchar(60) or longer.

    Finally, whatever you do, limit the size of all (n)varchar fields, or you might end up running a query making tempdb go full.

  5. #5
    Join Date
    Feb 2007
    Posts
    42
    now, i really understand! ac2ally, that's also how i understand data type articles over the net! tnx a lot..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •