Tjaart
Tjaart

Reputation: 4129

Are regex check constraints possible in SQL Server

I am trying to find a way to validate data in my columns using regex CHECK constraints but have so far only come across the LIKE keyword that has an extremely limited subset of regex syntax. I'd like to know if there is a way to use regex in check constraints?

I am using SQL Server 2005 and 2008.

Upvotes: 3

Views: 2460

Answers (2)

Alan Burstein
Alan Burstein

Reputation: 7928

I'm a little late to the thread here but check out my article about how to do this:

http://xmlsqlninja.blogspot.com/2013/09/mdqregex-clr-functions-part-3-regex.html

Upvotes: 0

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239764

I think you can create a CLR scalar UDF which can use the .Net framework RegEx classes, and then call that from your check constraint.

In fact, this article discusses this scenario (search for "Check Constraint", then move backwards through the article to find implementation details).

Upvotes: 4

Related Questions