One of my colleague asked me a question that how to “allow only alphanumeric characters” in a column. Below is the exact question:
How can i stop accepting any non-alphanumeric characters during DML operations in a column of a table?
To achieve this, we can follow below steps. There may be more different ways other than these;
- Create a table
- Create a scalar function which returns true or false by checking non-alphanumeric characters (Using scalar function as an example so that in case of complex logic it can be implemented inside this function.)
- Create a check constraint on table and call this created function to check that column has only alphanumeric values
Some other way, we can also create an “Instead Of Trigger” and write a logic to check alphanumeric values for that column which I will not cover in this post.
Now let’s brief me each step mentioned above:… More