0% found this document useful (0 votes)
9 views2 pages

Check Constraint

Uploaded by

Dhavan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Check Constraint

Uploaded by

Dhavan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

check constraint:

* It is domain level constraint


* implemented at column level
* it will check the given condition before inserting value
into a column.

syntax to add constraint during table creation:

create table tablename(


column_name datatype(size)constraint name check(condition),
column_name datatype(size)constraint name check(condition),
.
.
column_name datatype(size));

Note:
column_name must be used while writing condition

Example:

create a table flight with columns flight_id, flight_name,


Seat_no, amount

flight_id column must allow number above 1000 and below 9999

seat_no column must allow number between 1 to 50

amount column must allow price above 100

create table flight(


flight_id number(4)constraint flight_id check(flight_id between 1000 and 9999),
flight_name varchar2(25)constraint flight_name not null,
seat_no number(2)constraint seat_no check(seat_no between 1 and 50),
amount number(5)constraint amount check(amount>100));

IncomeTax(tax_id,payee_name,tax_slab,tax_amount,percentage)

add constraint check to tax_slab column, it must allow values between 1 to 100

syntax:
alter table tablename modify columnname datatype(size)
cosntraint name check(condition);

ex:

alter table incometax modify tax_slab number(3)


constraint tax_slab check(tax_slab between 1 and 100);

add constraint check to percentage column, it must allow values between 0.01 to
0.25

alter table incometax modify percentage number(5,2)


constraint percentage check(percentage between 0.01 and 0.25);

You might also like