saving strings in mssql databases

S

strangeduck

Guest
If I have a string that a user inputs into a textbox that could be anywhere from 5 characters to 5000, what's the best type to use for that variable in my databases and stored procedures? Right now I'm using nvarchar(1024), but I'm not entirely sure if that's the most efficient way - does that allocate 1024 bytes per string, or just declare a maximum size of 1024 and allocate as necessary? Is there a better way to store them?

Thanks!
 
If you need a length of 5000 and unicode, you will have to use ntext, as the maximum is 4000 characters for nvarchar. Remember that unicode UCS-2 uses more storage space.

Supposedly both text and varchar types only allocated as much space as required. Which seems to be supported by me creating a table with 1000 empty (non-null) varchar fields with max length 8000, without my database significantly increasing in size.
 
Back
Top