What’s up with the N in front of string values?

If you have looked at pretty much any Microsoft provided T/SQL code you have probably seen an N in front of a string value when setting a variable much like this.

SELECT *
FROM sys.databases
WHERE name = N'master'

What this N does is tell the SQL Server that the data which is being passed in is uni-code and not character data.  When using only the Latin character set this is not really needed.  However if using characters which are not part of the basic Latin character set then the N is needed so that SQL knows that the data being given it is uni-code data.

Denny

Contact the Author | Contact DCAC

Should I be using uni-code data types?

The path that Microsoft is going says yes.  They are moving all there samples and defaults to using uni-code.  In reality uni-code may not be needed in your environment.  If you are storing only Latin characters (the US alphabet characters) then you probably don’t need to store uni-code characters.  However if you are planning on moving your operations to support customers who do not speak English then you will want to setup your database and application to use the uni-code data types (nvarchar, nchar, ntext).

It doesn’t take much extra to use uni-code data types, however do keep in mind that it does require more disk space to use uni-code data types.  For each character saved two bytes of disk space are used instead of one byte.  While this may not seam like much space if you will have a large table with a large ntext field this can use a lot of space quickly.

Denny

Contact the Author | Contact DCAC

Excellent Lock Pages in Memory Blog

Video

Globally Recognized Expertise

As Microsoft MVP’s and Partners as well as VMware experts, we are summoned by companies all over the world to fine-tune and problem-solve the most difficult architecture, infrastructure and network challenges.

And sometimes we’re asked to share what we did, at events like Microsoft’s PASS Summit 2015.

Awards & Certifications

Microsoft Partner   Denny Cherry & Associates Consulting LLC BBB Business Review    Microsoft MVP    Microsoft Certified Master VMWare vExpert
INC 5000 Award for 2020    American Business Awards People's Choice    American Business Awards Gold Award    American Business Awards Silver Award    FT Americas’ Fastest Growing Companies 2020   
Best Full-Service Cloud Technology Consulting Company       Insights Sccess Award    Technology Headlines Award    Golden Bridge Gold Award    CIO Review Top 20 Azure Solutions Providers