For example, there is a string field Name in my C# (Linq-to-SQL); what data type would that SQL field have to be?
varchar? nchar? I’m confused.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
SQL Server 2005+ equivalent
The best SQL type equivalent to C#
Stringisnvarchar(max). It stores exactly the same amount of text as C#Stringobject instance. But beware. Choosing other[n][var]chartypes would be more optimal on data store (meaning they could work much faster), but choosing one of these greatly depends on the data that you wish to store.char(n)is for fixed length strings (of length n) so if your strings don’t vary in size, you would choose this type (i.e. product keys)varchar(n)is used for variable string lengths up to length of n (i.e. email address)varchar(max)is used for variable string lengths of whatever length up to 2G characters so basically the same as C#Stringtype (i.e. blog post content)Pre SQL Server 2005
Before SQL Server version 2005,
[n]varchar(max)types were not supported. You had to use[n]texttypes instead, but they were stored differently hence were much slower compared to[n][var]charalternatives and were also more cumbersome for developers to handle and manipulate.