An observation about Unicode in SQL Server Management Studio

A week or so ago I read a blog post and tweet about using an emoji in SQL Server. This inspired me to use the ninja cat emoji for my demo database name and something interesting was discovered.

How to use an emoji

You can use emojis very easily by typing them from the Windows 8 or 10 onscreen keyboard.

1 - keyboard

You can also hold the ALT key and type the unicode number for the key you want on the number pad. You can even use the Character Map tool. Finally, cut and paste seems to be a great option too.

Can you use them in SQL Server?

What happens if you try to name a database with some of the newer emojis like the ninja cat or the ninja cat riding a T-Rex?

create db

You get a cat and a person?? I can tell you that I didn’t see that coming.

So what happens if you don’t use the UI?

ninjacat

There it is! The ninja cat database! You can see that even IntelliSense shows the ninja cat. Cool, right? How does it show in Object Explorer?

object explorer shows different

DOH! There’s obviously something strange going on here. Let’s validate the sys.databases table:

sysdatabases shows different

The USE database drop down shows the ninja cat; yet, it shows a cat and a person in sys.databases.

Let’s try this with a different emoji. Cake! Yum mmmm cake.

cakefail

Cake already exists? I can tell you it does not. So why is it failing? Let’s compare the unicode values for the ninja cat and cake.

CakeCatCompare

Strangely enough, the unicode values are not the same but some parts of SQL Server like the database creation proc thinks they are. Using the USE statement for both cake and the ninja cat change to the same database.

I’m curious to see if collation will also affect the results. If you’ve done some testing along those lines send me some feedback.

 

Be sure to check out all my blog posts here:

http://www.sqlservercentral.com/blogs/confessions-of-a-microsoft-addict/

and https://sqltechblog.com/

Also, be sure to check out http://www.sqldatapros.com/

3 thoughts on “An observation about Unicode in SQL Server Management Studio

  1. This definitely amused me on a Friday morning. I just hope some silly soul doesn’t come to the conclusion that using Emoji’s for database names is a good idea some ime in the future.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s