4000 varchar field - efficient if 6 char or 600 used?

  • Using SQL 7

    Question: will the database automatically truncate the field to the size of the data stored in it, or will every entry/field have potentially 4000 empty characters and also have the potential to run slow when lots of data is stored and retrieved? 

    I'm storing data that could be 1-4000 characters and presumably most data will be much smaller than 4000 characters.  I just don't want to run into problems with speed and efficiency after a few thousand (tens of thousands?) records are entered, but obviously like having the flexibility of not limiting it to 300-500 characters or having multiple tables to deal with.

    Thanks in advance.

    Jason

  • Varchar will only store the actual data removing trailing white space, conserving diskspace in the process.

     

     

  • quoteVarchar will only store the actual data...

    True.

    declare @test-2 varchar(4000)

    set @test-2='abc   '

    will only store 6 characters (plus small overhead for string length)

    quote...removing trailing white space...

    False.

    declare @test-2 varchar(4000)

    set @test-2='abc   '

    will store 6 chars including the 3 trailing spaces

    select datalength(@test) will return 6

    quoteconserving diskspace in the process

    True.

    char(4000) will store 4000 characters and will pad with trailing spaces declare @test-2 char(4000)

    set @test-2='abc '

    will store 4000 chars including the trailing spaces

    select datalength(@test) will return 4000

    Note len returns the length of varchar ignoring trailing spaces

    declare @test-2 varchar(4000)

    set @test-2='abc '

    select len(@test) will return 3

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Please don't cross post: http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=169&messageid=220550 

    People look at many forums. 

    Thanks

    I wasn't born stupid - I had to study.

  • Are you trying to start an infinite loop???

    Post the link back to this post but not from this one to the cross one .

  • Scroll down for answer...

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    Scroll up for answer...

    I wasn't born stupid - I had to study.

  • lol, nice one Farrell.

    About time someone got one up on remi

    Far away is close at hand in the images of elsewhere.
    Anon.

  • You think I'm actually stupid enough to fall for that one???

  • At least not a third time.... 

     

    (lighten up.., I was only kidding...  bully   ) 

    I wasn't born stupid - I had to study.

  • I know... wanted to increase the post count by one more .

  • We all can do that

    Far away is close at hand in the images of elsewhere.
    Anon.

  • We can?   

     

    (poor Jason Carlson if he is getting emailed on this...) 

     

    I wasn't born stupid - I had to study.

  • Who is he?

Viewing 13 posts - 1 through 12 (of 12 total)

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