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 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2002-09-04 : 15:37:45
|
| I want to make sure that users are created with a numeric PIN field that has values between 001 and 9999.Is a Check Constrant the best way to impliment this?Since I want the two zero's in 001, I need to make teh field a VARCHAR(4) right?Thanks!Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-09-04 : 17:01:50
|
| Sounds reasonable.You could also make sure that users are added via a stored proc and put the validation in that.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2002-09-04 : 17:36:14
|
| Michael,Definately put this is a CHECK constraint at the column level...As NR has said, you can validate the data in a SP before insertion and thus avoid an exception from the DB Engine. But do not leave the validation entirely to the SP..DavidM"SQL-3 is an abomination.." |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-09-04 : 17:50:05
|
| Something like this should work:CREATE TABLE PinTable (PIN varchar(4) NOT NULLCHECK (PIN LIKE '[0-9][0-9][0-9]' OR PIN LIKE '[0-9][0-9][0-9][0-9]')) |
 |
|
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2002-09-04 : 17:50:28
|
| That was the plan. I want to make sure that "forgetful DBAs" (such as myself form time to time) CAN'T mess up our business rules.Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
|
|
|
|