dependencies of key foreign primary keys

Hi the gems...

I have a table with primary key composite (COL1, COL2)...
create table TABLE1 (COL1, COL2);
ALTER table TABLE1 add the primary key of the constraint (COL1, COL2) PK_TABLE1;

Now, I'm doing another table that will refer to the first table COL1.
create table TABLE2 (COL3, COL4);
ALTER table TABLE2 add constarint FK_TABLE2 (COL3) made reference to TABLE1 (COL1);

but it is a failure "without corresponding unique key or primary' error.

You have created a composite primary key, then there must be a composite foreign key that references the composite primary key. You cannot create a foreign key that refers to a unique composite primary key column.

Tags: Database

Similar Questions

  • Key foreign primary key

    Dear all,



    I have 30 paintings. of which some tables with primary key and the foreign key relationship.

    How can I find which table is to have a primary and key to the primary key column, what table is a foreign key for all tables.





    Saludos.
    select a.table_name as parent_table, b.table_name as child_table from user_constraints a,user_constraints b where a.constraint_type='P'
    and b.constraint_type='R'
    and a.constraint_name = b.r_constraint_name
    
  • Creating partitioned local index

    Hi all

    Planing to run the range-partitioned on a table and creating Local partitioned index, but in the table is seen forced composite primary key thought to previously create Composite Unique Local partitioned index.

    Problem is when creating index its error ORA-14039 giving, of course it is not possible as partitioning column is not a subset of columns in a UNIQUE index key.

    Is there no workaround solution to create Local partitioned indexes... otherwise I'll be forced to create the overall index part?

    Y at - it no drawback if I create Composite Unique Local partitioned indexes including the columns of partitioning on purpose?

    There will be no impact if I create the index Composite Unique Local partitioned by including the columns voluntarily on the SQL QUERIES, access this table partitioning?

    Please suggest me a workaround solution.
    CREATE TABLE YASIR.CS_RESEARCH (ORDER_NBR NUMBER NOT NULL,
                          ORDER_DETAIL_NBR NUMBER NOT NULL,
                          SESSION_ID VARCHAR2(40),
                          PRODUCT_GROUP VARCHAR2(16) NOT NULL,
                          PRODUCT_SUBGROUP VARCHAR2(16) DEFAULT 'N/A',
                          FORMAT_TYPE VARCHAR2(10) NOT NULL,
                          CONTRIBUTOR VARCHAR2(60) NOT NULL,
                          DOCUMENT_NUMBER VARCHAR2(15) NOT NULL,
                          DOCUMENT_DATE DATE,
                          BILLABLE_PAGES NUMBER,
                          NON_BILLABLE_PAGES VARCHAR2(512),
                          PURCHASED_UNITS VARCHAR2(2000),
                          DELIVERY_METHOD VARCHAR2(6) DEFAULT 'ONLINE',
                          COMPANY_NAME VARCHAR2(120),
                          STATUS VARCHAR2(10) DEFAULT 'NEW',
                          CONTENT_CODE VARCHAR2(15) NOT NULL, 
                          CONTENT_CODE_DESC VARCHAR2(60),
                          ITEM_PRICE NUMBER NOT NULL,
                          PAGES_ORDERED NUMBER,
                          LAST_MNT_DATE_TIME DATE NOT NULL,
                          LAST_MNT_OPID VARCHAR2(120) NOT NULL,
                          CREATE_DATE DATE NOT NULL,
                          DML_FLAG CHAR(1) NOT NULL)
         PARTITION BY RANGE (CREATE_DATE) 
         (PARTITION CS_RESEARCH_2009_Q2 VALUES LESS THAN (MAXVALUE));
    
    ###Split partitions:
    ALTER TABLE YASIR.cs_research
      SPLIT PARTITION CS_RESEARCH_2009_Q2 AT (TO_DATE('30-SEP-2007 23:59:59', 'DD-MON-YYYY HH24:MI:SS'))
      INTO (PARTITION CS_RESEARCH_2007_Q3,
            PARTITION CS_RESEARCH_2009_Q2);
    
    ALTER TABLE YASIR.cs_research
      SPLIT PARTITION CS_RESEARCH_2009_Q2 AT (TO_DATE('31-DEC-2007 23:59:59', 'DD-MON-YYYY HH24:MI:SS'))
      INTO (PARTITION CS_RESEARCH_2007_Q4,
            PARTITION CS_RESEARCH_2009_Q2);
    
    ALTER TABLE YASIR.cs_research
      SPLIT PARTITION CS_RESEARCH_2009_Q2 AT (TO_DATE('31-MAR-2008 23:59:59', 'DD-MON-YYYY HH24:MI:SS'))
      INTO (PARTITION CS_RESEARCH_2008_Q1,
            PARTITION CS_RESEARCH_2009_Q2);
    
    ALTER TABLE YASIR.cs_research
      SPLIT PARTITION CS_RESEARCH_2009_Q2 AT (TO_DATE('30-JUN-2008 23:59:59', 'DD-MON-YYYY HH24:MI:SS'))
      INTO (PARTITION CS_RESEARCH_2008_Q2,
            PARTITION CS_RESEARCH_2009_Q2);
    
    ALTER TABLE YASIR.cs_research
      SPLIT PARTITION CS_RESEARCH_2009_Q2 AT (TO_DATE('30-SEP-2008 23:59:59', 'DD-MON-YYYY HH24:MI:SS'))
      INTO (PARTITION CS_RESEARCH_2008_Q3,
            PARTITION CS_RESEARCH_2009_Q2);
    
    ALTER TABLE YASIR.cs_research
      SPLIT PARTITION CS_RESEARCH_2009_Q2 AT (TO_DATE('31-DEC-2008 23:59:59', 'DD-MON-YYYY HH24:MI:SS'))
      INTO (PARTITION CS_RESEARCH_2008_Q4,
            PARTITION CS_RESEARCH_2009_Q2);
    
    ALTER TABLE YASIR.cs_research
      SPLIT PARTITION CS_RESEARCH_2009_Q2 AT (TO_DATE('31-MAR-2009 23:59:59', 'DD-MON-YYYY HH24:MI:SS'))
      INTO (PARTITION CS_RESEARCH_2009_Q1,
            PARTITION CS_RESEARCH_2009_Q2);
    
    ###Create indexes on cs_research except primary key index CSR_PKEY:
    alter session set sort_area_size=262144000; -----(250MB Total will be 1GB for 4 parallel process)
    create index YASIR.CSR_DETAIL_NBR on YASIR.CS_RESEARCH(TO_NUMBER(REPLACE(TO_CHAR(ORDER_NBR,'999999999')||TO_CHAR(ORDER_DETAIL_NBR,'999999999'),' ',''),'999999999999')) LOCAL
              (PARTITION CS_RESEARCH_2007_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2007_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q2 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q2 TABLESPACE USERS)
         nologging parallel (degree 4);
    Index created.
    
    create index YASIR.CSR_SESSION on YASIR.CS_RESEARCH(SESSION_ID,ORDER_NBR) LOCAL
              (PARTITION CS_RESEARCH_2007_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2007_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q2 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q2 TABLESPACE USERS)
         nologging parallel (degree 4);
    Index created.
    
    create index YASIR.CSR_CREATED on YASIR.CS_RESEARCH(CREATE_DATE) LOCAL
              (PARTITION CS_RESEARCH_2007_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2007_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q2 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q2 TABLESPACE USERS)
         nologging parallel (degree 4); 
    Index created.
    
    create index YASIR.CSR_DOCUMENT_NUMBER on YASIR.CS_RESEARCH(DOCUMENT_NUMBER) LOCAL
              (PARTITION CS_RESEARCH_2007_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2007_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q2 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q2 TABLESPACE USERS)
         nologging parallel (degree 4); 
    Index created.
    
    create index YASIR.CSR_STATUS on YASIR.CS_RESEARCH(STATUS) LOCAL
              (PARTITION CS_RESEARCH_2007_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2007_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q2 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q2 TABLESPACE USERS)
         nologging parallel (degree 4);
    Index created.
     
    create unique index CSR_PRKEY_IND on YASIR.CS_RESEARCH(ORDER_NBR,ORDER_DETAIL_NBR) LOCAL
         (PARTITION CS_RESEARCH_2007_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2007_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q2 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q3 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2008_Q4 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q1 TABLESPACE USERS,
              PARTITION CS_RESEARCH_2009_Q2 TABLESPACE USERS)
         nologging parallel (degree 4);
    ERROR at line 1:
    ORA-14039: partitioning columns must form a subset of key columns of a UNIQUE
    index
    Thank you
    Yasser

    YasserRACDBA wrote:
    I want to create a unique partitioned index Local and use this primary key index.

    But my main question is if this create_date column will affect all sql queries that are not used in where clause?

    Yasser,

    your main question should not be about performance queries, but the consequence of adding the CREATE_DATE to the local unique index:

    1. you change the meaning of the primary key: adding the CREATE_DATE means that the unique character of ORDER_NBR, ORDER_DETAIL_NBR is only applied by CREATE_DATE. I guess that does not match the business experience that this primary key is supposed to enforce and defeated the original purpose of the uniqueness that is unique values of ORDER_NBR, ORDER_DETAIL_NBR across the table.

    2. If you want to use as a key in other tables you must add the CREATE_DATE to all child tables, because you need to refer to the primary key complete a relationship of key foreign primary key.

    So the only 'right' way to do this is to use a unique comprehensive index on ORDER_NBR, ORDER_DETAIL_NBR. Of course, this means you must rebuild whenever a partition maintenance is carried out which invalidates the overall index since you use 8i and you cannot use the UPDATE GLOBAL INDEXES clause.

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

  • How can I make sure that changes in a primary key (in the parent table) would also appear directly in the FOREIGN KEY in the child table?

    Forgive my question. I am very new to Oracle.

    How can I make sure that changes in the key primary supplier_id (concerning the supplier table) would also appear directly in the FOREIGN KEY (supplier_id) in the products table?

    Is that not all the primary key and FOREIGN KEY on?

    My paintings:

    I created 2 tables and connect to apply in the data base referential integrity, as I learned.

    CREATE TABLE - parent provider

    (the numeric (10) of supplier_id not null,)

    supplier_name varchar2 (50) not null,

    Contact_Name varchar2 (50).

    CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)

    );

    CREATE TABLE - child products

    (the numeric (10) of product_id not null,)

    supplier_id numeric (10) not null,

    CONSTRAINT fk_supplier

    FOREIGN KEY (supplier_id)

    REFERENCES beg (supplier_id)

    );

    I inserted the following text:

    INSERT INTO provider

    (supplier_id, supplier_name, contact_name)

    VALUES

    (5000, 'Apple', 'first name');

    I expect that the supplier_id (5000) to the provider of the table also appears in the products table under key supplier_id having the same value which is 5000. But this does not happen.

    How to get there?

    Thanks in advance!

    Hello

    What is a foreign key in Oracle?

    A foreign key is a way to ensure referential integrity in your Oracle database. A foreign key means that the values of a table must appear also in another table.

    Ok!??

    What is now the right way to implement referential integrity in your Oracle database that the values of a table must also be included in another table?

    A foreign key referential integrity indeed enfore in ensuring that the value in the child table must have a corresponding parent key (otherwise you will encounter an error, as evidenced by "SomeoneElse"). However, it will never automatically insert a row in the other table.

    If you are looking for a solution that automatically inserts a record in the other table, maybe you should go for triggers:

    See:

  • How to join two tables to retrieve the data from the columns in table two. Tables have primary and foreign key relationships

    Hello

    I want to join the two tables to retrieve the data from the columns of the two table passing parameters to the join query. Tables have primary and foreign key relationships

    Details of the table

    Alert-1 - AlertCode (FK), AlerID (PK)

    2 AlertCode-AlertDefinition-(PK)

    Help, please


    ----------

    Hi Vincent,.

    I think that you have not worked on adf 12.1.3.  In adf 12.1.3 you don't have to explicitly create the association. When you create the EO to your table, Association xxxxFkAssoc, will be created by ADF12.1.3 for you automatically. Please try this and do not answer anything... You can also follow the links below. I solved the problem by using the following link

    Oracle ADF Guide step by step - Oracle ADF tutorial: creating a relationship of the master / detail using Oracle ADF

    ---

  • Primary key and foreign key between the different schemas

    Hi all;

    SCOTT user have a 'rank' of table-> it contains the primary key-> users tablespace

    The U1 user have a 'emp' table-> it contains the foreign key-> test tablespace

    U1 > select constraint_name, constraint_type, r_owner, owner, r_constraint_name of all_constraints where table_name = 'EMP ';

    OWNER CONSTRAINT_NAME C R_OWNER R_CONSTRAINT_NAME

    ------------ ------------------------------ - -------------------------- ----------------------- -----------------------------------------------------

    U1              EMP_EMPLEV_C12_FK R SCOTT GRADE_GRL_C1_PK

    If I have connection U1, no possibility to find the name of the primary key without connection scott table?

    Thank you

    Hello

    So, you want to know what picture of the SCOTT schema has the constraint that is named "GRADE_GRL_C1_PK." Isn't it?

    If so,.

    SELECT table_name

    Of all_constraints

    Owner WHERE = 'SCOTT '.

    AND the argument constraint_name = 'GRADE_GRL_C1_PK. '

    ;

  • ODI is not able to detect the primary/foreign keys to XML - the user has no privilege or object not found

    Hi guys,.

    Im trying to load an XML with the address of two entities and employee as below. The topology of reverse engineering, everything works well. Even able to display the xml data in ODI, but when I try to load the data of these two entities join by the schema of the primary keys and foreign keys which created odi engineering process reverses for xml, im im getting the error below.  IM able to load an entity data, error occurs only when I use the join odi creates internally to identify employees for xml and address components

    XML file:

    <? XML version = "1.0" encoding = "UTF-8"? >

    < EMP >

    < Empsch >

    < employee >

    < EmployeeID 12345 > < / EmployeeID >

    < original > t < / initials >

    John < name > < / LastName >

    DOE < FirstName > < / name >

    < / employee >

    < address >

    < > 12345 as WorkPhone < / as WorkPhone >

    < WorkAddress > test 234 < / WorkAddress >

    < / address >

    < / Empsch >

    < / EMP >

    Topology: jdbc:snps:xml?f=C:/Temp/RR/Empsch.xml & s = Empsch & re = EMP & dod = true & nobu = false

    Error message:

    -5501: 42501: java.sql.SQLException: user has no privilege or object not found: EMPSCH. EMPSCHPK

    java.sql.SQLException: user has no privilege or object not found: EMPSCH. EMPSCHPK

    at org.hsqldb.jdbc.Util.sqlException (unknown Source)

    for org.hsqldb.jdbc.JDBCPreparedStatement. < init >(Unknown Source)

    at org.hsqldb.jdbc.JDBCConnection.prepareStatement (unknown Source)

    at com.sunopsis.jdbc.driver.xml.SnpsXmlConnection.prepareStatement(SnpsXmlConnection.java:1232)

    at sun.reflect.GeneratedMethodAccessor65.invoke (unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    to oracle.odi.core.datasource.dwgobject.support.OnConnectOnDisconnectDataSourceAdapter$ OnDisconnectCommandExecutionHandler.invoke (OnConnectOnDisconnectDataSourceAdapter.java:200)

    to $Proxy2.prepareStatement (Unknown Source)

    at oracle.odi.runtime.agent.execution.sql.SQLCommand.doInitializeStatement(SQLCommand.java:83)

    at oracle.odi.runtime.agent.execution.sql.SQLCommand.getStatement(SQLCommand.java:117)

    at oracle.odi.runtime.agent.execution.sql.SQLCommand.getStatement(SQLCommand.java:111)

    at oracle.odi.runtime.agent.execution.sql.SQLDataProvider.readData(SQLDataProvider.java:81)

    at oracle.odi.runtime.agent.execution.sql.SQLDataProvider.readData(SQLDataProvider.java:1)

    at oracle.odi.runtime.agent.execution.DataMovementTaskExecutionHandler.handleTask(DataMovementTaskExecutionHandler.java:70)

    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2913)

    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2625)

    at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:577)

    at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:468)

    at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2128)

    to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ 2.doAction(StartSessRequestProcessor.java:366)

    at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)

    at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:300)

    to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$ 0 (StartSessRequestProcessor.java:292)

    to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ StartSessTask.doExecute (StartSessRequestProcessor.java:855)

    at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:126)

    to oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$ 2.run(DefaultAgentTaskExecutor.java:82)

    at java.lang.Thread.run(Thread.java:662)

    Caused by: org.hsqldb.HsqlException: the user has no privilege or object not found: EMPSCH. EMPSCHPK

    at org.hsqldb.error.Error.error (unknown Source)

    at org.hsqldb.ExpressionColumn.checkColumnsResolved (unknown Source)

    at org.hsqldb.QueryExpression.resolve (unknown Source)

    at org.hsqldb.ParserDQL.compileCursorSpecification (unknown Source)

    at org.hsqldb.ParserCommand.compilePart (unknown Source)

    at org.hsqldb.ParserCommand.compileStatement (unknown Source)

    at org.hsqldb.Session.compileStatement (unknown Source)

    at org.hsqldb.StatementManager.compile (unknown Source)

    at org.hsqldb.Session.execute (unknown Source)

    ... more than 27

    Please advice

    Thank you

    Fabien

    It is clear from the content of the xml file, you have given here. In this xml file, you have four type of complex. Two of them are employed and address. However the employee doesnot has nothing to do with the address that you have not added the relationship. That is why its failure. This isn't the fault of the ODI.

    Also I suggest not to use self-generated by ODI dtd that you might face problem in the future. For example, the address of XML type has 8 attributes, and 4 of them are not mandatory. This means that each of your xml file may have attributes between 4 and 8.  That's where ODI auto generated DTD fails.

    ComplexType element XML schema

    Thank you

    Chantal

  • Three ways to join with key primary and composite foreign

    Hi all

    I have three tables

    1 - test_data_items (test_data_item_id pk

    test_data_item_name)

    2 - data_items_in_tests (test_id, test_data_item_id) - both are a composite primary key.

    3 - test_results (test_results_id, pk,

    test_admin_id,

    test_id, test_data_item_id)-both are a composite foreign key.

    How to reach the three tables?

    I want all the data, but I don't know how to write the join conditions when there are primary and foreign keys composite?

    Thank you very much

    Hello

    Any condition (including a join condition) may be a compound of 2 or more of the simple conditions, combined using AND or OR.

    Maybe that's what you want:

    SELECT *- or the columns that you want to the list

    Test_data_items I have

    JOIN data_items_in_test d.test_data_item_id d = i.test_data_item_id

    JOIN test_results r ON r.test_data_item_id = d.test_data_item_id

    AND r.test_id = d.test_id

    ;

    In this case, the join condition between tables d and r is a compound of 2 simple conditions, combined with the help of and.

    The above query is just a guess.  There is not necessarily a unique way to join any 2 tables given.  Aptly named columns (and yours seem to have good names) and foreign key constraints can help you make better guesses about how to join the tables, but they are still all speculation.  They same 2 tables can be attached in different ways, depending on what is in the tables and what results you expect from them.  It's one of the reasons why, whenever you post a question, you must post a small example data (CREATE TABLE and INSERT statements), the results that you want from this data, as well as an explanation of how you get these results from these data.

    See the FAQ forum: https://forums.oracle.com/message/9362002

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

  • How to make a primary foreign key?

    I'm working on my data model and I can't understand how a foreign key to be a primary foreign key... I'll make a primary foreign key for this specific table 2...
    I tried to do the foreign key checked as the primary_UID... but this isn't the solution... I want to show in the relational model indicated as "PF" or the primary foreign key

    Anyone know? Thanks in advance

    Hi Delos,

    What version of SQL Developer Data Modeler do you use?
    For me, it works in 3.1.1.703 and 3.1.2.704.
    Can you provide more details.
    For the logic model you can use the Unique identifier dialog box and add links to the list of used objects.

    Philippe

  • Primary key and foreign key

    Hi all

    I'm confused. If I create a primary key of table constraints, it willl create a unique index by default. If I create a foreign key, it also creates an index? of any kind?


    Thank you very much

    Kinz

    Laughing out loud. foreign key does not have a unique index on the table.

  • Creation of primary keys, foreign keys and indexes

    Hello

    I created 60 new tables based on 60 existing tables.

    The 60 current tables are named FY11_ACC1, FY11_ACC2, FY11_SALES1, FY11_SALES2..., but all of the 60 tables start with FY11. I created the same structured tables but with names like FY12_ACC1, FY12_ACC2, FY12_SALES1, FY12_SALES2 FY12...

    I used the below SQL and generated SQL code.

    Select 'create table ' | Replace (table_name, 11, 12).
    ' in select * from '. table_name | "where 1 = 0'.
    from user_tables;

    But this did not generate the PRIMARY KEYS, FOREIGN KEYS and INDEXES. How can I automatically or with similar like SQL above? _

    Thanks for your time and your help.







    How can I create primary keys, foreign keys and indexes for all

    ssk1974 wrote:
    Can you please provide me with more information or examples.

    Something like:

    SET SERVEROUTPUT ON FORMAT WORD
    DECLARE
        h   NUMBER;
        th  NUMBER;
        ddl CLOB;
    BEGIN
        h := DBMS_METADATA.OPEN('TABLE_EXPORT');
        DBMS_METADATA.SET_FILTER(h,'SCHEMA','SCOTT');
        DBMS_METADATA.SET_FILTER(h,'NAME','DEPT');
        DBMS_METADATA.SET_FILTER(h,'EXCLUDE_PATH_EXPR','=''TABLE_DATA''');
        DBMS_METADATA.SET_FILTER(h,'EXCLUDE_PATH_EXPR','=''STATISTICS''');
        th := DBMS_METADATA.ADD_TRANSFORM(h,'DDL');
        DBMS_METADATA.SET_TRANSFORM_PARAM(th,'PRETTY',false);
        DBMS_METADATA.SET_TRANSFORM_PARAM(th,'SQLTERMINATOR',true);
        LOOP
          ddl := DBMS_METADATA.FETCH_CLOB(h);
          EXIT WHEN DDL IS NULL;
          DBMS_OUTPUT.PUT_LINE (ddl);
        END LOOP;
        DBMS_METADATA.CLOSE(h);
    END;
    /
    
      CREATE TABLE "SCOTT"."DEPT" ("DEPTNO" NUMBER(2,0), "DNAME" VARCHAR2(14),
    "LOC" VARCHAR2(13),  CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") USING INDEX
    PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS  STORAGE(INITIAL 65536
    NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1
    FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE
    DEFAULT) TABLESPACE "USERS"  ENABLE) SEGMENT CREATION IMMEDIATE PCTFREE 10
    PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT
    1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST
    GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    TABLESPACE "USERS" ;
    
      CREATE UNIQUE INDEX "SCOTT"."PK_DEPT" ON "SCOTT"."DEPT" ("DEPTNO") PCTFREE 10
    INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS  STORAGE(INITIAL 65536 NEXT 1048576
    MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
    BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE
    "USERS" ;
    
      ALTER TABLE "SCOTT"."DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO")
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE
    DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS"  ENABLE;
    
    PL/SQL procedure successfully completed.
    
    SQL>  
    

    SY.

    Published by: Solomon Yakobson January 5, 2012 16:22

  • 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

  • primary-foreign key relationship

    Can we create composite foreign key on a primary key? How?

    Published by: 854624 on April 25, 2011 20:30

    Hello

    854624 wrote:
    Can we create composite foreign key on a primary key? How?

    Ensure that:

    CREATE TABLE     city
    (     city_name     VARCHAR2 (20)
    ,     state_abbr     VARCHAR2 (2)
    ,     PRIMARY KEY (city_name, state_abbr)
    );
    
    CREATE TABLE     address
    (     address_id     NUMBER
    ,     city_name     VARCHAR2 (20)
    ,     state_abbr     VARCHAR2 (2)
    ,     CONSTRAINT address_city_fk
              FOREIGN KEY     (city_name, state_abbr)
              REFERENCES city (city_name, state_abbr)
    );
    
  • Should I create primary keys or foreign first?

    I'm new to sql and a student please bear with me.

    I create a script so that when I run a sequence of tables are created. I created all of my fine tables but now I want to add the primary and foreign keys. I tried to do all this at once before but had problems, my idea was to use alter table instructions and add the constraints of key primary and foreign in this way.

    The thing I want to know is what to build first? Should I do any foreign keys and primary keys or visa versa? Or can I do them sequentially and connect relationships between the tables that I will. Thanks in advance!

    Hello

    One thing to remember as a student is to apply logic to the task at hand. In this case, to create a foreign key, it must refer to a primary key in its definition as well so the KP must exist first. What I tend to do is to break down as statements in separate files or sections separate scripts and execute it in a logical order. IE Tables first, and then of PK and UK followed by the FK etc.. I also prefer to create offline rather than constraints in create table statements.

    Hope this helps

    André

Maybe you are looking for