Questions about creating a foreign key on a large table

Hello @ll,
during a database update 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 table werteartarchiv_pt referencing werteart.
Some statistics about the sizes 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 (Excuses for the german error message):
sqlplus ORA-00604: Fehler auf rekursiver SQL-Ebene 1
sqlplus ORA-01652: Temp-Segment kann nicht um 128 in Tablespace TEMPS00 erweitert
The statement I used:
alter table werteartarchiv_pt
add constraint werteartarchiv_pt_fk1
foreign key (schiene, werteartadresse, merkmale)
references werteart (schiene, werteartadresse, merkmale)
on delete cascade
initially deferred deferrable;
So the problem seems to be, that Oracle needs a lot of temporary tablespace to generate the foreign key and I do not know how much and why.
My questions now are, and hopefully someone is here, who can answer all or a part of it:
1) Why does Oracle need temporary tablespace to create the foreign key? The foreign key uses the same columns like the primary key.
2a) Is it possible to tweak the statement without using the temporary tablespace?
2b) If it is not possible to avoid the usage of the temporary tablespace, is there a formula how to calculate the needed temporary tablespace?
3) Is it possible to modify data in the tables while the foreign key is created or is the whole table locked during the process?
Any help or hint is appreciated.
Regards,
Bjoern

RollinHand wrote:
My questions now are, and hopefully someone is here, who can answer all or a part of it:
1) Why does Oracle need temporary tablespace to create the foreign key? The foreign key uses the same columns like the primary key.Because it's validating the data to ensure the foreign key won't be violated. If you had specified ENABLE NOVALIDATE when creating it then the existing data in the table wouldn't need to be checked and the statement should complete instantly (future data added would be checked by the constraint).
http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/general005.htm
Search for "Enable Novalidate Constraint State"

Similar Messages

  • Question about scripting of foreign keys

    When I script FK_SalesOrderHeader_Address_BillToAddressID key from AdventureWorks.[Sales].[SalesOrderHeader] I get this:
    ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID] FOREIGN KEY([BillToAddressID])
    REFERENCES [Person].[Address] ([AddressID])
    GO
    ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID]
    GO
    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Foreign key constraint referencing Address.AddressID.' , @level0type=N'SCHEMA',@level0name=N'Sales', @level1type=N'TABLE',@level1name=N'SalesOrderHeader', @level2type=N'CONSTRAINT',@level2name=N'FK_SalesOrderHeader_Address_BillToAddressID'
    GO
    What is second ALTER statement for (the one highlighted with bold font)? First ALTER statement already includes WITH CHECK, so isn't the second one redundant?

    The 2nd Statement enables the Foreign Key.
    I think it is redundant because FOREIGN KEY is enabled by default when you execute the 1st statement.
    This script is generated by SSMS (Yes?), This is added just to ensure that CONSTRAINT is enabled.
    - Vishal
    SqlAndMe.com
    Yes, it is generated by SSMS 2008.

  • Question about creating and updating new columns in a table

    Hi, I have a couple of questions that would love some answers to
    Please bear in min that questions relate to datawarehouse / Just large tables with say about 50 million records
    1) How do you create new columns in a big table
    2) how do you update the new columns
    3) would you create an index on a column in a table with 200m rows when the only two possible values are stored in the column (e.g.Y, N) - give your resason
    my aswers to these would be
    1) simple alter table ...
    2) simple update statements
    3) No need to create an index
    I might be wrong on these in the context of datawarehouse
    cheers
    css_jay99

    If the number of Y vs. N is about 50/50, you only have to parse through 50% of the
    overall amount of columns.Fnord. If the ratio of Y to N was 1:20 then the index would be useful for searching for values of Y only. Or if the column is nullable and the bulk of the entries were null then it might be useful. But a 50/50 split? FTS is much more effective.
    So, it does depend on the data distribution, but in most cases such an index would never be used (or should never be used).
    Cheers, APC

  • Foreign Keys for a Logical Table

    Hi All,
    I want to know in which scenarios we create the Foreign Keys for a Logical Table. Once we create the foreign key for the logical table, does it mean that it will automatically override if any joins are there.
    Physical Table A, B ( no physical joins)
    Logical Table A, B (logical join B(Dim)-->A(Fact))
    created the foreign key in logical table A with B .(A.1=B.1)
    Will the rpd generate sql with A.1=B.1 join condition for reports.
    I tried to create the logical foreign key for logical table A, I could not see any corresponding table option.Here is its snapshot
    http://tinypic.com/r/jq1gkz/6
    Thanks,
    Virat

    In general when we go complex joins in Physical layer we go for Logical foreign key joins in BMM layer, best examples is SCD Type-II.
    Physical Table A, B ( no physical joins)
    -->You need to have a physical join so that this can be override by BMM layer
    created the foreign key in logical table A with B .(A.1=B.1) Will the rpd generate sql with A.1=B.1 join condition for reports.
    -->Yes you can see this join in BI Physical query.
    I tried to create the logical foreign key for logical table A, I could not see any corresponding table option.Here is its snapshot
    -->2 cases: 1)You need to delete existing logical joins 2) You might not have join in physical layer.
    Hope this helps
    Let me know for issues
    Edited by: Srini VEERAVALLI on Jan 18, 2013 1:29 PM
    BTW: You got very good name, why dont you update in your profile to see your name instead of some number
    Edited by: Srini VEERAVALLI on Jan 18, 2013 1:29 PM

  • I am unable to create the Foreign key

    Hi,
    I need to create the Foreign key which reffered to composite primary key.
    the following table structure
    Parent table
    DIVISION, PROJECT_NUMBER, COMPETITION_PROJECT_NUMBER, COMPETITIVE_STMT_TYPE, SEQUENCE, CATEGORY, STATEMENT, USER_ID, RECORD_MODIFICATION_DATE
    Here composite primary key columns(DIVISION, PROJECT_NUMBER, COMPETITION_PROJECT_NUMBER, COMPETITIVE_STMT_TYPE, SEQUENCE)
    Child Table
    DIVISION          VARCHAR2 (4)          
    PROJECT_NUMBER          NUMBER (10)COMPETITION_PROJECT_NUMBER     NUMBER (10)          
    COMPETITIVE_STMT_TYPE          VARCHAR2 (2)          
    SEQUENCE     NUMBER (2)          
    CATEGORY          VARCHAR2 (100)     
    STATEMENT     LONG          
    USER_ID     VARCHAR2 (100)          
    RECORD_MODIFICATION_DATE     DATE     
    ALTER TABLE COMPETITION_STMT ADD (CONSTRAINT COMPET_STMT_FK_PROJ_NUM foreign key
              (PROJECT_NUMBER) REFERENCES PROD_COMPET_XREF (PROJECT_NUMBER));
    when i am trying to create foreign key i got this error
    ORA-02270: no matching unique or primary key for this column-list
    this is production issue Please help me.
    Thanks in advance
    Regards
    Kumar.s

    ALTER TABLE PROD_COMPET_XREF ADD (
    CONSTRAINT PROD_COMP_XREF_PK_DPNCPNCT
    PRIMARY KEY
    (COMPETITION_PROJECT_NUMBER, PROJECT_NUMBER, DIVISION, PRODUCT_LOC_INDICATOR)
    When you create a foreign key, it must reference a unique or primary key. The primary or Unique key must consist ONLY of those columns upon which the Primary key is based.
    You must Alter the table and add a Unique key if you want to keep your compsite primary key constraint. The Unique key must be for only the column that your foreign key references. Then try to recreate your foreign key.
    I doubt you will be able to add a foreign key because I suspect you might have multiple rows with the same value for this column based on your composite key; however, if you only intend for the project number to be listed only once and to be unique for each row, then the unique key may work or you may want to revist your primary key on this table. Perhaps you don't need it to be a composite PK???
    If you can't work around that, one thing you can do is build a table based just on PROJECT_NUMBER that contains details about the project number and have other tables reference that. That is, if you have multiple rows with the same project number in that table. You may already have one? Perhaps you can build your foreign key to reference that?

  • Create a foreign key from a field that is part of a mulitple primary key

    Hi,
    i had a table named T_A, with a double primary key : (A,B)
    Then i created a table named T_B with a field : C.
    I want this field T_B.C to take only values that already exist in field T_A.A.
    So i tried to create a foreign key on my field T_B.C, pointing on the field T_A.A : an error message appeared "not possible to create a foreign key on a field that is not a primary key".
    How can i solve this....? If U have any idea, please mail me !!
    THANX very much.

    Add column A as foreign key into the table T_BHow?
    (was the question from the original poster. Adding a column to table T_B that happen to have same name as the corresponding column in table T_A would not allow you to add the foreign key).
    SQL> create table t_a (a number, b number, primary key(a, b)) ;
    Table created.
    SQL> create table t_b(a number, c number, constraint foreign key references t_a(a)) ;
    create table t_b(a number, c number, constraint foreign key references t_a(a))
    ERROR at line 1:
    ORA-02270: no matching unique or primary key for this column-list
    SQL>

  • Creating a foreign key constraint on a synonym of table in another schema.

    Hi,
    I am having two user operapps and oper
    owner of table po_vendors is operapps ,i have created a synonym in oper with select permission.
    now i am trying to create a foreign key.
    ALTER TABLE OPS_BR_VENDORS ADD ( FOREIGN KEY (VENDOR_ID) REFERENCES PO_VENDORS (VENDOR_ID));
    the bolded po_vendors is the synonym for the table po_vendors in operapps.
    i am getting the below error message.
    SQL> ALTER TABLE OPS_BR_VENDORS ADD ( FOREIGN KEY (VENDOR_ID) REFERENCES PO_VENDORS (VENDOR_ID));
    ALTER TABLE OPS_BR_VENDORS ADD ( FOREIGN KEY (VENDOR_ID) REFERENCES PO_VENDORS (VENDOR_ID))
    ERROR at line 1:
    ORA-01031: insufficient privileges.
    i have given dba privileges to oper user.
    Please advice.

    1) You cannot create a constraint on a synonym. You have to specify a physical table (i.e. OPERAPPS.PO_VENDORS)
    2) The owner of the OPS_BR_VENDORS table will need to have the REFERENCES permission on the PO_VENDORS table granted directly (not via a role).
    Justin

  • A question about creating packages as local objects in ABAP

    Hi,
    I have a question about creating packages with SE80. Whenever I create a new package it is assigned a new transport request. After that, I can create new programs inside this package, and each time I can choose whether to assign the new program to a transport request or just save it as a local object (I often do this for test programs that I don't transport and I remove them once my tests have been done).
    What I would like to ask is that, is it possible to create a package (and not just programs inside a given package) as a local object? so that every new object created in this package will be considered as a local object?
    Thanks in advane,
    Kind Regards,
    Dariyoosh

    Thomas Zloch wrote:
    Please also check the F1 help for the package field e.g. in SE80, SAP standard is in range A-S and U-X, namespaces start with "/", so you should be save. I am using the T namespace for temporary stuff since a long time and did not have a problem so far.
    > Thomas
    >
    > P.S. this applies to the package name only, of course
    Thank you very much for this remark, I checked F1 help for the package field and in fact as you mentioned these ranges are for local objects.
    Once again, thank you very much for your help.
    Kind Regards,
    Dariyoosh

  • Adding a foreign key to an access table

    I have set up two tables in access and I am using SQL insert
    with the form to populate the database. When I “submit”
    the form I receive the following error:
    Element CUST_ID is undefined in CUSTOMER_INFO.
    The error occurred in
    C:\Inetpub\wwwroot\spl_web_site\public_records\order_insert.cfm:
    line 23
    21 : <cfquery datasource="#odbc_datasource#"
    name="desc">
    22 : insert into rec_results (customer_info.cust_id,rec_desc)
    23 : values('#customer_info.cust_id#',
    24 : '#rec_desc#')
    25 : </cfquery>
    How do I get cust_id into the second table to be used as the
    foreigh key when it “has not been created (defined)” in
    the first table?

    If your cust_id is an autonumber primary key field in your
    first table, then you will have to create that record first, then
    retrieve the primary key value to be used as your foreign key in
    your second table, especially if you have foreign key constraints
    on the table. This is normal relational database behavior, since it
    isn't really possible to have a child if there is no parent. In
    this case, you will need some sort or SELECT between your two
    inserts in order to determine the newly created cust_id. Or, you
    may need some other means of gerating your unique PK value for
    cust_id outside of Access. If you do the SELECT method, you would
    do something like SELECT MAX(cust_id) FROM customer_info (assuming
    that cust_id is generated sequentially), and you should enclose all
    three database transactions within CFTRANSACTION tags so that you
    don't accidentally grab the wrong cust_id from another simultaneous
    transaction.
    Phil

  • How to create a foreign key for the table from two different tables?

    Hi All,
    I have a three table like below. In the below table SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK will be having the primary key for NAME column. The same SAMPLE_CONS3_CHECK table also having the primary key for NAME column and forieign key for SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK tables. See the below code 2
    code 1:
    CREATE TABLE SAMPLE_CONS_CHECK
            (NAME VARCHAR2(10),
            SERIES  VARCHAR2(5)
    CREATE TABLE SAMPLE_CONS2_CHECK
            (NAME  VARCHAR2(5),
             MODEL  NUMBER
    CREATE TABLE SAMPLE_CONS3_CHECK
            (NAME  VARCHAR2(5),
             MODEL_NO  NUMBER
            )code 2
    alter table SAMPLE_CONS_CHECK
    add constraint SAMPLE_CONS_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS2_CHECK
    add constraint SAMPLE_CONS2_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS3_CHECK
    add constraint SAMPLE_CONS3_CHECK_pk primary key (NAME)
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK1 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS_CHECK
        NAME
    ) ON DELETE CASCADE;
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK2 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS2_CHECK
        NAME
    ) ON DELETE CASCADE;From the above schenario i am able to insert the data to SAMPLE_CONS3_CHECK table. But the parent data is already available in the parent table. The problem is here two different constarints from two different tables. While inserting, it is checking from both the tables whether the parent is exist or not.
    How can i solve this problem? Can anyone halp me about this?
    Thanks
    Edited by: orasuriya on Aug 8, 2009 2:02 AM

    Actually the design is completely incorrect.
    What you say is
    I have
    'foo', 'foo series'
    'foo','foo model'
    'foo',666
    By virtue of table3 referring to both table1 and table2.
    This means you actually need to have 1 (one) table:
    'foo','foo series','foo model', 666
    And the 'problem' disappears.
    Sybrand Bakker
    Senior Oracle DBA

  • Can I create a foreign key when creating Business Components from Tables

    Hi,
    I would like to use ADF and JSF to create an application on our database. My problem is our database does not "conform". i.e. there are no foreign key constraints.
    When I create a "Business Component from Tables" view, can I put in my own joins between tables so enabling the use of the generated views?
    Jon L.

    View object instances show up in the data control palette once you've added them to your application module's data model.
    See these sections in the ADF Developer's Guide for more information:
    Section 2.6.3, "Using View Objects in the Application Module's Data Model" talks about using view object instance in the data model as part of the overview chapter.
    Section 4.5, "Understanding the Active Data Model" explains a little more about this
    Section 5.3, "Using a View Object in an Application Module's Data Model" shows how to do this.
    Chapter 10, "Overview of Application Module Data Binding" gives details on how the application and its view objects are exposed in the Data Control palette.
    You can find the guide on the ADF Learning Center on OTN.
    http://www.oracle.com/technology/products/adf/learnadf.html
    Look for the ADF Developer's Guide for Forms/4GL Developers.

  • Question about creating tree

    Hi, when I created a tree with an employees table, I created an entity object, association about manager foreign key, view object, and view link. There is a recursive tree to be created.
    But when I just created a view object and view link to create a tree. There is just two layer. Why I can't create a recursive tree with a view object?

    http://technology.amis.nl/2006/08/07/creating-multi-type-node-children-and-child-node-labels-in-adf-faces-tree-component/

  • How to create a Foreign key relationship between 2 user defined tables...

    Hi Folks,
    I have created two user defined tables... Where in i want to create foriegn key relationship between the 2 tables.... Can anyone guide the step by step procedure to do this scenario...
    Any help would be highly appreciated...
    Thanks

    Hi
    1.  In the 2nd table call the field of the 1st table which is a primary key.
    2.  Give the same field and dataelement name.
    3.  Select that field and then click on the foreign key field icon which is beside Search Help button.
    4. Then give short text, and the 1st table name.
    5. Then in the below box give the 2nd table name and 2nd table field name which you have called from 1st table.
    6. Then click on copy, then u will be able to see Check table name and check table field name beside foreign key table name.
    7. Then again click on copy.
    Regards
    Haritha.

  • HOw to create a foreign key in Derby netbeans 5.0

    I am trying to create a primary key in my database/web java application. I am using netbeans 5.0 and java vr5. I have put the following line in the DERBY SQL editor:
    ALTER TABLE staff ADD CONSTRAINT staff_fk FOREIGN KEY (staffID) REFERENCES staff (staffID);
    this returns Error: staffID is not a colum in Table of VTI skill
    However I have got a staffID Column in the table. Is this a BUG in netbeasn 5.0 or am I doing this incorrectly please can anyone show me a way round this problem. Iam suppose to use CMP or something please help.
    thanks in advance

    ALTER TABLE "staff" ADD CONSTRAINT "staff_fk" FOREIGN KEY ("staffID") REFERENCES "staff" ("staffID");

  • ABAP question: define a custom foreign key for a standard field??

    Hi,
    I want to use the field ADDR1_DATA-STR_SUPPL3 for customer use. I must to define a foreign key against a Ztable (as verification table) for this standard field. Also I must to define a custom search help.
    To defining a foreign key for this field, I must be in change mode, so the system ask to me for registering the object. That means this action is a modification. My question is the following: is there any way to do so without SAP standar modification??
    For instance, using BDT events...but how?
    Thanks in advance.
    Regards,
    Rosa

    Hi Rosa,
    Changing SAP Standard dictionary elements is not possible with out changing the same. To change these elements, we dont have any other method apart from SAP standard modification.
    Cheers
    Pavan

Maybe you are looking for