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.
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?
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?
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?
DOH! There’s obviously something strange going on here. Let’s validate the sys.databases table:
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.
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.
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:
Also, be sure to check out http://www.sqldatapros.com/
3 thoughts on “An observation about Unicode in SQL Server Management Studio”
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.
One additional thing to point out about Emoji’s that any silly souls will discover very quickly is that any saved scripts with an Emoji turn into ??; so, this is definitely a practice that should be avoided. 🙂
You can save your SQL scripts with a Unicode encoding, preserving your emojis.