Reputation: 8295
I have a person table that will have columns such as first name and last name.
What is the best data type to use for these columns as they can be any length. Is there a rule of thumb when it comes to this?
I am using sql server 2008.
Upvotes: 3
Views: 7720
Reputation: 27385
If any lenght can acceed 4000 for NVarchar or 8000 for Varchar you could use (N)Varchar(max). But if this would be unlike you should prefer (N)Varchar(Yourlimit) because of perfomance issues.
Upvotes: 1
Reputation: 21
You can use Varchar(50) data type and devide full name in to first name, middle name and l
Upvotes: 1
Reputation: 33839
I think it is highly unlikely someone to have a Firstname or Lastname more than 50 characters.
Datatype for string type with Unicode characters is NVARCHAR
and you can limit both of them to 50 or even 100
would not make a much difference.
So you can say
Firstname nvarchar(50)
Lastname nvarchar(50)
Upvotes: 5
Reputation: 499302
Use NVARCHAR(N)
, where N
is the largest number of characters you wish to support for the field.
If you expect that you will never have international names (say Chinese, Japanese, Hebrew and other scripts) than you can use VARCHAR(N)
.
These are variable length fields that are suitable for string data of variable length.
Upvotes: 3