Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

An observation about Unicode in SQL Server Management Studio

$
0
0

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.


An observation about Unicode in SQL Server Management Studio

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?


An observation about Unicode in SQL Server Management Studio

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?


An observation about Unicode in SQL Server Management Studio

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?


An observation about Unicode in SQL Server Management Studio

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


An observation about Unicode in SQL Server Management Studio

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.


An observation about Unicode in SQL Server Management Studio

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.


An observation about Unicode in SQL Server Management Studio

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/


Viewing all articles
Browse latest Browse all 3160

Latest Images

Trending Articles