I want to make sure that valid US states are input in my database. Can someone provide exampleas of a check constraint to do this. If not a check constraint are there any hard code examples?
Validating State abbreviations using a Check Constraint
Collapse
X
-
hi,
do the following.
1.var_state_nam e variable holds the entered state name
2.have a temp table(<state_ta ble>).which have a column(<state_n ame>) of US states.
3.now check the entered state name.
select count(*) from <state_table> where <state_name>='v ar_state_name'
4.if the query returns value 1(assuming 1 state name occurs once inthe table),that means the entered state is a valid state name.and u can follow rest of the code
if its 0,then no such state name exists,n you can give necessary message
hope it works,may have better approach.
Regards,
Lipsa
Comment