SQL Server Check Like Constraint for letters and numbers, and a trigger -
i'm creating simple constraint on table's column accepts 3 capital letters first 3 letters, dash "-" , 6 numbers follow. far inserts have been rejected because of it:
my constraint:
alter table equipos add constraint nombre check (idenlace like('[a-z][a-z][a-z]-[0-9][0-9][0-9][0-9][0-9][0-9]')) go
trigger caps:
create trigger tr_upper_nombre on equipos instead of insert begin insert equipos select upper(i.codequipo),i.marcaequipo,i.fchequipo,i.vtoequipo,i.idenlace inserted end go
edit: example of should valid:
'jhs-929323'
something should invalid
'jhs-929323' 'jhs-99323' 'jhs929323'
i think constraint wrong. comes after isn't being validated. suggestions who's done similar before?
create constraint this....
alter table equipos add constraint nombre check ( left(idenlace,3) = upper(left(idenlace,3)) collate latin1_general_cs_ai , substring(idenlace,4,1) = '-' , right(idenlace,6) not '%[^0-9]%' , len(idenlace) = 10 ) go
Comments
Post a Comment