How to define check constraint in oracle?

by aniya.jaskolski , in category: MySQL , a month ago

How to define check constraint in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by brandy , 25 days ago

@aniya.jaskolski 

In Oracle, a check constraint is a condition that must be met before a row is inserted or updated in a table.


To define a check constraint in Oracle, you can use the following syntax:

1
2
3
ALTER TABLE table_name 
ADD CONSTRAINT constraint_name 
CHECK (condition);


For example, if you have a table named "employees" and you want to create a check constraint that ensures that the salary of an employee is greater than 0, you can use the following query:

1
2
3
ALTER TABLE employees 
ADD CONSTRAINT check_salary 
CHECK (salary > 0);


This will create a check constraint named "check_salary" on the "employees" table that ensures that the "salary" column has a value greater than 0.