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

Tags: Database

Similar Questions

  • 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.

  • Constraint primary key turn off - turn on problem solution

    Hello
    recently I truncate a table. during the truncation process I face with problem and solve below the track.

    SQL > TRUNCATE TABLE USER_STATE;
    TRUNCATE TABLE USER_STATE
    *
    ERROR on line 1:
    ORA-02266: permit to unique/primary keys in table referenced by foreign keys

    Then I find the related CONSTRAINT on the table according to the truncate table ORA-02266


    SQL > ALTER TABLE USER_STATE_PARAMETER disable the CONSTRAINT FK1_USR_SES_ST_PAR;

    Modified table.

    SQL > ALTER TABLE USER_STATE disable the CONSTRAINT SYS_C0030849;

    Modified table.

    Then successfully truncate the table as below

    SQL > TRUNCATE TABLE USER_STATE;

    Table truncated.

    then I activate the CONSTRAINT

    SQL > ALTER TABLE USER_STATE allow CONSTRAINT SYS_C0030849;

    Modified table.

    SQL > ALTER TABLE USER_STATE_PARAMETER allow FK1_USR_SES_ST_PAR of CONSTRAINT;

    Modified table.


    -My Question is, after you disable the CONSTRAINT, I did the truncate operation, and then enable the CONSTRAINT. I do who will trust me to do not face any problem in the database of the DML OPERATION? I also found there is no CONSTRAINT to disable in my database.

    >
    I do
    >
    Nope - you would not enable foreign key constraints, if the tables had given them that reference the you truncated.

    So if the constraints are enabled and valid, you will have no problem.

    You can (and should) always test certain simple dml to confirm there is no problem.

  • Oracle 10.2.0.3.0 - impdp - unusable index exists on unique/primary...

    Hi all

    Oracle 10.2.0.3.0 - during impdp the following error appears:

    Object type SCHEMA_EXPORT/TABLE/CONSTRAINT/treatment
    ORA-39083: THAT CONSTRAINT Type could not create object error:
    ORA-14063: unusable Index exists on constraint unique/primary key
    Because sql is:
    ALTER TABLE 'MY_SCHEMA '. "' MY_TABLE ' ADD CONSTRAINT PRIMARY KEY 'MY_TABLE_PK' ('ID')
    USING INDEX PCTFREE, INITRANS 10 2 MAXTRANS 255
    STORAGE (INITIAL 1048576 THEN 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
    TABLESPACE "MY_TBS".

    Question:

    Tree index does not contain the dump file, and impdp should simply create index as it appears in the metadata information.

    So, what's the point to clear this error?

    921817 wrote:

    So, what's the point impdp tells his State? It can be hundreds of unusable indexes, why it is not only rebuild?

    Because Impdb cannot create an object that is already there and can't make it valid.

    Aman...

  • Why we cannot create more than one primary key on a table. Why we create several unique key on a table. Please explain if anyone have details of this.

    Why we cannot create more than one primary key on a table. Why we create several unique key on a table. Please explain if anyone have details of this.

    «a primary key has semantic meaning, it is to be immutable (never change of value), unique and not null.»

    a unique constraint is simply "at any time, these values are unique - they can change and they can be null.

    You use a unique when constraint

    (a) you do not already have a primary key for a table can have only one
    (b) you allow NULL values in attributes
    "(c) to allow you to update the values in the attributes.

    https://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:5541352100346689891

  • Potential problems for tables without primary keys and unique keys

    GoldenGate 11.2.1.0.3/Solaris 10
    DB: Oracle for Oracle (Source and target is 11.2.0.3)
    Topology: unidirectional


    In our one-way configuration GG, little of the tables being replicated is not a primary key or a Unique key.

    Last week when we have implemented GG for the test, we received warnings for these table below.
    GGSCI > add trandata WMHS_UD.crtn_dtl
    
    2013-01-12 11:34:33  WARNING OGG-00869  No unique key is defined for table 'CRTN_DTL'. All viable columns will be used to represent the key, but may not guarantee uniqueness.  KEYCOLS may be used to define the key.
    
    Logging of supplemental redo data enabled for table WMHS_UD.crtn_dtl.
    Replication seems to work very well for these tables.

    Googling, I think that there may be performance degradation when you replicate tables without PK or the United Kingdom.

    But are there other potential problems such as data of a certain kind not replicated to the lack of PK/UK?

    It really depends on the data.

    By default, GG is combining all columns as a virtual primary key but don't no conflict control by default. So when you can be sure that the record you insert into the table is unique, then it will work.
    BUT as soon as you insert the same record, which is already inserted, then you will encounter problems.

    Let me show what happens when you use an initial charge because it makes it easier to describe:
    We start at 10:00 the capture for a table. Now, you insert a record at 10:00 in the tables. When you now start an initial charge to 10.02, then check you have inserted in the database to 10.01 will be repeated two times. During the IPL as the initial charge is made to 10.02 and it includes data of 10.01 AND it will be replicated again through the process of capture/replicate.

  • ORA-02260: table can have only one primary key

    CREATE TABLE Invoice_Deatil

    (

    Invoice # KEY PRIMARY NUMBER REFERS to Invoice(Invoice#).

    Prod # KEY PRIMARY NUMBER REFERS to Product(Prod#).

    CHECKING NUMBER of Qty_Ordered (Qty_Ordered BETWEEN 50-5000)

    );

    create table invoice_deatil
    (
      invoice# NUMBER  REFERENCES invoice(invoice#),
      prod#    NUMBER  REFERENCES product(prod#),
      QTY_ORDERED NUMBER CHECK(QTY_ORDERED BETWEEN 50 AND 5000),
      CONSTRAINT invoice_deatil_pk PRIMARY KEY (invoice#,prod#)
    );
    
  • Local primary key on reference partitioned Table

    Oracle running on Red Hat Linux Rel6 11.2.0.3.

    I'm on a closed network, so the following must be typed manually.

    I have a table of documents which is essentially the following:

    (entire annual <-primary key)

    whole Source_ID,

    load_dt date,

    date of doc_dt,

    doc_info clob,

    ...)

    which is partitioned on column source_id.

    I created a partitioned table of reference as follows:

    create table doc_entities_prt)

    whole doc_entity_id

    all annual,

    whole entity_id,

    forced doc_ent_fk (annual) references to documents (annual)

    tablespace...

    allow the movement of the line

    benchmark score (doc_ent_fk);

    The annual column in the child table is not unique.  The doc_entity_id column is unique.  I want to set the primary key on doc_entities_prt as a local index on the doc_entity_id column.  I was not able to find the proper syntax to get there, and now I'm wondering if this is even possible? Any ideas appreciated.

    Oops, I missed part that you want to base the PK of this index. No, it is not possible and has nothing to do with the partitoning reference. A unique index can be partitioned only if it includes a partitioning column. You can create a non-unique without partitioning column partitioned index, but then you can't create PK supported by such an index for the same reason - oracle would not be able to verify uniquenes based on this index partition and controls of the cross-partition are not supported:

    SQL > create table documents)
    2 whole annual,
    3 whole source_id,
    load_dt date 4.
    date of doc_dt 5.
    6 doc_info clob
    7                        )
    8 partition by range (source_id)
    9      (
    10 partition p1 values less than (10),
    11 partition p2 values less than (100)
    12)
    13.

    Table created.

    SQL > create index unique documents_pk
    2 on documents (annual)
    (3) local
    partition 4 p1,
    5 partition p2
    6         )
    7.
    on documents (annual)
    *
    ERROR on line 2:
    ORA-14039: partitioning columns must be a subset of the columns of a unique key
    index

    SQL > create index documents_pk
    2 on documents (annual)
    (3) local
    partition 4 p1,
    5 partition p2
    6         )
    7.

    The index is created.

    SQL > alter table documents
    2 Add the constraint documents_pk
    3 key (annual) elementary school
    4 using index documents_pk
    5.
    change the documents table
    *
    ERROR on line 1:
    ORA-14196: specified Index cannot be used to apply the constraint.

    SQL >

    SY.

  • Accompanied by primary key to a non-unique index?

    Met a weird situation today. A utility, we set up which allows analysts to restore the data in their paintings, started failed when it attempted to drop an index. The index supported a primary key. Makes sense. But our script was supposed to be only an attempt to drop/recreate the nonunique indexes. It turns out that supported on the primary key index was not unique and to the best of my knowledge has emerged as follows:
    SQL> create table junk (f number(1));
    
    Table created.
    
    SQL> create index junk_ix on junk(f);
    
    Index created.
    
    SQL> select UNIQUENESS from DBA_INDEXES where index_name = 'JUNK_IX';
    
    UNIQUENES
    ---------
    NONUNIQUE
    
    SQL> alter table forbesc.junk add constraint junk_pk primary key (f) using index junk_ix;
    
    Table altered.
    
    SQL> select UNIQUENESS from DBA_INDEXES where index_name = 'JUNK_IX';
    
    UNIQUENES
    ---------
    NONUNIQUE
    
    SQL> insert into junk values (1);
    
    1 row created.
    
    SQL> insert into junk values (1);
    insert into junk values (1)
    *
    ERROR at line 1:
    ORA-00001: unique constraint (FORBESC.JUNK_PK) violated
    
    
    SQL> select index_name from dba_constraints where constraint_name = 'JUNK_PK';
    
    INDEX_NAME
    ------------------------------
    JUNK_IX
    What I can't understand, is how an index is not unique is to apply oneness. I thought it was the key to this process. I thought that perhaps an index with the 'SYS_123456' has be created, perhaps, but I couldn't find a:
    SQL> select object_name, object_type from dba_objects order by created desc;
    
    
    OBJECT_NAME   OBJECT_TYPE
    -------------------------------------------     
    JUNK_IX     INDEX
    JUNK     TABLE
    ...
    How the uniqueness is get applied in this case? It comes in Oracle 11.1.0.7

    Thank you
    -= Chuck

    It has always been like that. Oracle can and will use a non-unique index to apply a constraint to PK, the existing index just needs to have the columns PK as the leader or the columns in the index:

    SQL> create table t (id number, id1 number, descr varchar2(10));
    
    Table created.
    
    SQL> create index t_ids on t(id, id1);
    
    Index created.
    
    SQL> select index_name from user_indexes
      2  where table_name = 'T';
    
    INDEX_NAME
    ------------------------------
    T_IDS
    
    SQL> alter table t add constraint t_pk
      2  primary key (id);
    
    Table altered.
    
    SQL> select index_name from user_indexes
      2  where table_name = 'T';
    
    INDEX_NAME
    ------------------------------
    T_IDS
    
    SQL> insert into t values (1, 1, 'One');
    
    1 row created.
    
    SQL> insert into t values (1, 2, 'Two');
    insert into t values (1, 2, 'Two')
    *
    ERROR at line 1:
    ORA-00001: unique constraint (OPS$ORACLE.T_PK) violated
    

    John

  • create materialized view log on the table without a primary key

    Hi all
    CREATE TABLE client_months 
    (
      SUBJ_CODE         NUMBER(4),
      SERV_CODE         NUMBER(4),
      DEBIT_CODE        NUMBER(4),
      PERIOD_NUM        NUMBER(2),
      PERIOD_NAME       VARCHAR2(40 CHAR),
      FIRST_MON_DAY     DATE,
      LAST_MON_DAY      DATE,
      VALUE_MON_DAY     DATE,
      MONTHES           NUMBER(4,2),
      GARDENING_WEIGHT  NUMBER(5,4),
      REASON_CODE       NUMBER(5),
      STAMP_ACTION      VARCHAR2(1 CHAR),
      STAMP_CDATE       DATE                        DEFAULT SYSDATE,
      STAMP_DATE        DATE,
      STAMP_USER        VARCHAR2(15 CHAR),
      REGION_CODE       NUMBER(9)
    )
    table created.
    
    CREATE UNIQUE INDEX client_months_UK  ON client_months 
    (SUBJ_CODE, SERV_CODE, DEBIT_CODE, PERIOD_NUM, REGION_CODE)
    index created.
    
    CREATE MATERIALIZED VIEW LOG ON client_months with rowid;
    
    CREATE MATERIALIZED VIEW client_months_mv 
    BUILD immediate 
    REFRESH FAST ON COMMIT 
    AS 
    SELECT * FROM client_months;
    
    ORA-12014: table 'CLIENT_MONTHS' does not contain a primary key constraint
    I don't want to refresh the mview when validation is performed on the base table.
    And I don't want to change the base table by adding a primary key.

    is it possible to create the mview journal using the unique index? or another solution?
    Please help
    Thanks in advance
    Naama

    Naamas wrote:
    No,
    I already read this post!

    Then you read wrong:

    SQL> CREATE TABLE client_months
      2  (
      3    SUBJ_CODE         NUMBER(4),
      4    SERV_CODE         NUMBER(4),
      5    DEBIT_CODE        NUMBER(4),
      6    PERIOD_NUM        NUMBER(2),
      7    PERIOD_NAME       VARCHAR2(40 CHAR),
      8    FIRST_MON_DAY     DATE,
      9    LAST_MON_DAY      DATE,
     10    VALUE_MON_DAY     DATE,
     11    MONTHES           NUMBER(4,2),
     12    GARDENING_WEIGHT  NUMBER(5,4),
     13    REASON_CODE       NUMBER(5),
     14    STAMP_ACTION      VARCHAR2(1 CHAR),
     15    STAMP_CDATE       DATE                        DEFAULT SYSDATE,
     16    STAMP_DATE        DATE,
     17    STAMP_USER        VARCHAR2(15 CHAR),
     18    REGION_CODE       NUMBER(9)
     19  )
     20  /
    
    Table created.
    
    SQL> CREATE UNIQUE INDEX client_months_UK  ON client_months
      2  (SUBJ_CODE, SERV_CODE, DEBIT_CODE, PERIOD_NUM, REGION_CODE)
      3  /
    
    Index created.
    
    SQL> CREATE MATERIALIZED VIEW LOG ON client_months with rowid
      2  /
    
    Materialized view log created.
    
    SQL> CREATE MATERIALIZED VIEW client_months_mv
      2  BUILD immediate
      3  REFRESH FAST WITH ROWID ON COMMIT -- pay attention to WITH ROWID
      4  AS
      5  SELECT * FROM client_months
      6  /
    
    Materialized view created.
    
    SQL>
    

    SY.

  • Primary key and unique key not Null

    Hello gurus,

    Asked in an interview about the difference between primary and unique keys.
    I talked Unique keys can accept null values, but they are unique through should have the table. So, the next question asked me was "a Unique key NOT NULL can be treated as the primary key?

    Tricky question! :)
    I said yes! that it meets the requirement to be a primary key for this particular table, but since this isn't really a primary key, that it can't be covered in the foreign keys.

    The interviewer wanted just a Yes or no.

    Can someone please put some of this?

    Thanks in advance!

    Two things.
    1. unique can also be referenced as a foreign key. If your statement "but because this isn't really a primary key may not be seized key foreign." is not true.
    2. primary key and Unique key are different (for example you can have more than one UK in a table but PK's alone) and to know the difference, read some RDBMS concepts.

    I'm curious to know what is the outcome of your interview? ;)

  • 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/]

  • What is the difference between primary key and unique indexes with forced not null?

    Primary key is = unique index + not null?

    The short answer is Yes.

    However, even if the primary key, applying both uniquness and not null, there is a notion of "special".

    You can only have one primary key in tables, but you can have multiple unique indexes and constraints not null.

    See: https://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:8743855576462

  • When I change a column is a primary key the associated non-unique index to become unique?

    So basically I already tried this and it shows me that the associated index is not unique.

    create table employees2 in select * from employees;

    create index emp_idx on employees2 (employee_id);

    ALTER employees2 table add primary key (employe_id) using index emp_idx;

    Select * from user_indexes where index-name = "EMP_IDX";

    I was wondering if I right assuming that when you change a column to a primary key or unique while using a given index that does not have the respective index become unique.

    The textbooks I use are sometimes a little hard to understand because of the wording, also, I want to just ask someone with a little more experience than me.

    Thank you.

    your test did give the correct answer: the index is not unique if it serves to bear a unique or primary key constraint. Indeed, it is one of the benefits of the use of no unique indexes in support of UK/PK constraints (since it allows to set the unusable index before to make bulk loads; and, of course, they have also some disadvantages - for example, they need an additional logical reading to reach a line). Richard Foote explains the details in https://richardfoote.wordpress.com/2008/06/04/primary-keys-and-non-unique-indexes-whats-really-happening/ (and other items).

  • Two constraints of primary key of a table with two different constraint name

    Hi guys

    I am creating the table below

    Table name: TITLE_COPY

    Column name Copy_id Title_id Status

    Key type

    PKPK, FK
    UniqueNN, UNN, UNN
    CheckAvailable, destroyed, leased, reserved
    Table Ref FKTitle
    FK Ref ColTitle_id
    Data typeNumberNumberVarchar2
    Length101015

    The SQL statement below can create it

    CREATE TABLE title_copy (copy_id NUMBER (10),)

    title_id CONSTRAINT NUMBER (10) title_copy_title_id_fk title (title_id) REFERENCES.

    primary key constraint title_copy_title_id_pk title_id (copy_id)

    status VARCHAR2 (15) NOT NULL CONSTRAINT status_ck CHECK (status IN ('AVAILABLE', 'DESTROYED', 'RENTAL', 'RESERVED'))

    );

    Two primary keys (title_id, copy_id) are created with the same name of constraint (title_copy_title_id_pk) (-> table-level constraint). What happens if I want to have two different names of the primary key constraint, say title_copy_title_id_pk for the title_id column and title_copy_copy_id_pk for the copy_id column?

    I can do that with a column-level constraint? Something like below (complains about the additional primary key)

    CREATE TABLE title_copy (copy_id NUMBER (10) CONSTRAINT title_copy_copy_id_pk PRIMARY KEY,)

    constraint title_copy_title_id_pk primary key (title_id).

    title_id CONSTRAINT NUMBER (10) title_copy_title_id_fk title (title_id) REFERENCES.

    status VARCHAR2 (15) NOT NULL CONSTRAINT status_ck CHECK (status IN ('AVAILABLE', 'DESTROYED', 'RENTAL', 'RESERVED'))

    );

    In summary, I can define two primary keys with the name of different constraint in a column-level constraint?

    There are no two primary keys. There is a primary key made up of two columns - also called a composite key.

    A table can have at least a primary key. You can, if you wish, create a unique constraint on a different set of columns.

Maybe you are looking for

  • White LED of Ethernet to the router flashes constantly (to about 5 flashes per second)

    The Internet on my router Netgear (R7000 Nighthawk, AC1900) white LED flashes constantly (about 5 times per second), and it is originally the link on my modem light blinks constantly. All started about four days ago. I thought that my modem was defec

  • Need info on type of hard disk for Satellite A100

    I have a model of Satellite A100 (PSAA9E) It used to power up, but I need all the info on the hard drive, which models are compatible (plug-and-play style) so I can buy a 2nd hand laptop and use my old hard drive(assuming this is possible) Thank you

  • Don't get the names of the tracks - No Error Message

    Hello I have a problem that happens with all CD when I try to import, no track, the name appears and when I choose to get names follow No error message is given, this used to work but stopped after the recent updates. What is strange, is that when I

  • run an exe 6 moths later

    I have an executable of LabView that I had created on a host and then 6 months ago machine door on a target machine. The fine run exe on target many times. I tried to run this exe today (~ 6 months later) and get an error: resource not found, error c

  • Help my extensa 4420 does not illuminate

    I have a laptop Acer Extensa 4420 2009, that does not illuminate. He sat for 4 months unused. Don't work on battery power (15 min max) Finally bought a new battery. When I press the button start is there no response. I checked the power supply: good