Searching for "Constraint."

Q:

Explain unique Constraint.

Answer

A unique constraint on a column uniquely identifies the record by a combination of one or more fields. Few unique constraint fields can have a NULL value as long as the combination of values is unique.


Example:
create table employee ( id number NOT NULL, dob DATE, professor_id NOT NULL, Name varchar(200) Constraint id_unique UNIQUE(id,dob) );

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

Explain foreign key constraint.

Answer

A foreign key is a reference to another table. It is used to establish relationships between tables. For example, relationship between employee and professor table. One employee can have multiple professors. The Primary key of employee becomes foreign key of professor.
Example:
create table employee ( id number NOT NULL, professor_id NOT NULL, Name varchar(200) Constraint prim_id Foreign key(id) references professor(professor_id) );

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

Explain primary key constraint.

Answer

Primary key constraint ensures that the column(s) always has a unique value to identify the record.
Example:
Below, the primary key is created for column id with name prim_id.
create table employee ( id number NOT NULL, Name varchar(200) Constraint prim_id primary key(id) );

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

Explain Not Null constraint.

Answer

Oracle NOT NULL is used on a column to ensure that the value for that column can never be NULL.
Example:
Below, the constraint is that the id should never be NULL. If it is, oracle throws an error.
create table employee ( id number NOT NULL, Name varchar(200) );

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle

Q:

Explain Check constraint.

Answer

Oracle check constraint is used to ensure that before inserting the data in the database, it is validated and checked for the condition.
Example:
Below, the constraint is that the id has to be between 0 and 1000.
create table employee ( id number check (id between 0 and 1000), Name varchar(200) );

Report Error

View answer Workspace Report Error Discuss

Subject: Oracle