Standard Data Types for Web Addresses, Phone Numbers?
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
28 replies · 3K views
Discussion
Physics news on Phys.org
Science Advisor
Homework Helper
- 16,220
- 4,934
No standards in this jungle. E.g. for phone numbers the forms (or whatever) designers usually take their local favorite and thus exclude the rest of the world. Same with addresses, date/time, etc. etc.
Side note: I had fun long ago discovering that the default data type for windows forms text boxes turned out to be currency !
As Georgie says: What else
?
Side note: I had fun long ago discovering that the default data type for windows forms text boxes turned out to be currency !
As Georgie says: What else
Mentor
- 38,145
- 10,746
Strings?WWGD said:Hi All,
Just curious: what kind of data types does one usually use for web addresses, for phone numbers?
Thanks.
Phone numbers are really strings of digits. US phone numbers are 10 digits (not including the 1 prefix). International phone numbers are 12 digits, including the two-digit country prefix, but not including the + prefix that you sometimes see.
By "web address" do you mean the URL of a web page, and not an e-mail address?
Science Advisor
Homework Helper
- 7,849
- 13,168
Thanks; is it possible to store the webpage as a link in MSSQL 2014, i.e., so that one can double-click in the DB and access the page?Borg said:If you're referring to how to store them in a database, it would probably have to be as some form of a string like varchar.
Science Advisor
Homework Helper
- 7,849
- 13,168
Now that you mention it, I mean both.Mark44 said:Strings?
Phone numbers are really strings of digits. US phone numbers are 10 digits (not including the 1 prefix). International phone numbers are 12 digits, including the two-digit country prefix, but not including the + prefix that you sometimes see.
By "web address" do you mean the URL of a web page, and not an e-mail address?
Mentor
- 38,145
- 10,746
For web pages, I'm not aware of any particular format. For an e-mail address there is the user portion (the part before @) and the domain name (after @), which can include a subdomain. This is something I used to work with, but it's been awhile.WWGD said:Now that you mention it, I mean both.
newjerseyrunner
- 1,532
- 637
There absolutely are standards, I was an engineer for multiple telecom systems sold all over the world. For web addresses, refer to RFC7230 and use varchar(8000) and for phone numbers refer to RFC3966 and use varchar(22);BvU said:No standards in this jungle. E.g. for phone numbers the forms (or whatever) designers usually take their local favorite and thus exclude the rest of the world. Same with addresses, date/time, etc. etc.
Science Advisor
- 928
- 481
I usually work with PHP / MySQL and although I prefer to do as many things as I can inside the database - create stored procedures, triggers etc. wherever I have the chance to do it, most things are usually done through server side scripting. As mentioned above, varchar is the preferred data type for phone numbers, for they may contain symbols as well. For web addresses, you can store them as varchar too and create the links "on the fly" - as we usually say, through scripting.
Last edited:
Silicon Waffle
- 160
- 202
It depends.WWGD said:Hi All,
Just curious: what kind of data types does one usually use for web addresses, for phone numbers?
EDIT: I am using MSSQL 2014 .
Thanks.
If your web addresses are something like google.com, physicsforums.com etc then it would definitely be varchar(Max value defined in RFC)
In case they are something like 12.34.56.78 and you need to store a millions to billions of them, then a single separate table with tinyint types may be preferred. A script or some methods need to be used then to construct the requested address.
For the phone numbers, it is almost the same, you might probably need to head into int types but some numbers like 1800-CALL-ME will surely ask you to make use of a bit of extra memory to store the strings under consideration.
256bits
Gold Member
- 4,270
- 2,283
Silicon Waffle said:but some numbers like 1800-CALL-ME
Such numbers are not unique - how would one handle conflicts and testing.
newjerseyrunner
- 1,532
- 637
Normalize it before putting it in the database and doing and queries on it, make that your primary key. Add another field for the way the user provided the number.256bits said:Such numbers are not unique - how would one handle conflicts and testing.
Science Advisor
Homework Helper
- 7,849
- 13,168
Agree, of course there should be a format, a single standard used, same as with dates and all other fields.newjerseyrunner said:Normalize it before putting it in the database and doing and queries on it, make that your primary key. Add another field for the way the user provided the number.
Science Advisor
Homework Helper
Gold Member
- 5,020
- 3,264
I think you are confusing the database engine with whatever GUI front end tool you are using.WWGD said:Thanks; is it possible to store the webpage as a link in MSSQL 2014, i.e., so that one can double-click in the DB and access the page?
Science Advisor
Homework Helper
- 7,849
- 13,168
Sorry, I quoted your post but somehow replied to a different one. Senility happening earlier than I expected :(.newjerseyrunner said:Normalize it before putting it in the database and doing and queries on it, make that your primary key. Add another field for the way the user provided the number.
Science Advisor
Homework Helper
- 7,849
- 13,168
Sorry to bother you all again, how about sthe data type for street addresses, is this also a varchar(n)? Addresses always gave me problems in terms of normalizing; not clear where they begin, where they end, unless maybe if there is a general format, e.g., street number street name, etc.
newjerseyrunner
- 1,532
- 637
I would usually break it up before putting it in, provide different text boxes to ask the user for each part of the address, usually:
AddressLine1 (1600 Pennsylvania Ave)
AddressLine2 (Suite 1B)
City (Washington)
State/Province (DC)
Zip/Postal (20500)
Country (United States)
AddressType (Home)
Trying to take it in all at once and parse it is possible, but it'd be difficult, especially if you have to dealt with international addresses.
I would make each of the a varchar except for AddressType, for which I would create an enumeration.
AddressLine1 (1600 Pennsylvania Ave)
AddressLine2 (Suite 1B)
City (Washington)
State/Province (DC)
Zip/Postal (20500)
Country (United States)
AddressType (Home)
Trying to take it in all at once and parse it is possible, but it'd be difficult, especially if you have to dealt with international addresses.
I would make each of the a varchar except for AddressType, for which I would create an enumeration.
Science Advisor
Homework Helper
- 7,849
- 13,168
Thanks; wouldn't international addresses have the nchar() type?newjerseyrunner said:I would usually break it up before putting it in, provide different text boxes to ask the user for each part of the address, usually:
AddressLine1 (1600 Pennsylvania Ave)
AddressLine2 (Suite 1B)
City (Washington)
State/Province (DC)
Zip/Postal (20500)
Country (United States)
AddressType (Home)
Trying to take it in all at once and parse it is possible, but it'd be difficult, especially if you have to dealt with international addresses.
I would make each of the a varchar except for AddressType, for which I would create an enumeration.
newjerseyrunner
- 1,532
- 637
Good catch, but we're both wrong. Use nvarchar.WWGD said:Thanks; wouldn't international addresses have the nchar() type?
varchar doesn't support unicode, so you don't want to use that for international.
nchar however, is fixed length and will cause your database to grow quickly.
nvarchar both grows dynamically and supports unicode.
Science Advisor
- 928
- 481
It is generally a good idea to break the address into parts for input, as newjerseyrunner said and depending on your database design, it is a good idea to have the addresses in a separate table with foreign key e.g. the surname - or what helps more, as you may have two or more addresses per person and have separate columns for each part of the address. As for the data type, usually varchar is convenient, because you may have numbers with letters and/or symbols and you don't need anyway to carry any arithmetic operations on them.
Science Advisor
- 928
- 481
For international addresses, use nvarchar rather than varchar, in order to avoid coding conversions for each read / write on the database.
EDIT: Here of course I'm talking specifically about MSSQL Server.
EDIT: Here of course I'm talking specifically about MSSQL Server.
Last edited:
Science Advisor
Homework Helper
Gold Member
- 5,020
- 3,264
99% of people using a MS SQL Server database access it via a bespoke application and 99% of the remainder through ODBC. SQL Server Management Studio is not designed as an end-user tool.WWGD said:Thanks; I thought there was a default choice of GUI; not sure the name, but I thought there was one.
Usually best to have the address table keyed on an IDENTITY column and use that as a foreign key in the People table. It is generally a bad idea to use a data column as a foreign "key" because it is difficult to ensure (i) uniqueness (what happens when two people have the same surname?) and (ii) immutability (what happens when someone changes their surname)?QuantumQuest said:It is generally a good idea to break the address into parts for input, as newjerseyrunner said and depending on your database design, it is a good idea to have the addresses in a separate table with foreign key e.g. the surname - or what helps more, as you may have two or more addresses per person and have separate columns for each part of the address. As for the data type, usually varchar is convenient, because you may have numbers with letters and/or symbols and you don't need anyway to carry any arithmetic operations on them.
I have never regretted the decision to use an IDENTITY column as a primary key for every table (except usually the joining table in many-to-many relationships). I use a common name (Id) but some people include the table name or a singular version of it (e.g. People.PersonId).
Code:
CREATE TABLE Addresses
(
Id int NOT NULL,
CONSTRAINT PK_Addresses_Id PRIMARY KEY CLUSTERED (Id)
);
Science Advisor
- 928
- 481
MrAnchovy said:Usually best to have the address table keyed on an IDENTITY column and use that as a foreign key in the People table. It is generally a bad idea to use a data column as a foreign "key" because it is difficult to ensure (i) uniqueness (what happens when two people have the same surname?) and (ii) immutability (what happens when someone changes their surname)?
I just gave an example of something very usually done. Of course you can choose another way to design your database, but I don't really understand what you mean by "uniqueness" on the foreign key. There is no such need for foreign keys. And also I can't see where do you find any immutability issue.
QuantumQuest said:it is a good idea to have the addresses in a separate table with foreign key e.g. the surname - or what helps more
If "surname" does not help then another column can be chosen accordingly to the specific needs.
Science Advisor
Homework Helper
Gold Member
- 5,020
- 3,264
And in my experience very often corrected years later at vast expense.QuantumQuest said:I just gave an example of something very usually done.
What happens when there are two people with the surname "Smith"?QuantumQuest said:I don't really understand what you mean by "uniqueness" on the foreign key. There is no such need for foreign keys.
What happens when Mary Smith gets married and changes her name to Mary Jones?QuantumQuest said:And also I can't see where do you find any immutability issue.
What happens when the specific needs change?QuantumQuest said:If "surname" does not help then another column can be chosen accordingly to the specific needs.
If you use an IDENTITY column (or the equivalent in other SQL dialects) the answer to all three of these questions is "nothing, it all still works".
Science Advisor
Homework Helper
Gold Member
- 5,020
- 3,264
Just realized I missed the vital keyword out of this code:
MrAnchovy said:(although CLUSTERED is the default for a PRIMARY KEY I specify it out of habit so that it throws an error if another clustered key exists: for performance reasons you want your primary key to be the unique clustered index for a table).Code:CREATE TABLE Addresses ( Id int IDENTITY NOT NULL, CONSTRAINT PK_Addresses_Id PRIMARY KEY CLUSTERED (Id) );
Science Advisor
- 928
- 481
@MrAnchovy: I don't want to go further on this discussion, because it is off topic. But just because you obviously do not understand what I wrote
I don't know about your experience, but every professional who deals with databases, simply knows that any design depends on the problem at hand with its very details and there are various ways to think of it. There is no magic recipe that fits everything.
You say the same thing that I answered before. I see a clear misunderstanding of foreign keys.
There are various routines and database constructs to handle this through a foreign key. Trivially known.
I did not mean that you change anything according to needs, but choose it properly in the first place. But to answer this also, I use to create flexible designs.
As a final comment, if you believe that you have found a magic recipe then it's ok for me. But what I described for OP to use, are all tested through years and work fine.
MrAnchovy said:And in my experience very often corrected years later at vast expense.
I don't know about your experience, but every professional who deals with databases, simply knows that any design depends on the problem at hand with its very details and there are various ways to think of it. There is no magic recipe that fits everything.
MrAnchovy said:What happens when there are two people with the surname "Smith"?
You say the same thing that I answered before. I see a clear misunderstanding of foreign keys.
MrAnchovy said:What happens when Mary Smith gets married and changes her name to Mary Jones?
There are various routines and database constructs to handle this through a foreign key. Trivially known.
MrAnchovy said:What happens when the specific needs change?
I did not mean that you change anything according to needs, but choose it properly in the first place. But to answer this also, I use to create flexible designs.
As a final comment, if you believe that you have found a magic recipe then it's ok for me. But what I described for OP to use, are all tested through years and work fine.
Last edited:
Similar threads
Is Line able to associate e-mail accounts with phone numbers?
- blue_leaf77
- · Replies 10 ·
- Computing and Technology
- Replies
- 10
How can I generate word combinations for phone numbers using recursion?
- transgalactic
- · Replies 13 ·
- Programming and Computer Science
- Replies
- 13
Fortran How Can a Single READ Statement Handle Multiple Data Types in Programming?
- cibui
- · Replies 5 ·
- Programming and Computer Science
- Replies
- 5
Prime Cell Phone Numbers: Oddity or Probability?
- Char. Limit
- · Replies 40 ·
- Computing and Technology
- Replies
- 40
Comp Sci Java-converting phone numbers into words
- stripes
- · Replies 5 ·
- Engineering and Comp Sci Homework Help
- Replies
- 5
Comp Sci Computer programing - making new data types for integers java/c
- vorcil
- · Replies 4 ·
- Engineering and Comp Sci Homework Help
- Replies
- 4
Comp Sci Enum PaintColor in UsedCars class not accepting RED value
- kirkulator
- · Replies 1 ·
- Engineering and Comp Sci Homework Help
- Replies
- 1
