问题
I am trying to insert emoji / emoticons to MSSQL database but it just stores ??? instead of the emoji / emoticons.
I am finding only help for MSSQL 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;
MSSQL does not recognize this command. this is only for Microsoft SQL server not MySQL
回答1:
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 ║
╠═════════════════════════════════╣
║ 👍 🖒 🖓 🖕 🗑 🛦 ⁉ 😎 😔 😇 😥 😴😭 ║
╚═════════════════════════════════╝
来源:https://stackoverflow.com/questions/33938445/add-emoji-emoticon-to-mssql-table