Violate an unique constraints : Unique « Table « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE TABLE person (
  2       person_code VARCHAR2(3) PRIMARY KEY,
  3       first_name  VARCHAR2(15),
  4       last_name   VARCHAR2(20),
  5       hire_date   DATE
  6       );

Table created.

SQL>
SQL> ALTER TABLE person
  2  ADD CONSTRAINT person_unique UNIQUE (
  3       first_name,
  4       last_name,
  5       hire_date
  6       );

Table altered.

SQL>
SQL>
SQL>
SQL> INSERT INTO person VALUES ('CA', 'Chase', 'At', '01-FEB-02');

1 row created.

SQL> INSERT INTO person VALUES ('GA', 'Chase', 'At', '01-FEB-02');
INSERT INTO person VALUES ('GA', 'Chase', 'At', '01-FEB-02')
*
ERROR at line 1:
ORA-00001: unique constraint (JAVA2S.PERSON_UNIQUE) violated


SQL> INSERT INTO person VALUES ('BB', 'Bob', 'Bark', '28-FEB-02');

1 row created.

SQL> INSERT INTO person VALUES ('LB', 'Laren', 'Baby', '01-MAR-02');

1 row created.

SQL> INSERT INTO person VALUES ('LN', 'Linda', 'Norman', '01-JUN-03');

1 row created.

SQL>
SQL> select * from person;

PER FIRST_NAME      LAST_NAME            HIRE_DATE
--- --------------- -------------------- ---------
CA  Chase           At                   01-FEB-02
BB  Bob             Bark                 28-FEB-02
LB  Laren           Baby                 01-MAR-02
LN  Linda           Norman               01-JUN-03

SQL>
SQL> drop table person;

Table dropped.

SQL>
SQL>








6.12.Unique
6.12.1.Adding a UNIQUE Constraint
6.12.2.Add unique constraint across more than one columns
6.12.3.Add unique constraints for combined columns
6.12.4.Add unique constaint to new added column
6.12.5.Violate an unique constraints
6.12.6.Add unique constraints
6.12.7.ORA-00001: unique constraint (JAVA2S.JOB_UNIQUE_IN_TEAMID) violated