sqlsql-serverunicodecollationutf8mb4

How to insert special characters in SQL Server?


Much like this question in MySQL, I am trying to retain special characters such emojis into an nvarchar type column. However, any emojis are converted to "??". I have tried to reproduce the question's solution including changing column type and collation in SQL Server but haven't succeeded.

What I am attempting to do:

INSERT INTO TableName 
(Id, Title, Description) 
VALUES
(1, 'This is my title 😀','Here is a description with a 📻 radio');

Where Title and Description columns are nvarchar(255).

The resulting insert looks like:

| Id | Title               | Description                           |
|----|---------------------|---------------------------------------|
| 1  | This is my title ?? | Here is a description with a ?? radio |

Using this to create the table

CREATE TABLE TableName(
  Id INT PRIMARY KEY,
  Title NVARCHAR(255),
  Description NVARCHAR(255)
);

The database's collation is SQL_Latin1_General_CP1_CI_AS


Solution

  •     INSERT INTO TableName(Title,Description) 
        VALUES (N'👍 🖒 🖓 🖕 🗑 🛦 ⁉ 😎 😔 😇 😥 😴 😭',
                N'👍 🖒 🖓 🖕 🗑 🛦 ⁉ 😎 😔 😇 😥 😴 😭');
    

    Use the prefix string literal with " N' <"my strange text"> ' "

    Try this "select" statement as well:

        SELECT N'👍 🖒 🖓 🖕 🗑 🛦 ⁉ 😎 😔 😇 😥 😴 😭'