Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode SQL Query W/ Parameter instead N Prefix

Tags:

People also ask

Why do some SQL strings have an N prefix?

The "N" prefix stands for National Language in the SQL-92 standard, and is used for representing Unicode characters. In the current standard, it must be an upper case , which is what you will typically find implemented in mainstream products.

Why is a varchar getting prefixed by N?

NCHAR, NVARCHAR or NTEXT are similar to CHAR, VARCHAR OR TEXT, where the N prefix represents the International Language Character Set. The N-prefixed data types indicate that the resulting string could be comprised of a Unicode character set with variable length where each character occupies 2 bytes.

What is the N in nvarchar?

It's declaring the string as nvarchar data type, rather than varchar. You may have seen Transact-SQL code that passes strings around using an N prefix. This denotes that the subsequent string is in Unicode (the N actually stands for National language character set).


I have an insert query to execute from within a C# against a SQL Server database.

The column I am inserting to is of type nvarchar.

the data I am inserting to that column is non-english.

Is it sufficient for me to use AddWithValue in order to pass the non-english data to the server? like this example:

string dogName = "עברית";
using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();
    using (SqlCommand command = new SqlCommand("INSERT INTO Dogs1(Name) VALUES @Name", connection))
    {
    command.Parameters.AddWithValue("Name", dogName);
    command.ExecuteNonQuery();
    }
}

Or must I use the N prefix to declare it unicode? like it says so here.