November 25, 2010 at 1:46 am
Can somebody please advise me on the best Data Types to use for various Coloums. Im adding the ollowing Coloums to my database:
Post Code
Telephone Number
Mobile Number
Thanks
November 25, 2010 at 2:45 am
Hi,
My recommendations:
Postcode
If you always have same length then use char(<length>). If it can have different lengths like international postcodes, safest is nvarchar(<length>).
Telephone Number, Mobile Number
These can indeed be tricky:
1. One column for country code, one column for area code and one column for the phone number
2. Store the whole as varchar(<length>)
The requirements should help in deciding which alternative to choose.
There are some standard ways to store telephone numbers that handles international numbers, like Microsoft Outlook does, it is good practice to check the input and convert to a uniform format.
Similar choices as for telephone number, either store as whole string, or split it up into the components, like domain, user, etc. Depends on the requirements.
Good practice here also to do at least some basic checkof the format.
Good luck
November 25, 2010 at 4:08 am
Hi thanks for your reply, that all makes good sense. What would you suggest for Dates, I read on a website that SQL Server has:
datetime - From January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds 8 bytes
datetime2 - From January 1, 0001 to December 31, 9999 with an accuracy of 100 nanoseconds 6-8 bytes
smalldatetime - From January 1, 1900 to June 6, 2079 with an accuracy of 1 minute 4 bytes
date - Store a date only. From January 1, 0001 to December 31, 9999 3 bytes
time - Store a time only to an accuracy of 100 nanoseconds 3-5 bytes
datetimeoffset - The same as datetime2 with the addition of a time zone offset 8-10 bytes
timestamp
But I can only find, small datetime, datetime and time stamp!
November 25, 2010 at 4:26 am
da.drew (11/25/2010)
Hi thanks for your reply, that all makes good sense. What would you suggest for Dates, I read on a website that SQL Server has:datetime - From January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds 8 bytes
datetime2 - From January 1, 0001 to December 31, 9999 with an accuracy of 100 nanoseconds 6-8 bytes
smalldatetime - From January 1, 1900 to June 6, 2079 with an accuracy of 1 minute 4 bytes
date - Store a date only. From January 1, 0001 to December 31, 9999 3 bytes
time - Store a time only to an accuracy of 100 nanoseconds 3-5 bytes
datetimeoffset - The same as datetime2 with the addition of a time zone offset 8-10 bytes
timestamp
But I can only find, small datetime, datetime and time stamp!
Looks like you are using SQL 2005, the DATE/TIME and DATETIME2 are new to SQL 2008.
Thanks & Regards,
Nakul Vachhrajani.
http://nakulvachhrajani.com
Follow me on
Twitter: @sqltwins
November 25, 2010 at 5:53 am
Yes, it looks like you are using SQL Server 2005, so you are stuck with either datetime and smalldatetime. Which one to choose depends on the range and precision required. Timestamp is not a datetime in SQL Server (at least not yet) as explained here: timestamp
So timestamp has a different purpose.
Cheers
November 25, 2010 at 9:09 pm
Brigadur (11/25/2010)
Hi,My recommendations:
Postcode
If you always have same length then use char(<length>). If it can have different lengths like international postcodes, safest is nvarchar(<length>).
Telephone Number, Mobile Number
These can indeed be tricky:
1. One column for country code, one column for area code and one column for the phone number
2. Store the whole as varchar(<length>)
The requirements should help in deciding which alternative to choose.
There are some standard ways to store telephone numbers that handles international numbers, like Microsoft Outlook does, it is good practice to check the input and convert to a uniform format.
Similar choices as for telephone number, either store as whole string, or split it up into the components, like domain, user, etc. Depends on the requirements.
Good practice here also to do at least some basic checkof the format.
Good luck
I absolutely agree with the splits on telephone number. Keep in mind that many international numbers have a CITY code, as well. Then, there are countries (Mexico, for sure) that also have zone numbers.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 25, 2010 at 9:12 pm
Nakul Vachhrajani (11/25/2010)
da.drew (11/25/2010)
Hi thanks for your reply, that all makes good sense. What would you suggest for Dates, I read on a website that SQL Server has:datetime - From January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds 8 bytes
datetime2 - From January 1, 0001 to December 31, 9999 with an accuracy of 100 nanoseconds 6-8 bytes
smalldatetime - From January 1, 1900 to June 6, 2079 with an accuracy of 1 minute 4 bytes
date - Store a date only. From January 1, 0001 to December 31, 9999 3 bytes
time - Store a time only to an accuracy of 100 nanoseconds 3-5 bytes
datetimeoffset - The same as datetime2 with the addition of a time zone offset 8-10 bytes
timestamp
But I can only find, small datetime, datetime and time stamp!
Looks like you are using SQL 2005, the DATE/TIME and DATETIME2 are new to SQL 2008.
Of course, "It Depends", but I normally recommend not splitting date and time for most things. You usually end up just having to put then back together.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 30, 2010 at 4:41 am
My opinion abt this problem is
1) Postcode : nvarchar datatype will do the purpose
2) Mobile/Phone No: Go for numeric datatype , if it is having only numeric data.
3) Email: Go for varchar itself.
November 30, 2010 at 6:57 am
Junglee_George (11/30/2010)
My opinion abt this problem is1) Postcode : nvarchar datatype will do the purpose
2) Mobile/Phone No: Go for numeric datatype , if it is having only numeric data.
3) Email: Go for varchar itself.
I agree but just so folks don't make a mistake... the reason why it's ok to use something like BIGINT for a whole phone number is because phone numbers aren't supposed to have leading zeros. Don't ever use a numeric datatype for something like a Zip code or a Social Security Number even if they contain only numeric digits because both of those (and many other things) contain leading zeros which will be lost because numeric datatypes don't preserve leading zeros.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply