mysql - 是否可以将 varchar 限制为 MySQL 中的特定字符集?

标签 mysql string varchar

我正在创建一个网站,其中特定的用户数据应仅包含特定预先指定集中的字符。在将数据插入数据库之前,我可以使用 PHP 验证数据。但我想知道这在 MySQL 本身是否可行。

For instance, consider the Username. It should have characters only from the Alphanumeric set and underscore. Verification of this data is possible through PHP before inserting it into the database. But is it possible to assign a constrain to the Varchar column to not allow any string, with characters other than these, to be inserted into the table?

最佳答案

你问了

Is it possible to assign a constraint to the Varchar column to not allow any string, with characters other than these, to be inserted into the table?

答案是否定的。 MySQL 的约束并不那么聪明。

关于mysql - 是否可以将 varchar 限制为 MySQL 中的特定字符集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30413107/

相关文章:

php - 如果该特定内容不在数据库中,则显示错误消息

PHP mySQL 查询后对结果进行排序

java - 在Java中,从一个方法返回的字符串是否在另一种方法中打印出来?

mysql - 如何在 mysql 中的 varchar 中执行 SQL 插入

MySQL WHERE 在 VARCHAR 上使用公式 "="返回空结果

带有来自 MySQL 数据库的重复事件的 PHP 日历

php - 如何执行存储在 MySQL 数据库中的 PHP 函数

string - 算法帮助 : I need help parsing a string that contains * as a wild card in scala

c - 为什么我的解析函数返回不返回所有预期的标记?

MySQL varchar 索引长度