AndyLee100
Technical User
I am having a discussion with a colleague in the office here regarding text field lengths in databases.
The main discussion is regarding where to control the length of the string that you are entering into the database.
To explain further,
You have a form with a text box and you want to limit the number of characters the user can enter to 30.
So you set the max length property to 30.
But what about the field in the database? Do you as a rule set this to 30 aswell or allow 255 or even the (MAX) field length?
I argue that if you are using VarChar as a data type in your SQL database then SQL will only store the actual length of the string and not pad out the remaining spaces.
If you are using nvarchar then I agree this is a different issue.
The basis of my argument is that you control the length of the data at only one point (ie the application) and not have to worry about changing the database. However my colleague argues that you should also change the length in the database.
Points of view greatly appreciated
Cheers
Andy
The main discussion is regarding where to control the length of the string that you are entering into the database.
To explain further,
You have a form with a text box and you want to limit the number of characters the user can enter to 30.
So you set the max length property to 30.
But what about the field in the database? Do you as a rule set this to 30 aswell or allow 255 or even the (MAX) field length?
I argue that if you are using VarChar as a data type in your SQL database then SQL will only store the actual length of the string and not pad out the remaining spaces.
If you are using nvarchar then I agree this is a different issue.
The basis of my argument is that you control the length of the data at only one point (ie the application) and not have to worry about changing the database. However my colleague argues that you should also change the length in the database.
Points of view greatly appreciated
Cheers
Andy