Adding a UNIQUE Constraint
The following ALTER TABLE
statement adds a UNIQUE
constraint to the emp.empno
column:
SQL> CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL,
2 ENAME VARCHAR2(10),
3 JOB VARCHAR2(9),
4 SAL NUMBER(7, 2),
5 DEPTNO NUMBER(2));
Table created.
SQL>
SQL> ALTER TABLE emp
2 ADD CONSTRAINT empno_uq UNIQUE (empno);
Table altered.
SQL>
Any existing or new rows must always have a unique value in the status column.
Home »
Oracle »
Table »
Oracle »
Table »
Constraints:
- Adding a Constraint with CHECK
- Adding a NOT NULL Constraint
- Adding a FOREIGN KEY Constraint
- ON DELETE CASCADE
- ON DELETE SET NULL
- Adding a UNIQUE Constraint
- CHECK constraint
- Multiple Constraints
- Dropping a Constraint
- Disabling a Constraint
- Enabling a Constraint
- Deferred Constraints
- Getting Information on Constraints:user_constraints and all_constraints
Related: