Last post Dec 17, 2014 08:33 AM by Rion Williams
Dec 16, 2014 12:32 PM|johnjohn123123|LINK
I want to start a new asp.net mvc web application and I am using sql server 2008 R2. but I am not sure if there are some standards for defining the data types for these values. For example when defining a column which represents Email-address should it be
nvarchar(50) or nvarchar(20)
I need to know if there are some standards for these columns:-
- Email Address.
- Telephone with extension
- First Name & Last name
- Rich text editor .(which can store a description about something)
Dec 16, 2014 01:08 PM|Rion Williams|LINK
I don't know if there are any specific "standard" sizes for these types of fields, but you'll likely want to err on the side of caution as things could be much larger than you might expect (e.g. don't make any assumptions).
I would recommend the following very "rough" estimates, all of which will NVARCHAR or VARCHAR (depending if you need Unicode or not) :
It's important to remember that from a VARCHAR field is only going to take up what it actually needs (space-wise), so erring on the size of larger values wouldn't be a bad idea. This is one of the primary benefits of choosing these over their related CHAR
(and NCHAR) fields.
It looks like the
UK released a catalog of "standards" that they use for these types of fields. It may be worth looking over to get some ideas.
Dec 16, 2014 08:46 PM|johnjohn123123|LINK
thanks alot for the reply.
so erring on the size of larger values wouldn't be a bad idea. This is one of the primary benefits of choosing these over their related CHAR (and NCHAR) fields.
basically i know that NVARCHAR will take up space it only needs. but my main concern is about having a standard data + avoid wrong data. for example i have a field for storing user height in meters, so i chose Decimal(3,2) not to prevent wasted space, but
to make sure i do not get a value such as 10.85 for a user height (he wold be a basketball player for sure :) !! )
Dec 17, 2014 08:33 AM|Rion Williams|LINK
Generally, it's going to be up to your best judgement.
The standards that I provided earlier (from the UK) might be reasonable assumptions that I am sure plenty of work was put into to formulate. It's better to likely err on the side of caution and be able to handle values that might come in (even
though they may be anomalies). You can always simply notify the user if a value that they attempt to enter is too large (for instance your 10+ meter tall individual) and they can simply enter in the maximum allowed value.
Unless your database is going to be storing millions upon millions of records, using a slightly larger level of precision or larger fields isn't going to have a significant impact on size or performance, so it's really again - up to you.