为什么可以将乌克兰语字符串存储在 varchar 列中?

Why can I store an Ukrainian string in a varchar column?

我有点惊讶,因为我能够在 varchar 列中存储乌克兰语字符串。

我的 table 是:

create table delete_collation
(
   text1 varchar(100) collate SQL_Ukrainian_CP1251_CI_AS
)

并使用此查询我能够插入:

insert into delete_collation
values(N'використовується для вирішення квитки')

但是当我删除 'N' 时,它在 select 语句中显示 ??????

这样可以吗?还是我在理解 unicode 和非 unicode 时遗漏了什么?

来自MSDN

Prefix Unicode character string constants with the letter N. Without the N prefix, the string is converted to the default code page of the database. This default code page may not recognize certain characters.

更新:
请看类似问题::
What is the meaning of the prefix N in T-SQL statements?
Cyrillic symbols in SQL code are not correctly after insert
sql server 2012 express do not understand Russian letters

扩展 MegaTron 的回答:

使用 collate SQL_Ukrainian_CP1251_CI_AS,SQL 服务器能够使用 CodePage 1251 在 varchar 列中存储乌克兰语字符。

但是,当您指定一个没有 N 前缀的字符串时,该字符串将在发送到数据库之前转换为默认的非 unicode 代码页,这就是为什么您会看到 ??????.

所以使用 varchar 和整理是完全没问题的,但是在向数据库发送字符串时必须始终包含 N 前缀,以避免中间转换为默认值 (非乌克兰语)代码页。