SQL:如何使用case敏感的utf8mb4_general_ci的唯一键创建表?

发布于 2025-02-12 07:12:26 字数 415 浏览 0 评论 0原文

我正在使用phpmyadmin和PDO。 我的数据库使用UTF8MB4_GENERAR_CI。 看起来像这样。

CREATE TABLE `my_database`.`example` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `code` VARCHAR(255) NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE (`code`)
) ENGINE = InnoDB;

当我插入“ A”和“ A”时,我会遇到错误。 我通过将代码列的整理更改为UTF8MB4_BIN来修复它。

有什么方法可以将UTF8MB4_GENERAR_CI与敏感情况使用? 我可以将其设置在phpmyadmin,PDO或SQL中吗?

I am using phpMyAdmin and PDO.
My database using utf8mb4_general_ci.
And look like this.

CREATE TABLE `my_database`.`example` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `code` VARCHAR(255) NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE (`code`)
) ENGINE = InnoDB;

I got an error when I inserted 'A' and 'a'.
I fix it by changing the Collation of the code column to utf8mb4_bin.

Have any way to use utf8mb4_general_ci with sensitive cases?
Can I set it in phpMyAdmin, PDO, or SQL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杀お生予夺 2025-02-19 07:12:26

Thank @tkausl and @topsail.

The utf8mb4_general_ci contain _ci that for case insensitive.

From https://stackoverflow.com/questions/4558707/case-sensitive-collation-in-mysql,
I should use utf8mb4_bin for the unique column that I want case sensitive and I can use ORDER BY column COLLATE utf8_general_ci.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文