Add Emoji/Emoticon to SQL Server Table

Add emoji / emoticon to SQL Server table

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;

db<>fiddle demo

Output:

╔═════════════════════════════════╗
║ col ║
╠═════════════════════════════════╣
║ ⁉ ║
╚═════════════════════════════════╝

EDIT:

SQL Server 2019 and forward supports UTF-8 collation:

CREATE TABLE t(col VARCHAR(100) COLLATE Latin1_General_100_CI_AI_SC_UTF8);
-- column's data type is VARCHAR!
-- collate could be set on column/database/instance level

INSERT INTO t(col) VALUES (N'☢️');

SELECT * FROM t;
-- col
-- ☢️

db<>fiddle demo - SQL Server 2019

Insert Emoticons into SQL Server

Try this.

Dim command As New SqlCommand("INSERT INTO [dbo].[emoji]([Message]) VALUES(N'" & "☺️ & "')", SQLCon)

How to store Emoji Character in MySQL Database

Step 1, change your database's default charset:

ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

if the db is not created yet, create it with correct encodings:

CREATE DATABASE database_name DEFAULT CHARSET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci;

Step 2, set charset when creating table:

CREATE TABLE IF NOT EXISTS table_name (
...
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;

or alter table

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE table_name MODIFY field_name TEXT CHARSET utf8mb4;

SQL Query Where Column = '' returning Emoji characters 🎃 and 🍰

This is collation dependant.

Matches empty string

SELECT 1 where N'' = N''  COLLATE latin1_general_ci_as

Doesn't match empty string

SELECT 1 WHERE N'' = N''   COLLATE latin1_general_100_ci_as

The 100 collations are more up-to-date (though still not bleeding edge, they have been available since 2008) and you should use more modern collations unless you have some specific reason not to. The BOL entry for 100 collations specifically calls out

Weighting has been added to previously non-weighted characters that
would have compared equally.



Related Topics



Leave a reply



Submit