4

It's maybe a noob question but I found some T-SQL query example to verify database size with SELECT and WHERE clause here

Here is the code:

SELECT name, size, size*1.0/128 AS [Size in MBs] 
FROM sys.master_files
WHERE name = N'mytest';

My question is what does the N prefix mean in the WHERE name = N'keyword' clause?

I always use WHERE name = 'keyword' before, and I don't find the differences (you can try it by yourself).

I've googled that but I don't know the keyword I supposed to search

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Willy Lazuardi
  • 1,776
  • 4
  • 24
  • 38

4 Answers4

5

It's declaring the string as nvarchar data type (Unicode), rather than varchar (8-bit encoding, including ASCII).

FYI, this is a duplicate of the question: What is the meaning of the prefix N in T-SQL statements?

Community
  • 1
  • 1
Doug_Ivison
  • 778
  • 6
  • 16
  • 3
    This is not quite correct. Varchar is not ASCII. Varchar is an 8 bit encoding. It can store ASCII, or it can store any other 8 bit code page for that matter. – Stainy Oct 11 '13 at 20:10
2

From the docs:-

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). Which means that you are passing an NCHAR, NVARCHAR or NTEXT value, as opposed to CHAR, VARCHAR or TEXT.

Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319
2

N means there can be some unicode characters in the given string.

M.Ali
  • 65,124
  • 12
  • 92
  • 119
1

It means unicode. See http://msdn.microsoft.com/en-us/library/bb399176.aspx To declare a character string literal as Unicode, prefix the literal with an uppercase "N"

Mike Stockdale
  • 5,246
  • 3
  • 28
  • 33