如何防止 MySQL 中纯数字数据的 Insert?
大家讲道理
大家讲道理 2017-04-17 14:47:14
0
5
736

比如我不希望 username 是纯数字的,如果程序 insert 的数据,username 是纯数字的,就返回 mysql 数据格式错误,有这种功能吗?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(5)
洪涛

Achieved through stored procedures or triggers, but this logic is best controlled by the code layer

Peter_Zhu

Let’s talk about the conclusion first: I agree with LS’s point of view. Generally, verification is written in the program, and the database only does basic constraints such as unique

If you really want to do it in the database, you will usually write trigger

Then there seems to be add constraint check, but even if mysql supports this, it will not check before storage (all engines)

http://stackoverflow.com/questions/16005283/is-it-possible-to-enforce-data-checking-in-mysql-using-regular-expression

PHPzhong

Program logic problems should not be left to the database to handle, or it should be used as the last line of verification defense.

小葫芦

Check before or during submission.

小葫芦

This kind of basic verification is also done in the database. Doesn’t this just put more pressure on the database? Everyone is reducing the burden on it

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template