Oracle Unique | Unique - oracle tutorial - sql tutorial



Oracle unique

Learn oracle - oracle tutorial - Oracle unique - oracle examples - oracle programs

What is unique constraint in oracle ?

  • A unique constraint is a single field or combination of fields that uniquely defines a record.
  • Some of the fields can contain null values as long as the combination of values is unique.

Difference Between Primary Key and Unique Key:

Primary Key:

  • None of the fields that are part of the primary key can contain a null value.

Unique Key:

  • Some of the fields that are part of the unique constraint can contain null values as long as the combination of values is unique.
oracle tutorial , sql tutorial , sql , pl sql tutorial , oracle , pl sql , plsql

Syntax

CREATE TABLE table_name
     (
        column1 datatype [ NULL | NOT NULL ],
        column2 datatype [ NULL | NOT NULL ] ...
         CONSTRAINT constraint_name UNIQUE (uc_col1,   uc_col2, ... uc_col_n)
      );
click below button to copy the code. By - oracle tutorial - team

Parameters or Arguments

table_name

  • The name of the table that you wish to create.

column1, column2

  • The columns that you wish to create in the table

constraint_name

  • The name of the unique constraint.

uc_col1, uc_col2, ... uc_col_n

  • The columns that make up the unique constraint.

Example

CREATE TABLE wikitechy(
                   Emp_Id int NOT NULL,
                   Emp_Name varchar(20) NOT NULL, 
                   Position varchar(20),
                   City varchar(20) ,
                  CONSTRAINT wikitechy_unique UNIQUE ( Emp_Id)  );
click below button to copy the code. By - oracle tutorial - team
 unique table
  1. Insert the values in the wikitechy_emp table by using INSERT Statement.
  2. .
  3. Click Run button to execute the query.
  4. We can see the row which has been successfully inserted in the wikitech_emp table

Disable:

Syntax

  • ALTER TABLE table_name DISABLE CONSTRAINT constraint_name;

Example

    ALTER TABLE wikitechy DISABLE CONSTRAINT wikitechy_unique;
click below button to copy the code. By - oracle tutorial - team
 enable table

Enable:

Syntax

ALTER TABLE table_name ENABLE CONSTRAINT constraint_name;
click below button to copy the code. By - oracle tutorial - team

Example

ALTER TABLE wikitechy ENABLE CONSTRAINT wikitechy_unique;
click below button to copy the code. By - oracle tutorial - team
 enable table

Drop:

Syntax

ALTER TABLE table_name DROP CONSTRAINT constraint_name;
click below button to copy the code. By - oracle tutorial - team

Example

ALTER TABLE wikitechy DROP CONSTRAINT wikitechy_unique;
click below button to copy the code. By - oracle tutorial - team
 drop table

This tutorial provides an indepth knowledge on the following items such as oracle tutorial , sql tutorial , sql , pl sql tutorial , oracle , pl sql , mysql tutorial , sql tutorial for beginners , learn sql , oracle database tutorial , sql query tutorial , oracle dba tutorial , plsql tutorial , oracle tutorial pdf , oracle pl sql tutorial , oracle sql tutorial , sql tutorial point , oracle tutorial for beginners , learn oracle online free , learn oracle online , learning pl sql programming , learn sql online for free , sql learning online , dba oracle tutorial , oracle sql tutorial advanced , oracle 11g dba tutorial with examples , oracle online learning , oracle learning online , how to learn pl sql , sql coding tutorial , sql learning websites , sql basic learning

Related Searches to Oracle Unique | Unique