• yakko_Warner (10/26/2016)


    I'm working on a project with a co-worker and I was working on creating a database for some integration of data for his workflow.

    I was trying to figure out the max length that my varchar(n) would need to be and during that discussion he tells me well, that his database via Entity Framework by default just creates all strings as nvarchar(max). To which I thought I remembered seeing various articles about potential performance hits if the string goes over 8K bytes/4k Chars (if all of the unicode chars are below the values where they jump to 4bytes/value) i.e. stored off page values, and cpu overhead due to the extra 24bits needed etc.

    Is this still an issue? I have read many thing various places stating that why do you need for instance unlimited string lengths for a FirstName.

    He is under the impression that after if the database resides on a SQL 2012 or better that using nvarchar(max) isn't anything to worry about if it's storing less then 4k characters (not being stored off page).

    I'm just thinking that just the extra byte per character is storage issue when scaled up by not using varchar(n/max)

    Is that right?

    Thanks in advance.

    From my personal experience.

    On one reasonably big database (of a GPS provider) I've managed to cut query response time (on average) by 7 times simply by redefining all NVARCHAR(MAX) columns as NVARCHAR(500) (all actual strings in there were not longer than 250 characters).

    7 times.

    With no index tuning, without even seeing a single line of code.

    _____________
    Code for TallyGenerator