|
Re: How to give Check Constraint [message #20722 is a reply to message #20717] |
Sat, 15 June 2002 04:45 |
sureshraj
Messages: 9 Registered: May 2002
|
Junior Member |
|
|
Employee(e_no, e_name, basic_pay, deptno)
How to give constraint for
minimum basic_pay is 10000 and maximum is 50000.
answer:
create table employee(e_no number,e_name varchar2(15),basic_pay number(8,2) constraint ck check(basic_pay <10000 and basic_pay >50000),deptno number(4));
|
|
|
Re: How to give Check Constraint [message #20732 is a reply to message #20717] |
Sun, 16 June 2002 13:18 |
Su
Messages: 154 Registered: April 2002
|
Senior Member |
|
|
There is a syntax error in your solution. The 'constraint' clause is not allowed at column level, it is allowed for table level. And the solution is not correct as it checks whether the basic pay is less than 10000 and greater than 50000 same time, which is not possible all at once. The correct one is the following. And instead of giving < and > better to use BETWEEN operator.
SQL> r
1 create table employee (
2 e_no number not null,
3 e_name varchar2(20),
4 basicpay number(8,2) check (basicpay between 10000 and 50000),
5* depno integer)
Table created.
The basic pay should be in between 10000 (minimum) and 50000 (maximum). Check it out.
Good luck :)
|
|
|
Re: How to give Check Constraint [message #20774 is a reply to message #20717] |
Wed, 19 June 2002 16:34 |
Siva Ram
Messages: 22 Registered: November 2001
|
Junior Member |
|
|
Hi
The best method to do this is:
SQL> Create table employee(e_no number,e_name varchar2(15),basic_pay number(8,2) constraint chkbasic check(basic_pay between 10000 and 50000),deptno number(4));
Thank You
Siva Ram
|
|
|