Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6598249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:19:10+00:00 2026-05-25T18:19:10+00:00

Could someone clarify what is the purpose of having unique index without unique constraint

  • 0

Could someone clarify what is the purpose of having unique index without unique constraint (Oracle)?
For example,

create table test22(id int, id1 int, tmp varchar(20));
create unique index idx_test22 on test22(id);
insert into test22(id, id1, tmp) values (1, 2, 'aaa'); // ok
insert into test22(id, id1, tmp) values (1, 2, 'aaa'); // fails, ORA-00001: unique   
  // constraint (TEST.IDX_TEST22) violated

So far it looks like there is a constraint. But

create table test33(id int not null primary key, 
test22_id int not null, 
foreign key(test22_id) references test22(id) );

also fails with "ORA-02270: no matching unique or primary key for this column-list".
I’m totally confused by this behaviour. Is there a constraint or not?

There are many articles that explain why it’s possible to have a unique constraint without unique index; that is clear and makes perfect sense. However, I don’t understand the reason for unique index without constraint.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:19:12+00:00Added an answer on May 25, 2026 at 6:19 pm

    A constraint and an index are separate logical entities. A unique constraint, for example, is visible in USER_CONSTRAINTS (or ALL_CONSTRAINTS or DBA_CONSTRAINTS). An index is visible in USER_INDEXES (or ALL_INDEXES or DBA_INDEXES).

    A unique constraint is enforced by an index though it is possible (and sometimes necessary) to enforce a unique constraint using a non-unique index. A deferrable unique constraint, for example, is enforced using a non-unique index. If you create a non-unique index on a column and subsequently create a unique constraint, you can also use that non-unique index to enforce the unique constraint.

    In practice, a unique index acts very much like a unique, non-deferrable constraint in that it raises the same error that a unique constraint raises since the implementation of unique constraints uses the index. But it is not quite the same because there is no constraint. So, as you’ve seen, there is no unique constraint so you cannot create a foreign key constraint that references the column.

    There are cases where you can create a unique index that you cannot create a unique constraint. A function-based index, for example, that enforces conditional uniqueness. If I wanted to create a table that supported logical deletes but ensure that COL1 is unique for all non-deleted rows

    SQL> ed
    Wrote file afiedt.buf
    
      1  CREATE TABLE t (
      2    col1 number,
      3    deleted_flag varchar2(1) check( deleted_flag in ('Y','N') )
      4* )
    SQL> /
    
    Table created.
    
    SQL> create unique index idx_non_deleted
      2      on t( case when deleted_flag = 'N' then col1 else null end);
    
    Index created.
    
    SQL> insert into t values( 1, 'N' );
    
    1 row created.
    
    SQL> insert into t values( 1, 'N' );
    insert into t values( 1, 'N' )
    *
    ERROR at line 1:
    ORA-00001: unique constraint (SCOTT.IDX_NON_DELETED) violated
    
    
    SQL> insert into t values( 1, 'Y' );
    
    1 row created.
    
    SQL> insert into t values( 1, 'Y' );
    
    1 row created.
    

    But if we’re talking about a straight unique non-function based index, there are probably relatively few cases where it really makes more sense to create the index rather than creating the constraint. On the other hand, there are relatively few cases where it makes much difference in practice. You’d almost never want to declare a foreign key constraint that referenced a unique constraint rather than a primary key constraint so you rarely lose something by only creating the index and not creating the constraint.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I'm not quite sure the difference between these languages. Could someone clarify?
Could someone help me clarify the following conecpts, and the relationship among them ?
Could someone clarify for me what input Flash accepts for its text fields? I
I'm not able to understand the following multi-dimensional code. Could someone please clarify me?
Could someone please clarify for me the semantic difference between these two: self.foo =
Could someone please be kind enough to explain to me what the purpose of
I'm developing an iPad application using Core Data, and was hoping someone could clarify
Firstly could someone clarify whether in C++ the use of the [] operator in
This was probably asked somewhere but I couldn't find it. Could someone clarify why
I was just hoping someone could clarify this for me. If I have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.