index and foreign key

I just read an article on the index.

Jonathan Lewis - during indexing

The author says that if you update the primary key or a unique key at the end of 'parent' of the referential integrity constraint Oracle locks the "child" table to find the rows of children committed and uncommitted if a suitable index does not exist. After that he says do not create indexes 'foreign key '. I mean, there is a contradiction. What do you think?

delete this thread!

Tags: Database

Similar Questions

  • Indexes and foreign keys

    Hi, we have a RAC Oracle 10 g 2 EE on SLES10.

    I have tables with 300.000.000 of records. These paintings clues because it access it takes very very slow. I check what he need an index for each foreign key. I have a lot of tables and I'm looking for some tools or SQL or similar phrases that tell me, tables for each foreign key index. For example, I need to know what a lot of index left complete me the process and that it.

    Table A
    ID (PK)
    B1_ID
    B2_ID
    C_ID
    D_ID
    ...
    ...

    (B1_ID, B2_ID) FK TO TABLE_B
    (C_ID) FK IN TABLE C
    (D_ID) FK TO TABLE_D


    I create the index in table A, table B, but I don't have the index for the table C and table.

    I have a lot of tables, with several foreign keys.
    How can I find out what indexes that I need to create?

    Thank you very much.

    You can also refer to http://blog.go-faster.co.uk/2007/10/tm-locking-checking-for-missing-indexes.html

    HTH
    Anand

  • Index and foreign key referring to itself

    Hello!

    I'm working on an application that uses a basket stored in a database. The shopping cart uses two tables:
    BASKET: Contains the common information for a shopping cart: the user is logged in etc.
    -Primary key: CART_ID

    CART_ROW: A line in the shopping cart, for example a new product to buy.
    -Primary key: ROW_ID
    -Foreign key: CART_ROW. References CART_ID CART. CART_ID

    On the code lines in the basket are taken by cart, as is modeled by the foreign key. There is a relationship, that we use in the code, but which is not modelled by a foreign key in the database. A line can be dependent on another line, which makes the other row a parent.
    CART_ROW has a PARENT_ID column that refers to CART_ROW. ROW_ID.
    Would you add a foreign key to PARENT_ID? Or are there issues to consider when it is a foreign key to the same table?

    Some time ago, we added the index, both ROW_ID PARENT_ID. The index on PARENT_ID could have harmful, since there is no foreign key?

    Best regards!

    user9005175 wrote:
    Hello!

    I'm working on an application that uses a basket stored in a database. The shopping cart uses two tables:
    BASKET: Contains the common information for a shopping cart: the user is logged in etc.
    -Primary key: CART_ID

    CART_ROW: A line in the shopping cart, for example a new product to buy.
    -Primary key: ROW_ID
    -Foreign key: CART_ROW. References CART_ID CART. CART_ID

    On the code lines in the basket are taken by cart, as is modeled by the foreign key. There is a relationship, that we use in the code, but which is not modelled by a foreign key in the database. A line can be dependent on another line, which makes the other row a parent.
    CART_ROW has a PARENT_ID column that refers to CART_ROW. ROW_ID.
    Would you add a foreign key to PARENT_ID? Or are there issues to consider when it is a foreign key to the same table?

    I suggest to add the foreign key, it will not harm performance (except during an insert when there is validation of the foreign key). But it would avoid users to insert bad data / corrupted by code or directly on loggin in the database.

    Some time ago, we added the index, both ROW_ID PARENT_ID. The index on PARENT_ID could have harmful, since there is no foreign key?

    Index on parent_id would be dangerous if you do not use index after it is created (i.e. There is no application that can make use of this index).
    And if you decide to have a foreign key parent_id then I suggest to have too many indexes on parent_id because it would be at least useful when you delete a record in this table.

    Best regards!

  • 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

    ---

  • Indexes on foreign keys

    I have a large table which basically consists of the foreign keys to other tables (see below). Initially, I decided to create indexes of separate table for each of my foreign key columns. Because of the amount of records in the table, my index tablespace is taking up more data tablespace. What is the recommendation to add indexes for foreign key columns in a table?

    Thank you

    CREATE TABLE STU_ENROLLMENT
    (PK_ID VARCHAR2 (32), sys_guid() by default)
    CONSTRAINT pk_stu_enrollment
    KEY ELEMENTARY SCHOOL
    With the HELP of INDEX TABLESPACE sis_express_index
    STORAGE (4096 INITIAL
    NEXT 4096
    PCTINCREASE 0),.
    Fk_stu_enrollment_stu_school FK_STU_SCHOOL VARCHAR2 (32) CONSTRAINT
    REFERENCES
    stu_school (PK_ID)
    ON DELETE CASCADE,
    Fk_stu_enrollment_schl_cal FK_SCHOOL_CALENDAR VARCHAR2 (32) CONSTRAINT
    REFERENCES
    school_calendar (PK_ID)
    ON DELETE CASCADE,
    Fk_stu_enrollment_pcc_code FK_PCC_CODE VARCHAR2 (32) CONSTRAINT
    REFERENCES
    pcc_code (PK_ID)
    ON DELETE CASCADE,
    Fk_stu_enrollment_grade_level FK_GRADE_LEVEL VARCHAR2 (32) CONSTRAINT
    REFERENCES
    grade_level (PK_ID)
    REMOVE THE NULL VALUE,
    PCC_NOTES VARCHAR2 (1000)

    CREATE INDEX STU_ENROLLMENT_I2 ON STU_ENROLLMENT (FK_SCHOOL_CALENDAR)
    TABLESPACE sis_express_index
    STORAGE (4096 INITIAL
    NEXT 4096
    PCTINCREASE 0);

    CREATE INDEX STU_ENROLLMENT_I3 ON STU_ENROLLMENT (FK_PCC_CODE)
    TABLESPACE sis_express_index
    STORAGE (4096 INITIAL
    NEXT 4096
    PCTINCREASE 0);

    CREATE INDEX STU_ENROLLMENT_I4 ON STU_ENROLLMENT (FK_GRADE_LEVEL)
    TABLESPACE sis_express_index
    STORAGE (4096 INITIAL
    NEXT 4096
    PCTINCREASE 0);

    CREATE INDEX STU_ENROLLMENT_I5 ON STU_ENROLLMENT (FK_VOTECH)
    TABLESPACE sis_express_index
    STORAGE (4096 INITIAL
    NEXT 4096
    PCTINCREASE 0);

    CREATE INDEX STU_ENROLLMENT_I6 ON STU_ENROLLMENT (FK_SPECIAL_ED)
    TABLESPACE sis_express_index
    STORAGE (4096 INITIAL
    NEXT 4096
    PCTINCREASE 0);

    CREATE INDEX STU_ENROLLMENT_I7 ON STU_ENROLLMENT (FK_TUITION_CODE)
    TABLESPACE sis_express_index
    STORAGE (4096 INITIAL
    NEXT 4096
    PCTINCREASE 0);

    Salvation;

    Please see entery Tom site
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:292016138754

    Respect of
    HELIOS

  • Unique key and foreign key in the view of materialzied

    Hello world
    I have one main site and 4 materialized view sites.
    In my main site, I did a main group that contains my tables participating in replication.
    I have a table that has a primary key, foreign key constraint unique.
    In my first materialized view site I did group for my opinion

    BEGIN
    DBMS_REPCAT. () CREATE_MVIEW_REPGROUP
    gname = > "hr_repg"
    Master = > "orc1.com"
    propagation_mode = > 'ASYNCHRONOUS');
    END;
    /

    BEGIN
    DBMS_REFRESH. DO)
    name = > 'mviewadmin.hr_refg ',.
    list = > ",
    next_date = > SYSDATE,.
    interval = > 'SYSDATE + 1/144',.
    implicit_destroy = > FALSE,
    rollback_seg = > ",
    push_deferred_rpc = > TRUE,
    refresh_after_errors = > FALSE);
    END;
    /

    Then I created the materialized view

    HR.test CREATE MATERIALIZED VIEW
    COOL OFF QUICKLY WITH A PRIMARY FOR THE UPDATE KEY
    AS SELECT * FROM [email protected]
    /

    BEGIN
    DBMS_REPCAT. () CREATE_MVIEW_REPOBJECT
    gname = > "hr_repg"
    sName = > 'hr ',.
    oname = > 'test ',.
    Type = > "SNAPSHOT."
    min_communication = > TRUE);
    END;
    /

    BEGIN
    DBMS_REFRESH. ADD)
    name = > 'mviewadmin.hr_refg ',.
    list = > "hr_test.test"
    Lax = > TRUE);
    END;
    /

    When I check the test (materialized view) table in the site of the materialized view to a primary key, but it has no foreign key forced unique having the base table and because my test materialized view can be changed I need to have these 2 constraint on my my materialized view. You have an idea why these 2 constraint were not created on my materialized view? And what should I do to have these two constraints.

    Thanks in advance

    On MView is created automatically only PK. Other constraints (check, not null, unique or FK) should be created manulay. Indexes also.
    But be careful with the FK.
    On ORACLE8, I found lines that are inserted to updatable mview back in deleted updating process, then inserted (downloaded on the main site). When FK is with on delete cascade that the lines of the child tables (mviews are removed too). And when the child mview is updated before mview parent you found the child missing lines.
    When CF is on delete restrict that you refresh the process fails.

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

    ;

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

  • CFTransaction, several inserts and foreign keys

    Here is the joke of what I want to do

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

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

  • Import / Export and foreign keys

    Hi there;

    I am facing the problem more common online backup (I think), when we export a database online;


    I wonder if there are a few steps to that end, or maybe we have an export option to make a snapshot on export database begins;


    Any tips?

    Thank you

    Marcos Ortega
    Brasil

    More LOGIC - a comparable to CONSISTENT parameter is not necessary. Use FLASHBACK_SCN and FLASHBACK_TIME for this feature.

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14215/dp_export.htm#i1005864

    -André

  • foreign key index

    I read a book on the index, he said
    You should almost always index foreign keys because they are frequently used in joins. In addition, if you intend to delete or update unique or primary keys on the parent table, you should index the foreign keys to improve the locking of child records.
    what I don't understand, I should create index on the foreign key in parent-child table or table column or both?

    Thank you

    Hello

    806540 wrote:
    I read a book on the index, he said

    You should almost always index foreign keys because they are frequently used in joins. In addition, if you intend to delete or update unique or primary keys on the parent table, you should index the foreign keys to improve the locking of child records.
    

    what I don't understand, I should create index on the foreign key in parent-child table or table column or both?

    They mean that you need to create an index in the child table, that is the table that contains the foreign key constraint.

    In order to have a foreign key constraint, it must have a primary key constraint, or a unique constraint on the column, or columns referenced in the parent table. Either type (primary key or unique) automatically creates an index, so there is nothing more you need to do in the parent table.

  • Key Reg primary and foreign at the same table

    Hello

    It is - ok if create primary and foreign keys on the same table itself?

    For example:

    In a table X, I have two columns such as Codeunite and ParentUnitcode.
    Is it ok if create Mt10 as principal and ParentUnitcode as foreign keys in the table itself?

    The foreign key base table: OrganizationalUnit
    Foreign key columns: ParentUnitCode
    Primary/Unique key base: OrganizationalUnit
    Primary/unique key col: Mt10

    Can anyone answer me on that?

    Concerning
    Rajesh

    OWB,

    If the two tables are favouring a one-to-one relationship so there no need to have two separate tables and so you can have free referential foreign keys in the same table where the primary key.

  • How to set the condition of rule to check the Primary Key, Foreign Key and Unique

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

    Hello

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

    Hope this helps,
    -Aravind.

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

  • 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

Maybe you are looking for