ORA-02270: Error report: no matching unique or primary key for this column list












0















I have created two tables:



CREATE TABLE team (
teamname VARCHAR2(30) NOT NULL,
carndate DATE NOT NULL,
teamnomembers NUMBER(2) NOT NULL,
charname VARCHAR2(30),
entryno NUMBER(4) NOT NULL
);

COMMENT ON COLUMN team.teamname IS
'Team name';

COMMENT ON COLUMN team.carndate IS
'Date of carnival';

COMMENT ON COLUMN team.teamnomembers IS
'Number of team members';

COMMENT ON COLUMN team.charname IS
'Approved charity name';

COMMENT ON COLUMN team.entryno IS
'Team leader for this team in this carnival';

ALTER TABLE team ADD CONSTRAINT team_pk PRIMARY KEY ( teamname,
carndate );


and another:



CREATE TABLE entry (
entryno NUMBER(4) NOT NULL,
carndate DATE NOT NULL,
entrystarttime DATE NOT NULL,
entryfinishtime DATE NOT NULL,
entryplace NUMBER(4) NOT NULL,
charname VARCHAR2(30) NOT NULL,
compno NUMBER(4) NOT NULL,
eventypecode CHAR(3) NOT NULL,
teamname VARCHAR2(30) NOT NULL
);

ALTER TABLE entry ADD CONSTRAINT entry_pk PRIMARY KEY ( entryno,
carndate );

ALTER TABLE entry
ADD CONSTRAINT entry_charity_fk FOREIGN KEY ( charname )
REFERENCES charity ( charname );

ALTER TABLE entry
ADD CONSTRAINT entry_carnival_fk FOREIGN KEY ( carndate )
REFERENCES carnival ( carndate );

ALTER TABLE entry
ADD CONSTRAINT entry_team_fk FOREIGN KEY ( teamname )
REFERENCES team ( teamname );


When i run the script in Oracle, I'm getting an error report saying no matching unique or primary key for this column list.



*Cause:    A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view


and the error is reported at the Entry table, where i set the foreign key "teamname" at the last line. Why am i getting this error?










share|improve this question














bumped to the homepage by Community 38 secs ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 2





    Add a unique constraint / index on team.teamname alone

    – Philᵀᴹ
    May 10 '18 at 16:24
















0















I have created two tables:



CREATE TABLE team (
teamname VARCHAR2(30) NOT NULL,
carndate DATE NOT NULL,
teamnomembers NUMBER(2) NOT NULL,
charname VARCHAR2(30),
entryno NUMBER(4) NOT NULL
);

COMMENT ON COLUMN team.teamname IS
'Team name';

COMMENT ON COLUMN team.carndate IS
'Date of carnival';

COMMENT ON COLUMN team.teamnomembers IS
'Number of team members';

COMMENT ON COLUMN team.charname IS
'Approved charity name';

COMMENT ON COLUMN team.entryno IS
'Team leader for this team in this carnival';

ALTER TABLE team ADD CONSTRAINT team_pk PRIMARY KEY ( teamname,
carndate );


and another:



CREATE TABLE entry (
entryno NUMBER(4) NOT NULL,
carndate DATE NOT NULL,
entrystarttime DATE NOT NULL,
entryfinishtime DATE NOT NULL,
entryplace NUMBER(4) NOT NULL,
charname VARCHAR2(30) NOT NULL,
compno NUMBER(4) NOT NULL,
eventypecode CHAR(3) NOT NULL,
teamname VARCHAR2(30) NOT NULL
);

ALTER TABLE entry ADD CONSTRAINT entry_pk PRIMARY KEY ( entryno,
carndate );

ALTER TABLE entry
ADD CONSTRAINT entry_charity_fk FOREIGN KEY ( charname )
REFERENCES charity ( charname );

ALTER TABLE entry
ADD CONSTRAINT entry_carnival_fk FOREIGN KEY ( carndate )
REFERENCES carnival ( carndate );

ALTER TABLE entry
ADD CONSTRAINT entry_team_fk FOREIGN KEY ( teamname )
REFERENCES team ( teamname );


When i run the script in Oracle, I'm getting an error report saying no matching unique or primary key for this column list.



*Cause:    A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view


and the error is reported at the Entry table, where i set the foreign key "teamname" at the last line. Why am i getting this error?










share|improve this question














bumped to the homepage by Community 38 secs ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 2





    Add a unique constraint / index on team.teamname alone

    – Philᵀᴹ
    May 10 '18 at 16:24














0












0








0








I have created two tables:



CREATE TABLE team (
teamname VARCHAR2(30) NOT NULL,
carndate DATE NOT NULL,
teamnomembers NUMBER(2) NOT NULL,
charname VARCHAR2(30),
entryno NUMBER(4) NOT NULL
);

COMMENT ON COLUMN team.teamname IS
'Team name';

COMMENT ON COLUMN team.carndate IS
'Date of carnival';

COMMENT ON COLUMN team.teamnomembers IS
'Number of team members';

COMMENT ON COLUMN team.charname IS
'Approved charity name';

COMMENT ON COLUMN team.entryno IS
'Team leader for this team in this carnival';

ALTER TABLE team ADD CONSTRAINT team_pk PRIMARY KEY ( teamname,
carndate );


and another:



CREATE TABLE entry (
entryno NUMBER(4) NOT NULL,
carndate DATE NOT NULL,
entrystarttime DATE NOT NULL,
entryfinishtime DATE NOT NULL,
entryplace NUMBER(4) NOT NULL,
charname VARCHAR2(30) NOT NULL,
compno NUMBER(4) NOT NULL,
eventypecode CHAR(3) NOT NULL,
teamname VARCHAR2(30) NOT NULL
);

ALTER TABLE entry ADD CONSTRAINT entry_pk PRIMARY KEY ( entryno,
carndate );

ALTER TABLE entry
ADD CONSTRAINT entry_charity_fk FOREIGN KEY ( charname )
REFERENCES charity ( charname );

ALTER TABLE entry
ADD CONSTRAINT entry_carnival_fk FOREIGN KEY ( carndate )
REFERENCES carnival ( carndate );

ALTER TABLE entry
ADD CONSTRAINT entry_team_fk FOREIGN KEY ( teamname )
REFERENCES team ( teamname );


When i run the script in Oracle, I'm getting an error report saying no matching unique or primary key for this column list.



*Cause:    A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view


and the error is reported at the Entry table, where i set the foreign key "teamname" at the last line. Why am i getting this error?










share|improve this question














I have created two tables:



CREATE TABLE team (
teamname VARCHAR2(30) NOT NULL,
carndate DATE NOT NULL,
teamnomembers NUMBER(2) NOT NULL,
charname VARCHAR2(30),
entryno NUMBER(4) NOT NULL
);

COMMENT ON COLUMN team.teamname IS
'Team name';

COMMENT ON COLUMN team.carndate IS
'Date of carnival';

COMMENT ON COLUMN team.teamnomembers IS
'Number of team members';

COMMENT ON COLUMN team.charname IS
'Approved charity name';

COMMENT ON COLUMN team.entryno IS
'Team leader for this team in this carnival';

ALTER TABLE team ADD CONSTRAINT team_pk PRIMARY KEY ( teamname,
carndate );


and another:



CREATE TABLE entry (
entryno NUMBER(4) NOT NULL,
carndate DATE NOT NULL,
entrystarttime DATE NOT NULL,
entryfinishtime DATE NOT NULL,
entryplace NUMBER(4) NOT NULL,
charname VARCHAR2(30) NOT NULL,
compno NUMBER(4) NOT NULL,
eventypecode CHAR(3) NOT NULL,
teamname VARCHAR2(30) NOT NULL
);

ALTER TABLE entry ADD CONSTRAINT entry_pk PRIMARY KEY ( entryno,
carndate );

ALTER TABLE entry
ADD CONSTRAINT entry_charity_fk FOREIGN KEY ( charname )
REFERENCES charity ( charname );

ALTER TABLE entry
ADD CONSTRAINT entry_carnival_fk FOREIGN KEY ( carndate )
REFERENCES carnival ( carndate );

ALTER TABLE entry
ADD CONSTRAINT entry_team_fk FOREIGN KEY ( teamname )
REFERENCES team ( teamname );


When i run the script in Oracle, I'm getting an error report saying no matching unique or primary key for this column list.



*Cause:    A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view


and the error is reported at the Entry table, where i set the foreign key "teamname" at the last line. Why am i getting this error?







oracle oracle-11g-r2 foreign-key primary-key






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 10 '18 at 15:57









ElectricElectric

1




1





bumped to the homepage by Community 38 secs ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 38 secs ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 2





    Add a unique constraint / index on team.teamname alone

    – Philᵀᴹ
    May 10 '18 at 16:24














  • 2





    Add a unique constraint / index on team.teamname alone

    – Philᵀᴹ
    May 10 '18 at 16:24








2




2





Add a unique constraint / index on team.teamname alone

– Philᵀᴹ
May 10 '18 at 16:24





Add a unique constraint / index on team.teamname alone

– Philᵀᴹ
May 10 '18 at 16:24










1 Answer
1






active

oldest

votes


















0














Foreign keys must reference another table's primary key, or a unique column in the other table (that is, a column with a unique constraint or index of some sort).



teamname is not unique in team, so a foreign key cannot link to it.



you need to either make teamname unique in team, or use a composite foreign key to match `team's composite primary key:



ALTER TABLE entry
ADD CONSTRAINT entry_team_fk FOREIGN KEY ( teamname, carndate )
REFERENCES team ( teamname, carndate );


Note: carndate may not be appropriate for this foreign key - just using it as an example. You would know best if there's a date in entry that would match team.carndate.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "182"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f206384%2fora-02270-error-report-no-matching-unique-or-primary-key-for-this-column-list%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Foreign keys must reference another table's primary key, or a unique column in the other table (that is, a column with a unique constraint or index of some sort).



    teamname is not unique in team, so a foreign key cannot link to it.



    you need to either make teamname unique in team, or use a composite foreign key to match `team's composite primary key:



    ALTER TABLE entry
    ADD CONSTRAINT entry_team_fk FOREIGN KEY ( teamname, carndate )
    REFERENCES team ( teamname, carndate );


    Note: carndate may not be appropriate for this foreign key - just using it as an example. You would know best if there's a date in entry that would match team.carndate.






    share|improve this answer




























      0














      Foreign keys must reference another table's primary key, or a unique column in the other table (that is, a column with a unique constraint or index of some sort).



      teamname is not unique in team, so a foreign key cannot link to it.



      you need to either make teamname unique in team, or use a composite foreign key to match `team's composite primary key:



      ALTER TABLE entry
      ADD CONSTRAINT entry_team_fk FOREIGN KEY ( teamname, carndate )
      REFERENCES team ( teamname, carndate );


      Note: carndate may not be appropriate for this foreign key - just using it as an example. You would know best if there's a date in entry that would match team.carndate.






      share|improve this answer


























        0












        0








        0







        Foreign keys must reference another table's primary key, or a unique column in the other table (that is, a column with a unique constraint or index of some sort).



        teamname is not unique in team, so a foreign key cannot link to it.



        you need to either make teamname unique in team, or use a composite foreign key to match `team's composite primary key:



        ALTER TABLE entry
        ADD CONSTRAINT entry_team_fk FOREIGN KEY ( teamname, carndate )
        REFERENCES team ( teamname, carndate );


        Note: carndate may not be appropriate for this foreign key - just using it as an example. You would know best if there's a date in entry that would match team.carndate.






        share|improve this answer













        Foreign keys must reference another table's primary key, or a unique column in the other table (that is, a column with a unique constraint or index of some sort).



        teamname is not unique in team, so a foreign key cannot link to it.



        you need to either make teamname unique in team, or use a composite foreign key to match `team's composite primary key:



        ALTER TABLE entry
        ADD CONSTRAINT entry_team_fk FOREIGN KEY ( teamname, carndate )
        REFERENCES team ( teamname, carndate );


        Note: carndate may not be appropriate for this foreign key - just using it as an example. You would know best if there's a date in entry that would match team.carndate.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 10 '18 at 16:43









        RDFozzRDFozz

        9,88231530




        9,88231530






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Database Administrators Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f206384%2fora-02270-error-report-no-matching-unique-or-primary-key-for-this-column-list%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL Server 17 - Attemping to backup to remote NAS but Access is denied

            Always On Availability groups resolving state after failover - Remote harden of transaction...

            Restoring from pg_dump with foreign key constraints