Explain the constraints that can be applied to Oracle tables.
Oracle constraints are usually used to maintain integrity of data. The different types of constraints include:-
CHECK constraint: This constraint specifies a condition for a row.
Example:Create table employee
(
Id, varchar(10),
CONSTRAINT id
CHECK (id BETWEEN 10 and 1000)
);
NOT NULL constraint: This specifies that a column cannot accept NULL values.
Example:Create table employee
(
Id, varchar(10) NOT NULL,
CONSTRAINT id
CHECK (id BETWEEN 10 and 1000)
);
Primary key constraint: This constraint ensures that each row is identified by a unique key.
Example:Create table employee
(
Id, varchar(10) NOT NULL,
Roll_number INTEGER(10);
CONSTRAINT id PRIMARY KEY(Roll_number)
);
Unique Constraint: This constraint ensures no columns value has repetitive values.
Example:Create table employee
(
Id, varchar(10) NOT NULL,
Roll_number INTEGER (10);
CONSTRAINT id UNIQUE (Roll_number)
);
Explain the constraints that can be applied to Oracle tables.
The syntax of writing a table is
create table tablename ( columnname type, columnname type ..., primary key(keycolumn);
The keycolumn is associates with the key constraint.
You can even add the foreign key constraint by adding the references to the table for that foreign key in the following way:
foreign key(column) references foreigntable