Standard Data Types for Web Addresses, Phone Numbers?

In summary: I found it best to normalize it before putting it into the database. I would also add a field to store the way the user provided the number.
  • #1
WWGD
Science Advisor
Gold Member
7,019
10,591
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.
 
Last edited:
Technology news on Phys.org
  • #2
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 :smile:?
 
  • Like
Likes WWGD
  • #3
WWGD said:
Hi All,
Just curious: what kind of data types does one usually use for web addresses, for phone numbers?
Thanks.
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.
 
  • Like
Likes WWGD
  • #4
WWGD said:
Hi All,
Just curious: what kind of data types does one usually use for web addresses, for phone numbers?
Thanks.
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?
 
  • Like
Likes WWGD
  • #5
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.
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?
 
  • #6
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?
Now that you mention it, I mean both.
 
  • #7
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?
I haven't worked with MSSQL. God only knows what they allow. :wideeyed:
 
  • #8
Borg said:
I haven't worked with MSSQL. God only knows what they allow. :wideeyed:
Are you insinuating ( the very obvious statement that) Microsoft has a sloppy technical design?
 
  • #9
WWGD said:
Now that you mention it, I mean both.
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.
 
  • #10
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.
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);
 
  • Like
Likes WWGD and Silicon Waffle
  • #11
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:
  • Like
Likes WWGD
  • #12
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.
It depends.
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. :biggrin:
 
  • Like
Likes WWGD
  • #13
Silicon Waffle said:
but some numbers like 1800-CALL-ME

Such numbers are not unique - how would one handle conflicts and testing.
 
  • #14
256bits said:
Such numbers are not unique - how would one handle conflicts and testing.
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.
 
  • Like
Likes WWGD
  • #15
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.
Agree, of course there should be a format, a single standard used, same as with dates and all other fields.
 
  • #16
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?
I think you are confusing the database engine with whatever GUI front end tool you are using.
 
  • #17
MrAnchovy said:
I think you are confusing the database engine with whatever GUI front end tool you are using.
Thanks; I thought there was a default choice of GUI; not sure the name, but I thought there was one.
 
  • #18
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.
Sorry, I quoted your post but somehow replied to a different one. Senility happening earlier than I expected :(.
 
  • #19
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.
 
  • #20
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.
 
  • Like
Likes WWGD
  • #21
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.
Thanks; wouldn't international addresses have the nchar() type?
 
  • #22
WWGD said:
Thanks; wouldn't international addresses have the nchar() type?
Good catch, but we're both wrong. Use nvarchar.

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.
 
  • Like
Likes WWGD
  • #23
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.
 
  • Like
Likes WWGD
  • #24
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.
 
Last edited:
  • Like
Likes WWGD
  • #25
WWGD said:
Thanks; I thought there was a default choice of GUI; not sure the name, but I thought there was one.
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.

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.
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 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)
);
(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).
 
  • #26
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.
 
  • #27
QuantumQuest said:
I just gave an example of something very usually done.
And in my experience very often corrected years later at vast expense.

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 there are two people with the surname "Smith"?

QuantumQuest said:
And also I can't see where do you find any immutability issue.
What happens when Mary Smith gets married and changes her name to Mary Jones?

QuantumQuest said:
If "surname" does not help then another column can be chosen accordingly to the specific needs.
What happens when the specific needs change?

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".
 
  • #28
Just realized I missed the vital keyword out of this code:
MrAnchovy said:
Code:
CREATE TABLE Addresses
(
   Id int IDENTITY NOT NULL,
   CONSTRAINT PK_Addresses_Id PRIMARY KEY CLUSTERED (Id)
);
(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).
 
  • #29
@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
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:

Related to Standard Data Types for Web Addresses, Phone Numbers?

1. What are the standard data types for web addresses?

The standard data types for web addresses are Uniform Resource Locators (URLs) and Uniform Resource Identifiers (URIs). These are used to identify and locate resources on the internet, such as web pages, images, and videos.

2. What is the difference between a URL and a URI?

A URL is a specific type of URI that includes the protocol used to access the resource, such as http or https. A URI is a broader term that encompasses all types of resource identifiers, including URLs, Uniform Resource Names (URNs), and others.

3. What is the format of a web address?

The format of a web address typically includes the protocol, followed by the domain name, and optionally a path to a specific resource on the server. For example, http://www.example.com/index.html

4. What are the standard data types for phone numbers?

The standard data types for phone numbers are E.164 numbers, which are used for international phone numbers, and National Significant Numbers (NSNs), which are used for local phone numbers within a specific country.

5. How are phone numbers typically formatted?

Phone numbers are typically formatted differently depending on the country or region. In the United States, phone numbers are often written in the format of (XXX) XXX-XXXX, while in the United Kingdom, they are written as +44 XXXX XXXXXX. However, the E.164 standard recommends a consistent format of +[country code][area code][subscriber number] for all international phone numbers.

Similar threads

  • Programming and Computer Science
Replies
10
Views
1K
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
19
Views
2K
  • Programming and Computer Science
2
Replies
50
Views
4K
  • Programming and Computer Science
Replies
1
Views
339
  • Programming and Computer Science
Replies
8
Views
390
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
706
Back
Top