Results 1 to 4 of 4

Thread: [RESOLVED] SQL field size concerns

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Resolved [RESOLVED] SQL field size concerns

    I am changing my database system from ACCESS to SQL. I am currently setting up the database and have some confusion over field size, for those fields that the size can be set.

    I have selected Nvarcar() to use for my text fields. This field can have the size set from a minimum number of characters all the way up to MAX. I am completely unclear on how much memory is set aside, and the amount that can be used.

    My understanding of the setting for field size is that for whatever value is placed in the parenthesis, there is a 2 byte (1char) amount of memory set aside for every record created. It is also my understanding that whatever value I place within the parenthesis, up to and including MAX, is the maximum amount of memory that a field can use.

    I would like to set some of my text fields to Nvarcar(MAX), but I have been unable to get a number for the minimum memory set aside for this, and what the maximum amount of memory is. I don't mind a record being a memory hog, but I don't want to leave a whole lot of memory on the table that is not being used.

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,261

    Re: SQL field size concerns

    SQL is not a Database.
    do you mean MS SQL Server?

    NVARCAR is not a datatype. Do you mean NVARCHAR?

    What do you want with a minimum size? If a field has no entry it‘s NULL (if allowed)
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: SQL field size concerns

    That's why you use a nvarchar and not a nchar field ... If you define a field as nchar(10) ... it's going to take up 10 bytes no matter what size you fill it with... even if it's "Hi" it'll take up the same space as "Hello" ...

    nvarchars on the other hand vary... that's what the var means. using nvarchar(10) as an example... It take as much as it needs to UP TO the specified length. So now "Hi" (2) and "Hello" (5) take up as much space as they need to, and nothing more. Now, that's not to suggest everything should be nvarchar(MAX) ... be reasonable ... If you've got a field that can only be so long (let's say StateCode for instance, which can only be 2 characters long) then use nvarchar(2) ... so be reasonable with your lengths ... not everything needs to be a MAX length.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Re: SQL field size concerns

    Thanks, that completely eliminates my concerns. Especially good to know that nchar() does not operate the same as nvarchar(). I use MAX only for fields in some tables that a user might want to stuff in a large amount of content. I try to keep that limited. On the other hand, for tables that I use for comboboxes that only contain a few records, I don't worry about how much MAX is.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width