5

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
  • 732,580
  • 175
  • 1,330
  • 1,459
Willy Lazuardi
  • 1,806
  • 4
  • 26
  • 41

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
  • 7
  • 17
  • 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
  • 168,305
  • 31
  • 280
  • 331
2

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

M.Ali
  • 67,945
  • 13
  • 101
  • 127
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,256
  • 3
  • 29
  • 33