Add emoji / emoticon to MSSQL table

夙愿已清 提交于 2019-12-10 04:08:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!