Connecting Tech Pros Worldwide Help | Site Map

Query

Newbie
 
Join Date: Sep 2009
Posts: 1
#1: Sep 25 '09
I want to insert some particular values to a table

for ex:
In a table for a column i want to insert only values from 1,2,3,4,5.It sholud not allow to enter 6,7.... or any value
Familiar Sight
 
Join Date: Sep 2008
Posts: 253
#2: Sep 25 '09

re: Query


Are you doing this directly on the database or through an application/website?
ssnaik84's Avatar
Member
 
Join Date: Aug 2009
Location: Bengaluru, India
Posts: 119
#3: Sep 25 '09

re: Query


You can create a check constraint

Expand|Select|Wrap|Line Numbers
  1. create table testrule
  2. (srno int)
  3.  
  4. ALTER TABLE testrule 
  5. ADD CONSTRAINT myconstraint CHECK (srno LIKE '[1-5]' );
  6.  
  7. insert into testrule values (2)
  8. insert into testrule values (7)
  9.  
  10. select * from testrule
Reply