Two foreign keys

Hi, I would like to create a table with two strangers with the same name.

I have a first table named ' * registry * ' with a column named "* id_registry *" PK, and another called 'friends' table with two columns "* id_res *" and "* id_friends." Now I would like to id_res and id_friends should be CF and have the same id_registry PK as references.
I tried this way:
ALTER TABLE friends add friends COSTRAINT: FK REFERENCES FOREIGN KEY (id_res, id_friends) anagrafica (id_registry); but I got an error like this: ORA-02256.

Is possible to do?

You must create two foreign keys separated like that.

ALTER TABLE friends ADD CONSTRAINT friends_FK1 FOREIGN KEY (id_res) REFERENCES anagrafica (id_registry);

ALTER TABLE friends ADD CONSTRAINT friends_FK2 FOREIGN KEY (id_friends)  REFERENCES anagrafica (id_registry);

Tags: Database

Similar Questions

  • Two foreign keys of a table in a single column

    Hi gurus

    I wonder that can we add two foreign keys of a table on a single column, I think the answer is, but what should be the reason behind this?

    Appreciate if someone there explain to me...

    Concerning

    Muzz

    Hello Muzz,

    Perhaps the example of human Chen reveals a design error.
    If a student has a 'teacher_id' "teacher" FK and FK for "emp" becaue each teacher is an EMP, I guess that the correct design would be to have only the FK of 'teacher' and to have another pointing to the 'emp' table in the 'teacher' tabe FK

    But we can imagine comical situations...
    CREATE TABLE PEOPLE (id NUMBER of KEY PRIMARY, name VARCHAR2 (20 CHAR),...);
    CREATE TABLE SCIENTIST (id people KEY PRIMARY NUMBER (id) REFERENCES, discipline VARCHAR2 (20 CHAR),...);
    CREATE TABLE POLICEMAN (id REFERENCES to KEY PRIMARY NUMBER (id), hire_date people DATE,...);

    First table = all.
    2nd: a subset of the first, with people having the profile of 'scientific '...
    3rd: a subset of the first, with people being a policeman.
    It might be people first table and in none of the 2nd and 3rd, 1st and 2nd, 1st and 3rd only or in the 3 tables.

    Then we can have a fourth table of 'something' referring to a person who must be a scientist and a police officer.

    Here is a sqlplus session illustrating; the last piece: I try inserting several lines in xxxx, only the last is accepted.

    SQL > CREATE TABLE PEOPLE (id NUMBER of the PRIMARY KEY, name VARCHAR2 (20 CHAR));
    Table created.

    SQL > CREATE TABLE SCIENTIST (people of REFERENCES of KEY PRIMARY NUMBER id (id), discipline VARCHAR2 (20 CHAR));
    Table created.

    SQL > CREATE TABLE POLICEMAN (people of REFERENCES of KEY PRIMARY NUMBER id (id), DATE hire_date);
    Table created.

    SQL > CREATE TABLE XXXX (id PRIMARY KEY NUMBER, people_id NUMBER, any other VARCHAR2 (30 CHAR));
    Table created.

    SQL > ALTER TABLE ADD CONSTRAiNT fk_xxsci FOREIGN KEY (people_id) scientific xxxx REFERENCES (id);
    Modified table.

    SQL > ALTER TABLE ADD CONSTRAiNT fk_xxpol FOREIGN KEY (people_id) police xxxx REFERENCES (id);
    Modified table.

    SQL > INSERT INTO person VALUES (100, 'John');
    1 line of creation.

    SQL > INSERT INTO person VALUES (120, 'Mary');
    1 line of creation.

    SQL > INSERT INTO person VALUES (103, 'Tom');
    1 line of creation.

    SQL > INSERT INTO person VALUES (123, "Bruno");
    1 line of creation.

    SQL > INSERT INTO VALUES of scientific (120, 'Chemistry');
    1 line of creation.

    SQL > INSERT INTO scientific VALUES (123, 'Mathematics');
    1 line of creation.

    SQL > INSERT INTO VALUES of policeman (103, DATE ' 2001-04-01');
    1 line of creation.

    SQL > INSERT INTO VALUES of policeman (123, DATE ' 1998-07-01');
    1 line of creation.

    SQL > INSERT INTO xxxx VALUES (1, 456, "nothing");
    ERROR on line 1:
    ORA-02291: integrity constraint (SYS. FK_XXPOL) violated - key parent not found

    SQL > INSERT INTO xxxx VALUES (1, 100, "only to people");
    ORA-02291: integrity constraint (SYS. FK_XXPOL) violated - key parent not found

    SQL > INSERT INTO xxxx VALUES (1, 120, "only the learned");
    ORA-02291: integrity constraint (SYS. FK_XXPOL) violated - key parent not found

    SQL > INSERT INTO xxxx VALUES (1, 103, "only police officer");
    ORA-02291: integrity constraint (SYS. FK_XXSCI) violated - key parent not found

    SQL > INSERT INTO xxxx VALUES (1, 123, 'ok');
    1 line of creation.

    Best regards

    Bruno Vroman.

  • Two foreign keys to a primary key

    I can't display information to two foreign keys in my table. My purpose is to display the name and surname of a project manager and account manager. I have a "Jobs" table that is linked to a table 'employees '.

    Jobs
    ProjectMgrID
    AcctMgrID

    Employees
    EmployeeID
    LastName
    FirstName

    The ProjectMgrID (fk) and the AcctMgrID (fk) are related to the EmployeeID (pk). When I create a query, I do not know how to display the first name and the name of the fields for both. It only allows me to add them once and when I add both times, it just displays the same information twice.

    Help, please!

    Welcome to the forum!

    Looks like you will have to join EMPLOYEES twice.

    Something like the following:

    SELECT  e1.firstname
    ,       e1.lastname
    ,       e2.firstname
    ,       e2.lastname
    FROM    jobs
    JOIN    employees e1    ON e1.employeeid = jobs.projectmgrid
    JOIN    employees e2    ON e2.employeeid = jobs.acctmgrid
    ;
    
  • A table with two foreign keys

    Hi all

    I need to create a table (mytable) filled from 2 different tables, for example, table1 and table2

    When the rows of the table (mytable) comes from the first table (table1) columns in mytable (foreign key to the second table) are nulled, when they come (foreign key) column in the second table (table2)
    the first table) are cancelled as well.

    In terms of performance, architecture is valid, in other words, create a foreign key 2 on mytable and consequently, (the composite foreign key in this table are null according to whether they belong to the first or the second table)?

    Thanks in advance for any help

    I hope to clear

    As promised,

    mhouri.world > create table p as select * from all_users;
    
    Table created.
    
    mhouri.world > alter table p add constraint p_pk primary key (user_id);
    
    Table altered.
    
    mhouri.world > create table c (user_id references p, name varchar2(30));
    
    Table created.
    
    mhouri.world > select min(user_id),max(user_id) from p;
    
    MIN(USER_ID) MAX(USER_ID)
    ------------ ------------
               0           72                                                       
    
    mhouri.world > insert into c (user_id, name) values (0, 'test without index');
    
    1 row created.
    

    Thanks to the autonomous operation I simulates the effect of two users working on the same parent/child table

    (a) first of all, without any index covering the FK on the child table

    (b) second with a function based index on the FK column (note the desc clause in the definition of the index)

    (c) and finally with an index b-tree on the FK columns

    case (a)

    mhouri.world > declare
      2  pragma autonomous_transaction;
      3  begin
      4  delete from p where user_id = 72;
      5  commit;
      6  end;
      7  /
    declare
    *
    ERROR at line 1:
    ORA-00060: deadlock detected while waiting for resource
    ORA-06512: at line 4 
    
    mhouri.world > rollback;
    
    Rollback complete.
    

    case (b)

    mhouri.world > create index fbi_c_fk on c (user_id desc);
    
    Index created.
    
    mhouri.world > insert into c (user_id, name) values (0, 'test with fbi index');
    
    1 row created.
    
    mhouri.world > declare
      2  pragma autonomous_transaction;
      3  begin
      4  delete from p where user_id = 72;
      5  commit;
      6  end;
      7  /
    declare
    *
    ERROR at line 1:
    ORA-00060: deadlock detected while waiting for resource
    ORA-06512: at line 4 
    
    mhouri.world > rollback;
    
    Rollback complete.
    

    case (c)

    mhouri.world > create index btree_c_fk on c (user_id);
    
    Index created.
    
    mhouri.world > insert into c (user_id, name) values (0, 'test with b-tree index');
    
    1 row created.
    
    mhouri.world > declare
      2  pragma autonomous_transaction;
      3  begin
      4  delete from p where user_id = 72;
      5  commit;
      6  end;
      7  /
    
    PL/SQL procedure successfully completed.
    

    Only the index b-tree covered with success the threat of the deadlock in key foreign unidexed

    Best regards

    Mohamed Houri

  • foreign key 'generate' strange behavior check box, any idea?

    Summary: in the properties of the table, the foreign keys, the box generate behaves badly, and I don't understand why or how I got there.

    Oracle Data Modeler 4.0.2.840 8.1 X 64 Windows, jdk1.7.0_55

    the behavior is:

    (1) add the foreign key (two different more to see strange behavior)

    (2) uncheck 'generate' on a foreign key

    (3) apply, Ok

    (4) ask 'Preview DDL', a foreign key constraint is generated, SO FAR SO GOOD, I'm happy

    5-now click on the button 'generate the DDL' for any design = > * * TWO foreign keys are generated?

    (6) even more strange: sometimes the 'generate' check itself after step 5, most of the time is not

    (7) at the beginning this has occurred for a couple of foreign key 'uncheckees', now it almost always happens.

    The relational model was built by importing the SQL scripts already exist (try to migrate the Data Modeler). No too complex ~ 115 tables, 12 times.

    I think it's a bug, but I can't find any reference on the web, maybe I do something wrong?

    Hi Michel,.

    The generation is different depending on whether or not the relevant storage design is open.

    If the design of the storage is not open, the option "Generate DDL" on the foreign key is taken into account (for an overview of the DDL or full generation of DDL).  For an entire generation of DDL, the foreign key will initially not selected phase in the generation of the DDL if Options the option "Generate DDL" on the foreign key has been disabled.  (This change in the phase of the generation of DDL Options will also cause the option "Generate DDL" on the foreign key update.)

    If the design of the storage is open, the option 'generate DDL"on the foreign key has no effect (in a Preview of DDL or full DDL generation).

    Also in a generation full of DDL, an object will be initially marked as not selected if it has been disabled in the previous generation of DDL.

    I hope that this helps to explain the behavior that you find.

    David

  • 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

    ---

  • Several foreign key joins between two tables

    Hello

    I have a question about the creation of a repository.

    I have a date and a fact dimension. The fact table has about 10 columns in foreign key to the date Dimension.

    In this case I should create 10 aliases to create joins in the physical layer and MDB or y at - it another way to handle this situation.

    I ask this question because 10 aliases can get very confusing for me at the later stage of time when creating reports.

    With the help of OBIEE 10.1.3

    If you want to see in the industry as
    End date, start date, date etc. nearby
    you need to create 10 aliases for this purpose in the physical layer, make them drag in MDB and model, and then drag to the area of topic

    Score pls correct/good

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

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

  • Oracle cannot validate the composite foreign key when NULLs comes into play

    Hi all

    When a composite foreign key is used in a schema. Oracle does not check the necessary rules correctly, as indicated below.

    create the table parent_tab
    (
    x int,
    int y,
    z int,
    primary key for constraint p_key (x, y)
    );

    create the table child_tab
    (
    x int,
    int y,
    z int,
    Constraint f_key foreign key (x, y) refers to parent_tab (x, y)
    );

    insert into child_tab (x, y, z) values (1, NULL, 4);
    commit;

    Select count(x|| y) from parent_tab;

    0


    Select count(x|| y) from child_tab;

    1

    Tom Kyte says the following for an explanation.

    The database is unable to validate a foreign key when it is partially null. To assert the rule MATCH FULL for composite foreign keys, you add a constraint to your table:

    The constraint will ensure that either

    • All columns have NULL value in the foreign key, or
    • None of the columns are set to NULL in the foreign key

    As long as this constraint is in place, your foreign key will work as you probably think that it should.

    However, it does not explain WHY? I mean why Oracle is unable to validate the foreign key when it is partially NULL?

    Concerning

    John Spencer wrote:

    He thinks logically.  You have a composite PK of two columns, so 1, 1 is a valid key, as these are the 1, 2 and 1, 3 and 1.42.  In the child table, you have a line 1, the null value.

    What parent should have the child?

    I wish that it would be logical about this. Unfortunately, Oracle applies different rules in different cases. For example, parent of the value 1, NULL value and 1 child, NULL is not the same as NULL is equal or not equal to null. At the same time, one constraint unique index / unique Treaty, 1, NULL, equal to another 1, NULL NULL treatment as being equal to NULL and don't let several lines with 1, the NULL value.

    SY.

  • 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

  • Foreign key, check force

    Hello

    This is the structure of two two table.

    Untitled.png

    DDL:

    CREATE TABLE TEST_PARENT
      (
        PARENT_KEY NUMBER (22),
        PARENT_ID NUMBER (22),
        PARENT_NAME VARCHAR2 (255 CHAR),
        EFFECTIVE_START_DATE DATE DEFAULT sysdate NOT NULL ,
        EFFECTIVE_END_DATE   DATE
      ) ;
    ALTER TABLE TEST_PARENT ADD CONSTRAINT PK_TEST_PARENT PRIMARY KEY ( PARENT_KEY ) ;
    
    
    CREATE TABLE TEST_CHANNEL
      (
    
    
        CHANNEL_KEY NUMBER (22),
        CHANNEL_ID NUMBER (22),
        CHANNEL_NAME VARCHAR2 (255 CHAR),
        EFFECTIVE_START_DATE DATE DEFAULT sysdate NOT NULL ,
        EFFECTIVE_END_DATE   DATE 
      ) ;
    ALTER TABLE TEST_CHANNEL ADD CONSTRAINT PK_TEST_CHANNEL PRIMARY KEY ( CHANNEL_KEY ) ;
    

    Logic:

    Parent_id is always fixed to a Parent. But a Parent can have different attributes (parent_name here). Where the attributes are changing it will end the bu previous records put a value to effective_end_date and it will create a new line. New line will have the PARENT_KEY new PARENT_NAME with new effective_start_date and null in effective_end_date.

    Same logic applies to the CHILD table as well.

    What is the best way to put a reference to the type of the foreign key in the CHILD table that in case, will ensure that a child cannot exist without a parent now. I can't take PARENT_KEY as a foreign key to the same parent can change the PARENT_KEY and a child must always point to the parent ASSET (EFFECTIVE_END_DATE as null) folder.

    Thanks in advance.

    I would enrich your datamodel by tables of the object/version as:

    CREATE TABLE TEST_PARENT_OT
    (
    NUMBER OF PARENT_KEY (22) NOT NULL
    ) ;

    ALTER TABLE TEST_PARENT_OT ADD CONSTRAINT PK_TEST_PARENT_OT PRIMARY KEY (PARENT_KEY);

    CREATE TABLE TEST_PARENT_VT
    (
    NUMBER OF PARENT_KEY (22) NOT NULL,
    NUMBER of VERSION_ID (22) not null,
    PARENT_NAME VARCHAR2 (255 CHAR),
    EFFECTIVE_START_DATE DATE default sysdate NOT NULL,
    DATE OF EFFECTIVE_END_DATE
    ) ;

    ALTER TABLE TEST_PARENT_VT ADD CONSTRAINT PK_TEST_PARENT_VT PRIMARY KEY (PARENT_KEY, VERSION_ID);
    ALTER TABLE TEST_PARENT_VT add CONSTRAINT FK_PARENT_VT_PARENT_OT foreign key (parent_key) refers to test_parent_ot (parent_key);

    CREATE TABLE TEST_CHANNEL_OT
    (
    NUMBER OF CHANNEL_KEY (22) NOT NULL
    ) ;

    ALTER TABLE TEST_CHANNEL_OT ADD CONSTRAINT PK_TEST_CHANNEL_OT PRIMARY KEY (CHANNEL_KEY);

    CREATE TABLE TEST_CHANNEL_VT
    (
    NUMBER OF CHANNEL_KEY (22) NOT NULL,
    NUMBER OF VERSION_ID (22) NOT NULL,
    PARENT_KEY NUMBER (22) NOT NULL,
    CHANNEL_NAME VARCHAR2 (255 CHAR),
    EFFECTIVE_START_DATE DATE default sysdate NOT NULL,
    DATE OF EFFECTIVE_END_DATE
    ) ;

    ALTER TABLE TEST_CHANNEL_VT ADD CONSTRAINT PK_TEST_CHANNEL_VT PRIMARY KEY (CHANNEL_KEY, VERSION_ID);
    ALTER TABLE TEST_CHANNEL_VT add CONSTRAINT FK_CHANNEL_VT_CHANNEL_OT FOREIGN KEY (channel_key) REFERENCES TEST_CHANNEL_OT (channel_key);
    ALTER TABLE TEST_CHANNEL_VT add CONSTRAINT FK_CHANNEL_VT_PARENT_OT FOREIGN KEY (PARENT_key) REFERENCES test_parent_ot (parrent_key);

    Using this you will not have to reallocate your child of the lines when a new version of parent is created and you will be able to have the independent channel versions of the parent versions (so no need to change all the children when the parents ends).

    the construction of views of parents and the channels which only show active lines.

    The problem you may have is to be sure to have for each point in time an active version and so I would not implement of an effective_end date, but inherit the effective end of the effective next to (which is a little more work but you will help gapelessness if necessary)

    HTH

  • integrity of foreign key error

    I had the departments and officials from two tables
    employee table has a foreign key that is a primary key in the departments table
    IE department_id
    every time I try to delete records from the employee table using the department_id IE a foreign key
    then it displays error
    but when I do it through other constraints then the lines are to remove
    so why can't delete lines in the employees table using department_id which is a foreign key in the employees table
    and the primary key for the departments table?

    guys, it's really easy when you really look at the error message:

    The violation is not the FK on employees.department_id. (the name will be EMP_DEPT_FK)
    The violation is against the FK hr.dept_mgr_fk which refers to the column manager_id (employee id) in the departments. When you try to remove all dept 50 employees, you also try to remove the service manager, but which is not allowed due to the FK of departments. Try this:

    update departments set manager_id = null where id = 50;
    delete from employees where department_id = 50;
    

    Bjoern

  • type a materialized view foreign key constraint?

    Hello.

    I have a materialized view that flows into a single column 'A' two different columns of different tables of a remote database.

    I also have a table that has a column 'B', whose values must exist in the column 'A' of the materialized view.

    So it's like defining a constraint foreign key of a table to a view, but this is not possible.

    Is it possible to do?

    I saw some triggers that verify the existence of the 'A' value before insertion in 'B', but this fails when a value is changed or deleted in 'A'

    Any suggestions?

    Thank you very much.

    Published by: user7029403 on 18-ene-2013 03:57

    There is no problem of definition of a primary key on a materialized view and then reference it with a foreign key. It works for me:

    create database link l1 connect to scott identified by tiger using 'orcl';
    create materialized view mv1 as select deptno||dname as a from dept@l1;
    alter table mv1 add constraint mv1pk primary key (a);
    alter table dept add (fkcol as (deptno||dname));
    alter table dept add constraint deptfk foreign key (fkcol) references mv1;
    

    I don't know there is a more elegant solution than to use a virtual column, which seemed the best way to get around the concatenation of two columns in a single

  • Questions about the creation of a foreign key on a table

    Hello @ll,

    during an update of the database, I lost a foreign key between two tables. The tables are called werteart and werteartarchiv_pt. Because of its size, werteartarchiv_pt is a partitioned table. The missing foreign key was a constraint on werteartarchiv_pt table referencing werteart.

    Some statistics on the size of the mentioned tables:
    werteart 22 MB
    werteartarchiv_pt 223 GB
    werteartarchiv_pt (Index) 243 GB

    I tried to create the foreign key again but it failed with the following error (apologies for the German error message):

    sqlplus ORA-00604: Fehler auf rekursiver SQL-ebony 1
    sqlplus ORA-01652: Temp-Segment kann nicht um 128 in Tablespace TEMPS00 judgements

    The statement that I used:

    ALTER table werteartarchiv_pt
    Add constraint werteartarchiv_pt_fk1
    foreign key (rail, werteartadresse, merkmale)
    Reference werteart (rail, werteartadresse, merkmale)
    on delete cascade
    at the delayed start can be delayed;

    So, the problem seems to be that Oracle needs a lot of temporary tablespace to generate foreign key and I do not know how and why.

    My questions now are, and I hope that someone is there who can answer all or part of it:

    (1) why Oracle should temporary tablespace to create the foreign key? The foreign key uses the same columns as the primary key.

    is 2 (a) possible to change the statement without using the temporary tablespace?

    2 (b) if it is not possible to avoid the use of temporary storage space, is there a formula how to calculate the necessary temporary tablespace?

    (3) is it possible to modify data in tables while the foreign key is created or is the whole table locked during the process?

    Any help or advice is appreciated.

    Kind regards
    Bjoern

    RollinHand wrote:
    My questions now are, and I hope that someone is there who can answer all or part of it:

    (1) why Oracle should temporary tablespace to create the foreign key? The foreign key uses the same columns as the primary key.

    Because it is data validation to ensure that the foreign key are violated. If you had specified NOVALIDATE ACTIVATE in its creation then the existing data in the table should be checked and the statement must fill out instantly (future data added is enabled by the constraint).

    http://download.Oracle.com/docs/CD/B28359_01/server.111/b28310/general005.htm

    Search for "Enable Novalidate constraint State"

Maybe you are looking for

  • Qosmio F50-125 freezes for 2 seconds every 10 minutes

    Hello. On 15 may, I noticed that my laptop freezes for 2-3 seconds every 10 minutes.I use the original Windows Vista 32 bit. I remember my firewall (Comodo) program update and Toshiba TEMPRO that day.I tried to restore the system to the State on May

  • Why Apple does not have a backup battery for Apple devices?

    Why Apple does not have a backup battery for Apple device? Recommended us that of our full when we are on the road, so they should do a backup battery for their devices instead of other companies do. The backup battery that I use for my iPhone 5 c do

  • Photo animation control ring spinning problem

    Hello Control of animation frame ring does not turn to me as expexted.In my main function after having posted the signAnimateCtrl_ConvertFromPictRing (Panel, PNL_SPLASH_ANIMATION);AnimateCtrl_SetAttribute (Panel, PNL_SPLASH_ANIMATION,ATTR_ANIMATE_ENA

  • Accidents of games

    I use Windows 7 RC and it works fine except when it comes to games. I tried all the games crashes after a few minutes. The rest, no problem. So, if you know what the problem is please let me know. Thank you!

  • If subscription "expires" due to technical difficulties, Adobe will give a separate temporary license?

    Unknown technical difficulties, my programs all the reports start my subscription as expiring within 14 days. It was 7 days ago and even with several cats with Adobe support and promises that it will be fixed, nothing has changed. Hope it will, but a