Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
snowy
Starting Member
5 Posts |
Posted - 2009-09-25 : 20:35:37
|
| hey, could someone please tell me how i would go aboutspecifying the following constraint, it's quite specificand I really don't have a clue how to do it ><. I have a product table, and each product hasa product_ID which MUST consist of 4 letters followedby 4 digits where the FIRST digit must be 1, 2, 3, 4 or 5e.g. COKE2189, CAKE5555 etcThanx heaps, |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-09-26 : 02:45:16
|
| hi..Just add check constraint like thisALTER TABLE Product WITH NOCHECK ADD CONSTRAINT CK_Product_ID CHECK( Product_ID LIKE '[A-Z][A-Z][A-Z][A-Z][1-5][0-9][[0-9][0-9]') |
 |
|
|
snowy
Starting Member
5 Posts |
Posted - 2009-09-26 : 23:42:31
|
| Ahh thanx, I misread the spec. i'm not allowed to have the number 4 as one of the First digitsso the FIRST digit of the 4 digits following the 4 lettersmust be 1,2,3 or 5.So would this be correct then?ALTER TABLE Product WITH NOCHECK ADD CONSTRAINT CK_Product_ID CHECK( Product_ID LIKE '[A-Z][A-Z][A-Z][A-Z][1-3][0-9][[0-9][0-9]') ORPRODUCT_ID LIKE '[A-Z][A-Z][A-Z][A-Z][5][0-9][[0-9][0-9]ty |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-09-29 : 00:22:19
|
| ALTER TABLE Product WITH NOCHECK ADD CONSTRAINT CK_Product_ID CHECK( Product_ID LIKE '[A-Z][A-Z][A-Z][A-Z][1,2,3,5][0-9][[0-9][0-9]') |
 |
|
|
|
|
|
|
|