Showing posts with label blown. Show all posts
Showing posts with label blown. Show all posts

Sunday, March 11, 2012

Check Constraint Regular Expressions

Does MS SQL support full blown Regular expression features under SQL CHECK CONTRAINTS ?Full blown Regular expression features? Explain what it is!|||Yes to an extent. Remeber that a check constraint need only evaluate to True Or False. Consider the following:

create table #Tmp(f1 int, f2 varchar(10) constraint Tmp_f2 check(f2 like 'a_[0-9][0-9]-[A-Z]'))
insert into #tmp values (1,'az00-a')
insert into #tmp values (1,'a*99-a')
insert into #tmp values (1,'b*99-a')
insert into #tmp values (1,'b1')

In Perl or Python the last character of f2 wold need to be uppercase but because I have a case-insensative collation upper or lower case is accepted.