| Author |
Topic |
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2007-10-02 : 12:25:09
|
| I've got a field of type int, is there any way I can make it only accept values with 1 digit - i.e. 0 to 9Thanks |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-10-02 : 12:37:35
|
| Why don't you put this validation logic in the front-end. That's the logical place for it rather than having it at database level.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-02 : 13:08:40
|
check yourColumn between 0 and 10 _______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-10-02 : 16:52:11
|
quote: Originally posted by harsh_athalye Why don't you put this validation logic in the front-end. That's the logical place for it rather than having it at database level.
While I agree that you should have a front-end check. If it is a business rule then it probably makes sense to have a check constraint on the database. Some businesses enforce their business rules with the database and some don't, depends on how you do it. I personaly tend to put these constraints in my database since it would enforce the business rule and trying to get bad data into the database will fail if someone is able to circumvent the front-end. |
 |
|
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2007-10-02 : 17:05:33
|
quote: Originally posted by spirit1 check yourColumn between 0 and 10 
Where do I put this statement?Also should it be check yourColumn between 0 and 9? I want to allow 0,1,2,3,4,5,6,7,8,9Thanks |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-02 : 17:20:55
|
| [code]CREATE TABLE t1 (ID int PRIMARY KEY, somenum tinyint)GOALTER TABLE t1 ADD CONSTRAINT CK_t1_0_to_9 CHECK (somenum >= 0 AND somenum <= 9)[/code]between translates to col >= firstValue and col < lastValue_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2007-10-03 : 07:37:13
|
quote: Originally posted by spirit1between translates to col >= firstValue and col < lastValue
I'm sure it is just a type-o, but ...quote: BOLBETWEEN returns TRUE if the value of test_expression is greater than or equal to the value of begin_expression and less than or equal to the value of end_expression.
Jayto here knows when |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-03 : 07:42:17
|
[code]DECLARE @Sample TABLE (i INT)INSERT @SampleSELECT 1 UNION ALLSELECT 5 UNION ALLSELECT 7 UNION ALLSELECT 9SELECT iFROM @SampleWHERE i BETWEEN 5 AND 7[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-03 : 09:23:08
|
yes it was a typo... thanx!_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
|