foreign key mapped to a unique constraint

OK, here's the question

create a parent of the table (col1, col2 char char);
alter table add constraint pk_parent key (col1) parent primary;
alter table add constraint uk_parent unique(col1,col2) parent;

Insert into parent values ('A', '7');

* 1 row created.*

create the child table (col1, col2 char char);
ALTER table child add constraint fk_child_parent foreign key(col1,col2) references parent(col1,col2);

insert into values('B','4') of the child;

insert into the child values('B','4')
***
ERROR on line 1:
ORA-02291: integrity constraint (WILDGOD. FK_CHILD_PARENT) violated - parent key
not found

That's what I expect... but

insert into values('B',) of the child;

* 1 row created.*


why he let me do, I realize its because col2 is NULL, but it should not yet check for col1 in the parent?

Please clarify, thanks in advance.

Documented behavior.

See here:
http://download.Oracle.com/docs/CD/E11882_01/AppDev.112/e10471/adfns_constraints.htm#ADFNS273

-Mark

Tags: Database

Similar Questions

  • Is a foreign key MUST have a UNIQUE or PK column as a reference?

    First I tried, from what I saw Yes it must be Unique or PK. Secondly, I am pretty sure that I read somewhere where there are PK or unique. Thirdly, I checked oradocs and other pages, the thing ends, I owe an answer

    Constraint foreign key (also called a constraint referential integrity) designates a column as a foreign key and establishes a relationship between this foreign key and a primary or unique key specified, called the referenced key.


    This implies, but does not explicitly specify that it MUST be a PK or a SINGLE.


    Basically I want a simple yes/no answer just to give me some peace of mind. I don't want to waste any time, but changes to the oracle from time to time, and I'd rather have a confirmation from someone with more knowledge/experience.


    Thank you!

    Yes.

    This same document you are referencing tells you what are the rules for the creation of a foreign key.

    Data integrity

    Foreign key constraints

    Whenever two tables have one or more common columns, Oracle database can apply the relationship between the two tables with a foreign key, also called a referential integrity constraint constraint. The constraint requires that for each value in the column on which the constraint is defined, the value in the other specified that another table and column must match. An example of a referential integrity rule is that an employee may work for only one Department.

    Table 5-2 lists the terms associated with referential integrity constraints.

    Table 5-2 referential integrity constraint conditions

    Term Definition

    Foreign key

    The column or set of columns included in the constraint definition that refers to a key that is referenced. For example, the department_id column employees is a foreign key that refers to the department_id column of departments .

    Foreign keys can be described as several columns. However, a composite foreign key must refer to a primary or unique key with the same number of columns and the same types of data.

    The value of the foreign keys can be either the primary or unique key value referenced or be null. If any column of a composite foreign key is null, then the portions not null the key do not match any corresponding part of a parent key.

    Referenced key

    The unique key or the primary key of the table referenced by a foreign key. For example, the department_id column departments is the key referenced to the department_id column of employees .

    Table dependent or child

    The table containing the foreign key. This table is based on the values present in the primary or unique key referenced. For example, the employees table is a child of departments .

    Referenced or the parents table

    The table that is referenced by the foreign key of the child table. It is the key to this table reference that determines whether specific inserts or updates are allowed in the child table. For example, the departments table is a parent of employees .

    The first three terms defined in the table EXPLICITLY State references to the 'core' or 'unique' keys to the parent.

    The doc also refers to the Application Developer Guide:

    Maintaining the integrity of the data in Database Applications

    Foreign key references a primary key by default

    If the list of columns is not included in the REFERENCES option when you set a FOREIGN KEY constraint (simple or composite column), then Oracle database assumes that you want to reference the primary key of the specified table. You can also explicitly specify the columns to reference the table parent in parentheses. Oracle database checks automatically to check this list of column refers to a primary or unique to the parent table key. If it isn't, an informative error is returned.

    That the entire paragraph is as explicitly as it gets.

    No list of columns? Oracle then checks for a primary key.

    There is a list of columns? Then Oracle 'control to verify this list of column made reference to a primary or unique key'...

  • A foreign key can reference a unique non-primary key?

    Hello everyone, I have 2 tables: [books] with the fields (id, title, author, isbn) and another table called [issue Book] with the fields (id, borrower_id, borrow_date, book_isbn)...
    Now the field (book_isbn) in the [book number] table of authorities (isbn) in the table [books], which is a single field, but not a primary key.

    My questions:

    1 - is this OK for a foreign key referencing a unique key but no primary in another table?

    2 is it normal that the foreign key field to have another name as the field it references in another table?

    Your help is appreciated indeed...

    Yes CF can refer to Unique key, but you must specify the Unique key column when the creation of FK

    and YES FK may have a different name, but for your convenience, we use the same column name

    Here is an example

    create table mymaster
    (val_id number unique);
    
    create table mydetail
    (det_id number,
     val_id_fk number references mymaster(val_id));
    

    Please mark correct / useful if it is

    Bangoura
    [My Oracle Blog | http://baigsorcl.blogspot.com/]

  • Get the "unique constraint" error while mapping custom jsp

    Hello

    We are implementing iStore R12 (12.1.3).

    We have customized ibeCCtdMenu.jsp, renamed as xxibeCCtdMenu.jsp and moved to $OA_HTML / folder.

    Now in the template Manager, we create a new source (xxibeCCtdMenu.jsp) file to the title of "model of generation of Menu".

    However when we select site and language like 'All', it gives following error:
    Error in the logical record of physical mapping
    ORA-00001: unique constraint (IBE. IBE_DSP_LGL_PHYS_MAP_U2) violated in the package IBE_PhysicalMap_GRP procedure save_physicalmap
    All the sites and all the language already exists exists for 7670 deliverable

    How can we overcome them this error? Please notify.
    Thank you
    Vivek

    for a given Site and the language combination, can exist only one model.
    Default file provided by Oracle is set with combination like all Sites - all languages, and you will not be able to change it.

    Save your file with combination such as all Sites - English
    or , all languages.

    Then it will work fine.

    Hrishikesh

  • stored procedure to disable all foreign key constraints?

    Hi all

    I need a stored procedure to disable / enable all the constraints in the database schema.

    Create or replace procedure enable_disable_proc (status varchar2 schema_name varchar2 (20)) (3).
    ......
    ....
    ...


    -> where the 'status' parameter condition must be (YES to activate) (NO to disable)
    -> 'schema_name' is a setting where, this scheme should be affected by this procedure.


    Thanks in advance...

    Sorry Raineau, you have said foreign keys in the thread title, constraints cannot be turned on and off like that.

    So for foreign keys:

    CREATE OR REPLACE PROCEDURE enab_disab_proc (
       status          IN   VARCHAR2,
       current_schema   IN   VARCHAR2
    )
    IS
    
    BEGIN
       FOR cur_rec IN (SELECT table_name, constraint_name
                         FROM user_constraints
                        WHERE owner = current_schema
                            AND constraint_type  = 'R')
         LOOP
          EXECUTE IMMEDIATE 'ALTER TABLE ' || cur_rec.table_name
                                           || CASE status WHEN 'YES' THEN ' ENABLE ' ELSE ' DISABLE ' END
                                           || 'CONSTRAINT '
                                           || cur_rec.constraint_name;
    
         END LOOP;
    
    END;
    / 
    
  • Drop partition without disabling the foreign key

    Hi all

    I have a table parent and child.

    Parent table

    create the table parent_1
    (identification number,
    create_date date,
    Constraint parent_1_pk001 PRIMARY KEY (id))
    PARTITION OF RANGE (create_date)
    INTERVAL (NUMTODSINTERVAL(1,'DAY'))
    (PARTITION parent_1_part VALUES LESS THAN (January 1, 2010 '));

    Child table
    create the table child_1
    (identification number,
    create_date date,
    Constraint child_1_fk001 FOREIGN KEY (id)
    REFERENCES parent_1 (id))
    PARTITION OF RANGE (create_date)
    INTERVAL (NUMTODSINTERVAL(1,'DAY'))
    (PARTITION create_date_part VALUES LESS THAN (January 1, 2010 '));


    I have problems to delete partition.
    Parent_1
    1 JULY 26, 12
    2 JULY 26, 12

    Child_1
    1 JULY 26, 12

    ALTER drop partition table CHILD_1 SYS_P274;
    table altered CHILD_1.

    ON THE PARENT PARTITION A FALL
    ALTER drop partition table parent_1 SYS_P273;

    Error report:
    SQL error: ORA-02266: unique/primary keys in table referenced by foreign keys enabled
    02266 00000 - "unique/primary keys in table referenced by foreign keys enabled.
    * Cause: An attempt was made to truncate a single table or
    primary keys referenced by foreign keys in another table.
    Other unauthorized trades are a drop/truncate partition a
    partitioned table or an ALTER TABLE EXCHANGE PARTITION.
    * Action: Before performing the operations described above, the table, disable the
    constraints foreign key in other tables. You can see what
    constraints are making reference to a table by issuing the following
    command:
    SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'tabnam ';


    PLEASE KNOW IF THERE IS A WAY TO THE PARENT PARTITION DROP WITHOUT TOGGLE FOREIGN CONSTRAINTS


    Thank you
    SQL Error: ORA-02266: unique/primary keys in table referenced by enabled foreign keys
    02266. 00000 - "unique/primary keys in table referenced by enabled foreign keys"
    *Cause: An attempt was made to truncate a table with unique or
    primary keys referenced by foreign keys enabled in another table.
    Other operations not allowed are dropping/truncating a partition of a
    partitioned table or an ALTER TABLE EXCHANGE PARTITION.
    *Action: Before performing the above operations the table, disable the
    foreign key constraints in other tables. 
    

    You can do until you disable the foreign key constraint

    http://jonathanlewis.WordPress.com/2006/12/10/drop-parent-partition/

    Hope this helps

    Mohamed Houri
    www.hourim.WordPress.com

  • CFTransaction, several inserts and foreign keys

    Here is the joke of what I want to do

    < cfset commitit = yes >
    < cftransaction action = start >
    < cftry >
    < cfquery >
    making my first insertion on the main table - primary key is the unique sequence number
    < / cfquery >
    < cfquery >
    do my next insertion in the second, but it has a foreign key to the intial insert constraint
    < cfquery >
    < cfquery >
    do my next insertion in the third table, but it has a foreign key to the intial insert constraint
    < cfquery >
    < cfcatch >
    < commitit = no >
    Rollback
    < / cfcatch >
    If commitit = yes
    commit the changes
    endif
    < / cftry >
    < / cftransaction >
    Problem is when I try to insert the record in the second table, the first record (parent) is not here because no validation has yet arrived. I get a foreign key error. I want to do within a transaction so that I can do a restore if there are questions. Is it possible to do in a cftransaction?

    I want to thank you all for your answers. The code I had was OK. I kept changing the code for serialization, because it makes sense in this case. I needed to get back to the basics - my definition of foreign key was in trouble. Thanks to you all.

  • Need help with cause of foreign key

    Hi all

    Kindly help me to understand the scenario mentioned below...

    Please refer below

    I create a table of TabA as below with more details...
    SQL> create table TabA
      2  (cola  varchar2(10) not null,
      3   colb  number(19)   not null,
      4   colc  varchar2(1));

    Table created.

    SQL> alter table taba add constraint taba_pk primary key(cola, colb);

    Table altered.

    SQL> alter table taba add constraint taba_uq unique(colb);

    Table altered.

    SQL> create index taba_idx on taba(cola, colc);

    Index created.
    Now I create a TabB table as below
    SQL> create table tabb
      2  (colb number(19) not null,
      3   cold number(10) not null,
      4   cole number);

    Table created.


    SQL> alter table tabb add constraint tabb_pk primary key(colb, cold);

    Table altered.

    SQL> alter table tabb add constraint
      2  tabb_fk foreign key(colb) references taba(colb)
      3  deferrable initially deferred;

    Table altered.
    Now, let us drop the key foreiogn of TabB and Unique constraint created on Colb of TabB. And create a unique index on colb of TabA.
    SQL> alter table tabb drop constraint tabb_fk;

    Table altered.

    SQL> alter table taba drop constraint taba_uq;

    Table altered.

    SQL> create unique index taba_uq on taba(colb);

    Index created.
    Now, try to recreate the foreign key on ColB of TabB constraint...
    SQL> alter table tabb add constraint
      2  tabb_fk foreign key(colb) references taba(colb)
      3  deferrable initially deferred;
    tabb_fk foreign key(colb) references taba(colb)
                                              *
    ERROR at line 2:
    ORA-02270: no matching unique or primary key for this column-list
    This time, it's giving an error. Why this behaves like that.

    Please explain?

    As previously explained his checking no primary key, but the constraint of uniqueness on tabA.

    You can remove the primary key of tabA, but retain the unique constraint of tabA and then create the foreign key on tabB.

    It will create the foreign key

    SQL>drop table tabb;
    
    Table dropped.
    
    SQL>drop table taba;
    
    Table dropped.
    
    SQL>create table TabA
      2  (cola  varchar2(10) not null,
      3   colb  number(19)   not null,
      4   colc  varchar2(1)
      5  );
    
    Table created.
    
    SQL>alter table taba add constraint taba_uq unique(colb);
    
    Table altered.
    
    SQL>create table tabb
      2  (colb number(19) not null,
      3   cold number(10) not null,
      4   cole number
      5  );
    
    Table created.
    
    SQL>alter table tabb add constraint tabb_fk foreign key(colb) references taba(colb) deferrable initi
    ally deferred;
    
    Table altered.
    

    Concerning
    Arun

  • correct handling of foreign keys in unique constraints for operations ON DELETE SET NULL

    During my troubleshooting at a client site, I came across an interesting setup where I would like to ask your opinion.


    Consider two tables ADTB and TBLB.

    ADTB:

    INT COLA1

    COLA2 INT

    TBLB:

    COLB1 INT

    COLA2 is COLB1 as a foreign key ON DELETE SET NULL value.

    COLA1 and COLA2 are combined into a UNIQUE for the BATTERY constraint.

    I have two records of TBLB:

    (1)

    (2)

    and two DRUM recordings:

    (1, 1)

    (2, 2)

    so far, all the constraints are valid.

    During my research, I learned that I can not put COLA2 null in ADTB for two lines at the same time:

    TBLA UPDATE set COLA2 = NULL where COLA1 = 1;

    -> OK

    TBLA UPDATE set COLA2 = NULL where COLA1 = 2;

    -> VIOLATED UNIQUE CONSTRAINT

    Unfortunately, it's something my application needs, anyway. In order to get this resolved, but I try to understand, what would happen if I:

    REMOVE THE TBLB;

    ?

    It should set COLA2 in ADTB "Null" on the two lines, which is not allowed due to the UNIQUE CONSTRAINT.

    Can someone shed light on this issue? Thank you.


    Yours,

    Ronny

    Unfortunately, as you say, you can't not NULL values in such a unique constraint.  It would be the same as if you had a composite primary key and try to allow one of the columns will be null in several rows with the same value in the other column.  NULL is treated as an "unknown" value, it is possible that it could be the same value (it may or may not be, but Oracle does not know), so it must assume that it might be and that's why treat it as if there is the potential for a duplicate... so it's not unique.

    In short, do not allow null values in your unique constraints.

    The default is in the drawing, not in the way that Oracle is the treatment.  Fix the design if you do not have NULL values.

    In terms of relational database design, it seems that you are trying to transform the 1:M relations M:M relations, and which requires an intermediate table if you have M:1 and 1:M between 3 tables instead.

  • ORA-02266: permit to unique/primary keys in table referenced by foreign keys

    Hello
    I'm trying to delete data from a table by dropping a partition. I've identified all the child tables by running the following command.

    Select "select count (*) from ' |" table_name |' where employee_id = 100; »
    of dba_constraints
    where constraint_type = 'R '.
    and r_constraint_name in
    (select constraint_name from dba_constraints
    where constraint_type in ('P', 'U') and table_name =' EMPLOYEE);


    "SELECTCOUNT (*) OF | TABLE_NAME | "WHEREEMPLOYEE_ID_ID = 100; »
    -----------------------------------------------------------------------------------------------
    Select count (*) in the PT_ORDERS where employee_id = 100;
    Select count (*) in the PT_DEP where employee_id = 100;
    Select count (*) in the PT_SKILLSET where employee_id = 100;

    I dropped the score for number 100 in all child tables. The count (*) select returns 0 rows for each of the foregoing.

    When I try to run the command on the EMPLOYEE table, below I get ' ORA-02266: unique/primary keys in table referenced by foreign keys enabled.

    Drop partition ALTER table EMPLOYEE EMP_ID_100;

    I don't see why I am unable to give up this partition now because it is data child present in any of the referenced tables. Any suggestions or help on this would be greatly appreciated.

    Thank you.

    RGS,
    Rob

    You must first disable foreign key constraints and delete the partition. Deletion of lines or a fall in childs partitions do not work in this case
    as you have the overall dependence:


    SQL > create table scott.t (x int primary key, int y)
    2 partition by (list (y)
    3 values p_1 (1) partition, partition values p_2 (2))
    4.

    Table created.

    SQL > create table scott.t_c (x int references scott.t (x), int y)
    2 partition by (list (y)
    3 values p_1 (1) partition, partition values p_2 (2))
    4.

    Table created.

    SQL > insert into scott.t values (1,1)
    3 N

    1 line of creation.

    SQL > insert into scott.t values (2,2)
    3 N

    1 line of creation.

    SQL > insert into scott.t_c values (1,1)
    3 N

    1 line of creation.

    SQL > insert into scott.t_c values (2,2)
    3 N

    1 line of creation.

    SQL > commit;

    Validation complete.

    SQL > alter table scott.t_c drop partition p_2.

    Modified table.

    SQL > alter table scott.t drop partition p_2.
    ALTER table drop partition p_2 scott.t
    *
    ERROR on line 1:
    ORA-02266: permit to unique/primary keys in table referenced by foreign keys

    SQL > select constraint_name from dba_constraints
    2 where owner = 'SCOTT' and constraint_type = 'P '.
    3 and table_name = 't';

    CONSTRAINT_NAME
    ------------------------------
    SYS_C0011058

    SQL > select constraint_name from dba_constraints
    2 where owner = 'SCOTT' and constraint_type = 'R '.
    3 and r_constraint_name = "SYS_C0011058";

    CONSTRAINT_NAME
    ------------------------------
    SYS_C0011059

    SQL > alter the constraint to disable scott.t_c table SYS_C0011059;

    Modified table.

    SQL > alter table scott.t drop partition p_2.

    Modified table.

    SQL > alter table scott.t_c enable novalidate constraint SYS_C0011059;

    Modified table.

    I guess you should consider options such as partitioning Referencial (with some restrictions).

    Best wishes
    Dmitry.

  • ORA-02449: unique/primary keys in table referenced by foreign keys

    SQL > create table empinformation
    () 2
    primary key pk_empinformation number (6) 3 forced mobileno
    4 address varchar (100),
    5 salary number (10),
    6 personalid varchar (10) constraints fk_employees_section references employee (emp_id));

    Table created.


    SQL > drop table empinformation;

    ORA-02449: unique/primary keys in table referenced by foreign keys

    solution

    This error happens when the foreign key of a table is referenced by the primary key of the other table.

    If you want to remove the table had refernce key then, you must
    need to remove this table with the foreign key is referenced.

    or

    SQL > drop table EMPLOYEE CASCADE CONSTRAINTS;
    Deleted table.

    This will remove the table parent without droping the child table.

    Published by: Ritesh Singh October 3, 2011 14:04

  • How to associate an index with a foreign key constraint

    I understand how to associate a primary key constraint or a Unique key constraint index...
    Yet I don't see how to associate the index of a foreign key constraint. Is this possible?

    Thank you
    Bob Larsen

    Hi Bob,

    In Data Modeler, physical model for Oracle primary and unique keys dialog boxes offer an Index field using, which is used to generate the 'using_index_clause' in the DDL for primary and Unique key constraints.
    However the Oracle Database DDL does not have the "using_index_clause" for Foreign Key constraints, thus Data Modeler does not provide this feature for foreign keys.

    So, you will need to create a separate Index that uses the same columns as the foreign key (using the index page of the table properties dialog box in the relational model).

    David

  • How to create a foreign key constraint on a table nested column

    Dear Experts,
    I create 2 tables using the object type. the VESSEL_PARAM table contains the list of the parameters allowed.
    The table VESSEL_TYPE containe single item we list some parameters.

    On this table, I love the column VESSEL_PARAM table VESSEL_PARAM to check if the settings are and the reference value is allowed.
    How to create a foreign key?
    Here my script that generates this runtime error: 00904. 00000 - '% s: invalid identifier' on this line

    ALTER TABLE VESSEL_PARAM_TAB ADD CONSTRAINT FK_VESSEL_TYPE FOREIGN KEY (NAME, DATA_VALUE)
    REFERENCES VESSEL_PARAM (PARAM_NAME, LIST_PARAM_VALUE. DATA_VALUE)
    CREATE OR REPLACE TYPE OBJ_PARAM_VALUE AS OBJECT 
    ( 
      DATA_VALUE  VARCHAR2(20)
     ,DESCRIPTION VARCHAR2(125)
    ) NOT FINAL;
    /
    
    CREATE OR REPLACE TYPE LIST_PARAM_VALUE AS TABLE OF OBJ_PARAM_VALUE;
    /
    
    -- derive object subtype from object supertype
    CREATE OR REPLACE TYPE OBJ_PARAM_NAME UNDER OBJ_PARAM_VALUE (
      NAME VARCHAR2(30)
    )NOT FINAL;
    /
    
    CREATE OR REPLACE TYPE LIST_PARAM_NAME AS TABLE OF OBJ_PARAM_NAME;
    /
    
    Prompt create table VESSEL_PARAM;
    CREATE TABLE VESSEL_PARAM (
       PARAM_NAME   VARCHAR2(20) NOT NULL
      ,PARAM_DESC   VARCHAR2(125)
      ,PARAM_VALUE  LIST_PARAM_VALUE
      ,CONSTRAINT PK_VESSEL_PARAM PRIMARY KEY (PARAM_NAME)
    ) 
    NESTED TABLE PARAM_VALUE STORE AS PARAM_VALUE_TAB
    TABLESPACE CMS_ADMDATA;
    /
    ALTER TABLE PARAM_VALUE_TAB ADD CONSTRAINT UN_PARAM_VALUE_TAB UNIQUE (DATA_VALUE);
    /
    SHOW ERROR;
    
    Prompt create table CMS_ADM.VESSEL_TYPE;
    CREATE TABLE CMS_ADM.VESSEL_TYPE (
      VESSEL_TYPE  VARCHAR2(20) NOT NULL
     ,VESSEL_DESC  VARCHAR2(125)
     ,VESSEL_PARAM LIST_PARAM_NAME
     ,CONSTRAINT PK_VESSEL_TYPE PRIMARY KEY (VESSEL_TYPE)
    -- ,CONSTRAINT FK_VESSEL_TYPE FOREIGN KEY (VESSEL_PARAM) 
    --        REFERENCES VESSEL_PARAM (PARAM_NAME)
    ) 
    NESTED TABLE VESSEL_PARAM STORE AS VESSEL_PARAM_TAB
    TABLESPACE CMS_ADMDATA;
    /
    ALTER TABLE VESSEL_PARAM_TAB ADD CONSTRAINT UN_VESSEL_PARAM_TAB UNIQUE (NAME);
    ALTER TABLE VESSEL_PARAM_TAB ADD CONSTRAINT FK_VESSEL_TYPE FOREIGN KEY (NAME,DATA_VALUE) 
            REFERENCES VESSEL_PARAM (PARAM_NAME,LIST_PARAM_VALUE.DATA_VALUE)
    /
    SHOW ERROR;
    Thank you

    Salvatore

    Could you please indicate your answer as correct if you judge them correct.

    Best regards

    Mohamed Houri

  • FOREIGN KEY CONSTRAINTS

    Oracle Database 11 g Release 11.2.0.1.0 - 64 bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    AMT for 64-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production

    Hi all.
    I'm having a problem to add a foreign key to a table constraint, and I was wondering if anyone had any ideas.
    I did my example about as simple as you can get.

    CREATE TABLE tparent)
    PID NVARCHAR2 (10) NOT NULL,
    PID2 NVARCHAR2 (10) NULL);
    CREATE UNIQUE INDEX ui_tparent ON tparent (pid);

    (Tchild) CREATE TABLE
    CID NVARCHAR2 (10) NOT NULL,
    CID2 NVARCHAR2 (10));
    CREATE UNIQUE INDEX ui_tchild ON tchild (cid);
    ALTER TABLE ADD CONSTRAINT fk_tc_to_tp FOREIGN KEY (cid) tchild REFERENCES tparent (pid);

    Error report:
    SQL error: ORA-02270: no unique or primary key corresponding to this column list
    02270 00000 - 'no matching unique or primary key to this list of columns.
    * Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
    gives a list of columns for which there is no unique or primary match
    key in the referenced table constraint.
    * Action: Find the names of correct column using the ALL_CONS_COLUMNS
    display catalog

    ??? Which - as you can see I have a unique index - ui_tparent.

    This works fine if I use a PRIMARY KEY and a UNIQUE INDEX?
    That is to say
    ALTER TABLE ADD CONSTRAINT pk_tparent PRIMARY KEY (pid) tparent;

    Ora docs say that in order to create a parent needs a UI PK or FK.

    Any ideas?

    Kind regards

    as I say the mistake:

    no unique or primary key corresponding to this column list

    It takes a unique or primary key and a unique index is not a unique key.

    SQL> CREATE TABLE tparent(
    pid NVARCHAR2(10) NOT NULL,
    pid2 NVARCHAR2(10) NULL);  2    3
    
    Table created.
    
    SQL> alter table tparent add constraint tparent_uk unique (pid);
    
    Table altered.
    
    SQL> CREATE TABLE tchild(
    cid NVARCHAR2(10) NOT NULL,
    cid2 NVARCHAR2(10));  2    3
    
    Table created.
    
    SQL> ALTER TABLE tchild ADD CONSTRAINT fk_tc_to_tp FOREIGN KEY (cid) REFERENCES tparent(pid);
    
    Table altered.
    
    SQL>
    
  • How to set the condition of rule to check the Primary Key, Foreign Key and Unique

    I use Oracle 10.2
    Could someone tell me please how to set the rule condition to check the primary key, foreign key constraint of uniqueness?

    Hello

    Primary key, unique constraints and foreign key are better applied using the native functionality of database constraint. If you like the rules to check if a key exists at the time of the evaluation, you can use a function defined by the user in a rule condition and this function can ask to turn the table keys.

    Hope this helps,
    -Aravind.

Maybe you are looking for

  • Update from an another Apple ID...

    Hi all! So, briefly explain my problem - a family member of mine connected to their account on my iMac and I forgot to close the session. They then use their own Mac and download apps etc etc. Not much. I logged into my account and thought that every

  • How to get the share button

    I had to reboot firefox and lost all the buttons on my part. How can I get them back or where can I find them and bring them to pin on the page?

  • HP Mini 2102, wireless detects networks but does not connect

    Hi, I have recently reinstalled Windows 7 on my HP Mini 2102, downloaded this driverhttp://h20000.www2.HP.com/bizsupport/TechSupport/SoftwareDescription.jsp?lang=en & CC = US & prodTypeId = 32...I tried to reinstall, but it still does not work.

  • System hangs when the computer sleeps with error KMode_Exception_Not_Handled after generation installed 9926

    Since the new version update (9926), whenever my computer goes to sleep or when it is left for several hours compress I get unhandled KMode Exception error.  I deleted a suspicious program who has problems during the previous generation, but that mad

  • model of dynamic system, which is the Solver

    Dear Member What labview mean by that word in this helpl http://zone.ni.com/reference/en-XX/help/371894G-01/lvsimconcepts/sim_c_ode/ labview "" Because many models of dynamic systems consist of differential equations, you must resolve these different