I'm creating a database in db2 and I want to add a constrain to validate whether the user inserting a valid email address, that contain %@%.% . Without luck...any advice?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
You could create a trigger that checks the given string with a regular expression that describes the structure of an email
However, the regular expression of an email is not easy to define: Using a regular expression to validate an email address
Once you have the value of RET (true or false) you can do something in the trigger.
You can test the regular expression you want to use from command line:
You can use LIKE with wildcards. See here for the wildcards on DB2.
This will ignore the following cases (simple version for valid emails):
You can see an example in MySql in sqlfiddle.
To add it as a constraint, you do (as mustaccio said in a comment):