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 8025231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:06:00+00:00 2026-06-04T23:06:00+00:00

I have two tables, Table JOB and Table USER , here is the structure

  • 0

I have two tables, Table JOB and Table USER, here is the structure

 CREATE TABLE JOB
 (
   ID       NUMBER NOT NULL ,
   USERID   NUMBER,
   CONSTRAINT B_PK PRIMARY KEY ( ID ) ENABLE
 );

 CREATE TABLE USER
 (
   ID       NUMBER NOT NULL ,
   CONSTRAINT U_PK PRIMARY KEY ( ID ) ENABLE
 );

Now, i want to add foreign key constraint to JOB referencing to USER table, as

Alter Table JOB ADD CONSTRAINT FK_USERID FOREIGN KEY(USERID) REFERENCES USER(ID);

this throws Oracle (ORA-02270) : no matching unique or primary key for this column-list error, doing some investigation it appears that we need to have either unique key or primary key constraint on USERID but I cannot have that as one USERID can have multiple JOBS associated with him, any thoughts or suggestions on how to fix this issue?

Researched ORA-02270 and SO related question

  • 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-06-04T23:06:02+00:00Added an answer on June 4, 2026 at 11:06 pm

    The ORA-2270 error is a straightforward logical error: it happens when the columns we list in the foreign key do not match a primary key or unique constraint on the parent table. Common reasons for this are

    • the parent lacks a PRIMARY KEY or UNIQUE constraint altogether
    • the foreign key clause references the wrong column in the parent table
    • the parent table’s constraint is a compound key and we haven’t referenced all the columns in the foreign key statement.

    Neither appears to be the case in your posted code. But that’s a red herring, because your code does not run as you have posted it. Judging from the previous edits I presume you are not posting your actual code but some simplified example. Unfortunately in the process of simplification you have eradicated whatever is causing the ORA-2270 error.

    SQL> CREATE TABLE JOB
     (
       ID       NUMBER NOT NULL ,
       USERID   NUMBER,
       CONSTRAINT B_PK PRIMARY KEY ( ID ) ENABLE
     );  2    3    4    5    6  
    
    Table created.
    
    SQL> CREATE TABLE USER
     (
       ID       NUMBER NOT NULL ,
       CONSTRAINT U_PK PRIMARY KEY ( ID ) ENABLE
     );  2    3    4    5  
    CREATE TABLE USER
                 *
    ERROR at line 1:
    ORA-00903: invalid table name
    
    
    SQL> 
    

    That statement failed because USER is a reserved keyword so we cannot name a table USER. Let’s fix that:

    SQL> 1
      1* CREATE TABLE USER
    SQL> a s
      1* CREATE TABLE USERs
    SQL> l
      1  CREATE TABLE USERs
      2   (
      3     ID       NUMBER NOT NULL ,
      4     CONSTRAINT U_PK PRIMARY KEY ( ID ) ENABLE
      5*  )
    SQL> r
      1  CREATE TABLE USERs
      2   (
      3     ID       NUMBER NOT NULL ,
      4     CONSTRAINT U_PK PRIMARY KEY ( ID ) ENABLE
      5*  )
    
    Table created.
    
    SQL> Alter Table JOB ADD CONSTRAINT FK_USERID FOREIGN KEY(USERID) REFERENCES USERS(ID);   
    
    Table altered.
    
    SQL> 
    

    And lo! No ORA-2270 error.

    Alas, there’s not much we can do here to help you further. You have a bug in your code. You can post your code here and one of us can spot your mistake. Or you can check your own code and discover it for yourself.


    Note: an earlier version of the code defined HOB.USERID as VARCHAR2(20). Because USER.ID is defined as a NUMBER the attempt to create a foreign key would have hurl a different error:

    ORA-02267: column type incompatible with referenced column type

    An easy way to avoid mismatches is to use foreign key syntax to default the datatype of the column:

    CREATE TABLE USERs
     (
       ID    number NOT NULL ,
       CONSTRAINT U_PK PRIMARY KEY ( ID ) ENABLE
     );
    
    CREATE TABLE JOB
     (
       ID       NUMBER NOT NULL ,
       USERID   constraint FK_USERID references users,
       CONSTRAINT B_PK PRIMARY KEY ( ID ) ENABLE
     );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two table: job with jobid, jobdescription, etc and user with userid, jobid,
I have two tables in my database as following: Employee Table: Username, Name, Job,
I have two tables Table public.tags_to_entities Column | Type | Modifiers --------+---------+----------- tid |
I have two tables: Table items: | id | name | description | |
I have two tables: table A id | level_ID | col_m | col_n table
I have two tables (Table A, Table B) joined with a join table (TableAB)
I have two tables Table A type_uid, allowed_type_uid 9,1 9,2 9,4 1,1 1,2 24,1
Assume I have two tables: Table MY_ENTITY ID: PK OTHER_ID: FK to table OTHER
I have two tables : one table it matchs and the other is teams.
I have two tables: a schedule table that contains information about how an employee

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.