Add emoji / emoticon to SQL Server table

Yagnesh picture Yagnesh ยท Nov 26, 2015 ยท Viewed 17.5k times ยท Source

I am trying to insert emoji / emoticons to a SQL Server database but it just stores ??? instead of the emoji / emoticons.

I am finding only help for SQL Server not MySQL.

I tried : link

but not finding answers even not able to set with :

ALTER TABLE mytable charset=utf8mb4, 
    MODIFY COLUMN textfield1 VARCHAR(255) CHARACTER SET utf8mb4,
    MODIFY COLUMN textfield2 VARCHAR(255) CHARACTER SET utf8mb4;

SQL Server does not recognize this command. This is only for Microsoft SQL Server not MySQL

Answer

Lukasz Szozda picture Lukasz Szozda ยท Nov 26, 2015

Use NVARCHAR(size) datatype and prefix string literal with N:

CREATE TABLE #tab(col NVARCHAR(100));

INSERT INTO #tab(col) VALUES (N'๐Ÿ‘ ๐Ÿ–’ ๐Ÿ–“ ๐Ÿ–• ๐Ÿ—‘ ๐Ÿ›ฆ โ‰ ๐Ÿ˜Ž ๐Ÿ˜” ๐Ÿ˜‡ ๐Ÿ˜ฅ ๐Ÿ˜ด ๐Ÿ˜ญ');

SELECT *
FROM #tab;

LiveDemo

Output:

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘              col                โ•‘
โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฃ
โ•‘ ๐Ÿ‘ ๐Ÿ–’ ๐Ÿ–“ ๐Ÿ–• ๐Ÿ—‘ ๐Ÿ›ฆ โ‰ ๐Ÿ˜Ž ๐Ÿ˜” ๐Ÿ˜‡ ๐Ÿ˜ฅ ๐Ÿ˜ด๐Ÿ˜ญ โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•