A unique constraint is called a unique constraint, and you can set the field values entered in the table to be unique, similar to the primary key, except that the unique constraint can have more than one, and the primary key can only have a field that is not a primary key but is guaranteed to be unique, it is possible to suggest a unique constraint
(1) Adding a unique constraint
"1" adds a unique constraint while creating a table
Add a unique constraint when creating a table, after creating the table
Grammar:
CONSTRAINT Constraint name UNIQUE (field name)
Example:
create table orderinfo ( orderid varchar2 (Ten),        CUSTOMID VARCHAR2 (, ) productid varchar2 (Ten), orderdate varchar2 (Ten), orderquality varchar2 (Ten), senddate varchar2 (Ten), [constraint unq_orderid] unique (ORDERID) );
"2" adds a unique constraint using alter
Grammar:
ALTER table name ADD CONSTRAINT constraint name unique (field name)
Example:
ALTER TABLE ORDERINFO ADD CONSTRAINT unq_orderid UNIQUE (ORDERID);
(2) View UNIQUE constraints
Syntax:
Select cu.* from User_cons_columns cu, user_constraints au where cu.constraint_name = Au.constraint_name and Au.constrai Nt_type = ' U ' and au.table_name = ' table name ';
Example:
Select cu.* from User_cons_columns cu, user_constraints au where cu.constraint_name = Au.constraint_name and Au.constrai Nt_type = ' U ' and au.table_name = ' ORDERINFO ';
(3) Delete Unique constraint
Syntax:
ALTER TABLE table_name DROP CONSTRAINT constraint_name;
Example:
--delete the unique constraint for the Order Information table
ALTER TABLE ORDERINFO DROP CONSTRAINT Unq_orderid;
This article is from the "Loly_zhang" blog, make sure to keep this source http://lolyzhang.blog.51cto.com/10029387/1889005
Oracle database Add, query, delete unique constraint