How to define check constraint in oracle?

by aniya.jaskolski , in category: MySQL , 10 months ago

How to define check constraint in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by brandy , 10 months 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.

Related Threads:

How to rename a default constraint on oracle?
How to define default where clause on a table in oracle?
How to check oracle internal process?
How to check if all values of column are same in oracle?
How to check whether index is being used or not in oracle?
How to define 3 way relationship in laravel?