Drop partition without disabling foreign key

Hi All,
I have parent and child table.
Parent table
create table parent_1
(id number,
create_date date,
constraint parent_1_pk001 PRIMARY KEY (id))
PARTITION BY RANGE (create_date)
INTERVAL (NUMTODSINTERVAL(1,'DAY'))
(PARTITION parent_1_part VALUES LESS THAN ('01-JAN-2010'));
Child Table
create table child_1
(id number,
create_date date,
constraint child_1_fk001 FOREIGN KEY (id)
REFERENCES parent_1 (id))
PARTITION BY RANGE (create_date)
INTERVAL (NUMTODSINTERVAL(1,'DAY'))
(PARTITION create_date_part VALUES LESS THAN ('01-JAN-2010'));
I am having problems dropping partition.
Parent_1
1     26-JUL-12
2     26-JUL-12
Child_1
1     26-JUL-12
alter table CHILD_1 drop partition SYS_P274;
table CHILD_1 altered.
ON DROPPING PARENT PARTITION
alter table parent_1 drop partition SYS_P273;
Error report:
SQL Error: ORA-02266: unique/primary keys in table referenced by enabled foreign keys
02266. 00000 - "unique/primary keys in table referenced by enabled foreign keys"
*Cause:    An attempt was made to truncate a table with unique or
primary keys referenced by foreign keys enabled in another table.
Other operations not allowed are dropping/truncating a partition of a
partitioned table or an ALTER TABLE EXCHANGE PARTITION.
*Action:   Before performing the above operations the table, disable the
foreign key constraints in other tables. You can see what
constraints are referencing a table by issuing the following
command:
SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = "tabnam";
PLEASE CAN I KNOW IF THERE IS ANY WAY TO DROP PARENT PARTITION WITHOUT DISABLE/ENABLE FOREIGN CONSTRAINTS
Thanks

SQL Error: ORA-02266: unique/primary keys in table referenced by enabled foreign keys
02266. 00000 - "unique/primary keys in table referenced by enabled foreign keys"
*Cause: An attempt was made to truncate a table with unique or
primary keys referenced by foreign keys enabled in another table.
Other operations not allowed are dropping/truncating a partition of a
partitioned table or an ALTER TABLE EXCHANGE PARTITION.
*Action: Before performing the above operations the table, disable the
foreign key constraints in other tables. You can't do that until you disable the foreign key constraint
http://jonathanlewis.wordpress.com/2006/12/10/drop-parent-partition/
Hope this helps
Mohamed Houri
www.hourim.wordpress.com

Similar Messages

  • Disabling Foreign keys before Insert

    DB version:10gR2
    Is it a standard practice to disable Foreign keys when you have Huge INSERTs . Is there performance enhancement by deferring the Foreign key Check during Huge INSERTs?
    Our client want to disable the FKs before a huge INSERT. They say they can manually rectify all issues related to Foreign key violation resulting from Disabling the FK.
    What do you guys reckon?

    It should hapen an enhancement performance by deferring the Foreign key Check during Huge INSERTs.
    The same thing with triggers.
    If you are sure that data that you want to insert is not inconsistent with the data on the DB, or that you manually rectify inconsistencies after the insert, then there is no problem by disabling Foreign key constraints/triggers.
    Also there are gains of performance if you drop of the indices (if there's any) and recreate after the Huge INSERT.
    Regards.

  • Subquery in IF statement in trigger, without using foreign keys

    Hello,
    I'm investigating ways of writing a subquery in an IF statement, which is placed inside a trigger.
    I wanna write smth like IF (:new.jazz not in (select goldies from T where ... )) etc. I don't know whether the fact that the IF is in a trigger adds some additional restrictions. (Does it?)
    So far I found the solution described here: SubQuery Comparison in If Statement which I find a bit tacky, I could have the 'cooleststarinthegalaxy' instead of 1 and seems you need to do extra light, but still extra lifting.
    I also read about the possibility of using MERGE, which I'm currently researching.
    Is there any other way?
    Thanks
    Edited by: BluShadow on 14-Nov-2012 13:37
    fixed link
    Edite by me: the question is how (if possible) to do this without a foreign key.
    Edited by: questioningq12 on Nov 14, 2012 6:11 AM
    Edited by: questioningq12 on Nov 14, 2012 6:13 AM

    Hi,
    questioningq12 wrote:
    Say I have tables A(namea varchar(10)), B(nameb varchar(10)), and B contains tuples ('1stname','2ndname').
    I wrote a trigger before insertion, for each row, on table A. For a tuple t to be inserted, it should check whether t.namea is in the set of values nameb from B.
    E.g., INSERT INTO A VALUES('1stname') should work. But INSERT INTO A VALUES ('3rdname') should fail. You can use a foreign key constraint for that.
    If the tables already exist, and b.nameb is declared as UNIQUE (or PRIMARY KEY), then you can say:
    ALTER TABLE  a
        ADD CONSTRAINT     a_namea_fk
        FOREIGN KEY  (namea)
        REFERENCES b (nameb)
    ;If you had a situation where you really needed to query a table in PL/SQL, and you weren't sure if the query would find anything, you could put the query in its own BEGIN ... EXCEPTION block, and test for NO_DATA_FOUND.
    If you're just checking to see if a row exists or not, you can always write a query that is guaranteed to return exactly 1 row, like this:
    BEGIN
        SELECT  COUNT (*)
        INTO    x
        FROM    b
        WHERE   nameb = :NEW.namea
        AND         ROWNUM  = 1;
        IF x = 0
        THEN  
            ...        -- print msgs, raise exceptions etc
        END IF;
    END;Edited by: Frank Kulash on Nov 14, 2012 9:22 AM
    Added example

  • CDR-21605, but not without a foreign key

    Hello All,
    I am working with Designer 9.0.2.96.6 and generating some forms that were proted from a previous designer version. Most of the forms are ok, but some are not.
    They give the following error:
    Message
    CDR-21605: Failed while processing Module F_CF_COD in function cfbbsa() :671 BOF cfbbs
    Cause
    The generator failed due to an unexpected error - the
    error indicates the object the generator was processing
    when it failed.
    Action
    These forms use two tables that are joined using a foreign key.
    I have created a copy of the form and it didn't work either. Then when I disabled the foreign key that is used in the table, and regenerate the form, it works ok.
    The problem is that the foreign key is used to get referential integrity.
    Does anyone have any idea or direction to solve this problem?
    Mark

    Are we generating Master-Detail Form or Base Table with lookup form? Please give more details, such as the schema definition, the Module Data Diagram, i.e. which is the base table, which is the reference table.
    For Master-Detail table, you need to define the Context value of the master table in order to populate the values of the detail table in the detail block of the generated form.

  • ORA-02266: unique/primary keys in table referenced by enabled foreign keys

    Hi,
    I am trying to delete data from a table by dropping a partition. I have identified all the child tables by running the following command.
    select 'select count(*) from '||table_name||' where employee_id = 100;'
    from 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(*)FROM'||TABLE_NAME||'WHEREEMPLOYEE_ID_ID=100;'
    select count(*) from PT_ORDERS where employee_id = 100;
    select count(*) from PT_DEP where employee_id = 100;
    select count(*) from PT_SKILLSET where employee_id = 100;
    I dropped the partition for employee_id 100 in all of the child tables. The select count(*) returns 0 rows for each of the above.
    When I try to run the below command on the EMPLOYEE table, I get 'ORA-02266: unique/primary keys in table referenced by enabled foreign keys'.
    alter table EMPLOYEE drop partition EMP_ID_100;
    I cant see why I am unable to drop this partition now as there is now child data in any of the referenced tables. Any suggestions or help on this would be greatly appreciated.
    Thanks.
    Rgs,
    Rob

    You should disable foreign key constraints first and drop partition. Deletion of rows or dropping partitions in childs don't work in this case
    as you have the global dependency:
    <PRE>
    SQL> create table scott.t (x int primary key, y int)
    2 partition by list (y) (
    3 partition p_1 values(1), partition p_2 values(2))
    4 /
    Table created.
    SQL> create table scott.t_c (x int references scott.t(x), y int)
    2 partition by list (y) (
    3 partition p_1 values(1), partition p_2 values(2))
    4 /
    Table created.
    SQL> insert into scott.t values(1,1)
    2 /
    1 row created.
    SQL> insert into scott.t values(2,2)
    2 /
    1 row created.
    SQL> insert into scott.t_c values(1,1)
    2 /
    1 row created.
    SQL> insert into scott.t_c values(2,2)
    2 /
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> alter table scott.t_c drop partition p_2;
    Table altered.
    SQL> alter table scott.t drop partition p_2;
    alter table scott.t drop partition p_2
    ERROR at line 1:
    ORA-02266: unique/primary keys in table referenced by enabled 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 table scott.t_c disable constraint SYS_C0011059;
    Table altered.
    SQL> alter table scott.t drop partition p_2;
    Table altered.
    SQL> alter table scott.t_c enable novalidate constraint SYS_C0011059;
    Table altered.
    </PRE>
    I guess you should consider such option as Referencial partitioning (with some restrictions).
    Best wishes,
    Dmitry.

  • Foreign Key Relationship.

    Hi,
    I asked a question in the link below(which I solved).
    https://social.msdn.microsoft.com/Forums/en-US/514a4f48-b1fa-4fe7-bc2b-4c252b34cf50/insertion-of-null-value?forum=vbgeneral
    Here my question is that:
    We make relation of foreign keys to enforce user for accurate data insertion, but sometime we do need null values to be passed to attribute that is used as
    Foreign key. We studied and know that Foreign keys are meant to except null values, which it doesn't(In simple way. I mean when we select an attribute as foreign key and check it to except nulls, then it should.)
    As I explained in the upper link how I solved the problem, if similar problems have to be solved like that then,
    Why we define Foreign Key over there, i mean it could be done without defining the Foreign key?
    If it is necessary in any meaning then why we Enforce Foreign
    Key Constraint as No,
    to except nulls from user?
    What effects does Enforce Foreign Key Constraint as No
    gives to Foreign Key Constraints?
    Thnx in advance.
    Habib Ur Rehman

    Hello Habib,
    I do not think what you are seeing is normal and without having the exact DDL it will be hard to comment.
    I suspect,  you may had "NOT NULL" constraint on the foreign key column. thats why it is not allowing NULLs.
    By definition, Foreign Key maintains(enforces) referential integrity and does allows NULLs. So,  you should be able to enter nulls without having to disable the foreign key enforcement.  
    by setting
    Enforce Foreign Key Constraint to NO, you are effectively disabling the enforcement. you are invalidating the whole purpose of the constraint. 
    The purpose of having that option(disabling foreign key) is to fasten the data load process bypassing the check(extra work) to make sure the value exists in the primary key table when importing large amounts of data.  But to maintain the referential
    integrity you should have that enabled.
    I am not sure without having the ddl, where you did wrong.PLEASE POST YOUR DDL and it should be clear where it went wrong for you. but i hope this script below should help you understand...
    CREATE TABLE [dbo].[Make]([sid] [int] NULL unique,[sname] [varchar](50) NULL)
    go
    CREATE TABLE [dbo].[Make_FK]([sno] [int] NULL unique,[sname] [varchar](50) NULL,[sid] [int] NULL
    CONSTRAINT FK_MAKE FOREIGN KEY (sid) REFERENCES dbo.make (SID))
    insert into make(sid,sname)
    values(1,'sam')
    insert into dbo.Make_FK(sno,sname,sid)
    values(100,'somename',null)
    select * from Make
    --sid is null. SID is the foreig n key referring to sid in MAKE table.
    select * from Make_FK
    Hope it Helps!!

  • Problem creating table with foreign key in SQL Workshop

    Application Express version 2.2.1.00.04
    Get error message "Number of referencing columns/data types must match referenced columns"
    Master table SLS_SUPPLIERS has primary key SLS_ID NUMBER(8,0) and when creating table SLS_PRODUCTS with FK SLS_SLP_ID NUMBER(8,0) using the create table wizard I get the above error.
    The name of the FK is SLP_SLS_FK, key column is SLP_SLS_ID, referenced table is SLS_SUPPLIERS and referenced column is SLS_ID.
    Any help is much appreciated.
    James Edey
    I should add that if I create the table without the foreign key constraint and then create the constraint separately in SQL Workshop then it creates OK. It only fails in the create table wizard dialog.
    Message was edited by:
    edeyje
    Obviously no-one interested in this - just thought it may be a bug in v2.2 that the development team would find useful.
    James
    Message was edited by:
    edeyje

    I replied to the other thread on this too -
    there is a bug on that page when you click Next. If you define more than one fk but then navigate using the links on the process chart on the left (Constraints, Confirm, etc), the page works fine. We do have a bug on this now and I just added the notes I will need to get this fixed in 3.1 (I have already assigned it to me - must have some rogue validation that fires on next).
    Sorry it took so long for this to get noticed - I am glad I checked the forum this morning -
    -- Sharon

  • Select List with Redirect clears Foreign Key

    I have two pages created by the Form wizard, a report and a form, with a Create button on the report page. When the Create button is pressed it passes a Foreign Key item using f?p syntax - stardard code, so far, so good, the form page works fine.
    However, the form contains three Select List items, and the second and third ones need to be restricted by the value of the first one. That is, once they choose an Organization using the first Select List the second Select List should only show Groups that belong to that Organization. To do this, I have chosen the first Select List to be "Select List with Redirect". This does exactly what I want, restricting the values in the second and third items because the LOVs they are based on refer to the value of the first item in their where clauses.
    This works fine when I edit an existing record, and also works if I create a new record but don't touch the value of the first Select List. The problem is that when there is no database record and the first Select List is changed, it wipes out the Foreign Key value that was passed - so the record cannot be saved. The url after redirection shows only a value for the item that was changed, and does not include the value of the Foreign Key item as it did when the Create button was pressed.
    I cannot find anywhere to specify item/value pairs for the redirection url. So I have created a Computation which sets the value of the Foreign Key item and computes it Before Header, After Header or Before Region, etc. It sets the value, and Session State displays the value. Debug shows it being set, too. But the displayed field is empty in the region, and the record cannot be saved because the item has no value!
    Can anyone tell me what I'm missing here? I suspect the processing of the region is overriding the computation. But I can't find a way around this. Any ideas?

    Scott,
    Sorry, my mistake - it's not a database column, and Alternate Source Used is set to "Only...". The problem is still occurring.
    The tables are:
    - Person - list of People
    - Organization - list of Organizations
    - Organization Role - Roles defined for each Organization, has foreign key to Organization
    - Person Role - Assignment of a Person to an Organization Role, has foreign key to Organization Role and also to Person
    I generated a report on Person with a link to a form on the table. When they press the edit icon, the form for the person comes up fine. Then I enable a series of tabs for that person - to edit addresses, phone numbers, etc. and carry the Person ID forward to each page.
    On the Person Roles page, I generated a report that lists the roles that person is assigned to and a form to maintain the assignments. Pressing the edit button goes to the form to maintain the assignment, which works fine.
    There is also a Create button to add a new assignment, which goes to the same form and clears the primary key of this table to create a new record. I also pass the Person ID in the url so that the new record can create the foreign key value to Person.
    Now here's the problem. On the form to create or edit an assignment, there is a Select List to choose the Organization Role record that they are being assigned to. But this can be a long list, with the same role in several organizations, etc. So I want to allow them to first select the Organization, then select Roles in that Organization.
    To do that, I created a new item on the page that is not a database column. It is defined as a Select List on Organization, and they can choose the Organization from the list. Then the select statement for the Organization Role LOV has a where clause that compares Organization ID against the value chosen by the user. To make this work, the page has to be updated when they choose a different Organization, so I made the Organization field a Select List with Redirect.
    When I edit existing role assignments this works fine. As soon as I select a new Organization, the Organization Role Select List is updated and I can choose roles defined for that Organization. But when I create a new record (which passes in the Person ID in the url) and then choose an Organization, the Person ID is wiped out - and the record cannot be saved without this foreign key value.
    After selecting an organization on a new record, the url shows that the page has been called with only the new value of Organization - so the Person ID is lost, because there is no database record to fetch and it is not passed to the page. And I cannot find a way to set the item/value pairs passed to the url when the redirect is performed.
    I am displaying the Person ID for debugging purposes, and see it disappear if I set Display As to "Text", "Display as Text", "Display as Text (based on LOV, does not save state)" or "Display as Text (based on LOV, saves state)". Interestingly, even though the later saves state (I can see it in Session State), it still gets wiped out in the record - presumably because it's a database column and there is no record, and the value is "Always" going to update the session state.
    Another interesting behavior: If I set the Person ID to display as a Select List, it remains. I think this is because I do not allow extra values or nulls, so it displays the first value in the list if there is no value. (I have only created one person so far in my testing, so I can't tell yet for sure if it changes. Will try that.)
    Is this clear? I'm trying to get this application created in my workspace on htmldb.oracle.com (currently it's on my local database) but having problems creating the tables - unable to create initial extents. Hopefully, I'll have it up there soon and you can examine what I'm doing. I'll let you know when it's available.
    Thanks for your help.
    Sam

  • Publish: dropping index when it is used for foreign key constraint enforcement

    Hi,
    I'm trying to update a target schema from a reference database via Publish. Among the changes to apply, there's an index that needs to be dropped. Since it's linked to a foreign key constraint, it cannot be deleted unless the foreign key is temporarily dropped
    (I saw somewhere that disabling the foreign key should be enough but it doesn't seem to work either).
    Since there are other changes to be made on the same table, this foreign key also has to be dropped before the script can delete the table and re-create it. This part of the script is correctly generated. The problem is that this part appears after the 'DROP
    INDEX' instruction.
    So when generating the update script, SSDT tries to drop the index BEFORE dropping the foreign key. And I can't drop the foreign key in my custom pre-deployment script, otherwise the update script would fail when trying to delete it again.
    Shouldn't SSDT be smart enough to drop the constraint before the index? Is it a bug or did I forget to set an option? If it's not a bug, what can I do apart from doing it manually?
    Thank you for your help

    Hi Elsa,
    That sounds like a bug. Could you please file a Connect issue for this at
    https://connect.microsoft.com/SQLServer/feedback/CreateFeedback.aspx using the category "Developer Tools (SSDT, BIDS, etc.)"? We're trying to track all bugs through
    Connect so that you can tell when we have fixed the issue and we can request more information.
    A workaround for this issue might be to write a pre-deployment script for your project to drop the foreign key prior to deployment. A pre-deployment script can be added to your project by right-clicking on the
    project in solution explorer and then clicking on Add > Script... and selecting Pre-Deployment Script from the list.
    Thanks!

  • Foreign keys without ON DELETE CASCADE; Database Design question

    This is the 3rd company i am working, where i see Foreign Keys created without
    ON DELETE CASCADEclause.
    My colleague says that it is created without ON DELETE CASCADE clause in order to make deletion of data (child records) difficult. So, for Purge/Archive codes, before we delete from Parent table we have to delete from the Child table first.
    Occasinaly , something goes wrong and we'll end up disabling all FKs and then do Purging, Archiving, etc..
    So, isn't it better to create Foreign keys with ON DELETE CASCADE clause rather than having all these hassles?
    From you experience, what do you guys think?

    ON DELETE CASCADE is usually not a good idea - something 'magical' happens in the background and rows go away. Instead, consider making the FK DEFERRABLE INITIALLY DEFERRED. That way you can delete the parent and child rows in any sequence and the constraint will not be checked until commit time. You want to use an API (stored procedure/package) to make sure DML is executed in the proper sequence and in the proper way for your business rules.

  • Foreign keys at the table partition level

    Anyone know how to create and / or disable a foreign key at the table partition level? I am using Oracle 11.1.0.7.0. Any help is greatly appreciated.

    Hmmm. I was under the impression that Oracle usually ignores indices on columns with mostly unique and semi-unique values and prefers to do full-table scans instead on the (questionable) theory that it takes almost as much time to find one or more semi-unique entries in an index with a billion unique values as it does to just scan through three billion fields. Though I tend to classify that design choice in the same category as Microsoft's design decision to start swapping ram out to virtual memory on a PC with a gig of ram and 400 megs of unused physical ram on the twisted theory that it's better to make the user wait while it needlessly thrashes the swapfile NOW than to risk being unable to do it later (apparently, a decision that has its roots in the 4-meg win3.1 era and somehow survived all the way to XP).

  • Drop foreign keys and recreate foreign keys with on delete cascade dymanica

    I need to drop foreign keys and recreate foreign keys with on delete cascade dymanically via a script. Does anyone have a script available?

    You could also disable the integrity contraints.
    SET PAGESIZE 0
    SET FEEDBACK OFF
    SET PAUSE OFF
    -- create a disable script
    SPOOL do_disable.sql
    SELECT 'ALTER TABLE '
           || table_name
            || chr(10) ||
           'DISABLE CONSTRAINT '
            || constraint_name
            || ';'
      FROM user_constraints
    WHERE constraint_type = 'R'
       AND status = 'ENABLED'
    select 'alter trigger '
           || trigger_name
            || ' disable;'
      from user_triggers
    where status = 'ENABLED'
    SPOOL OFF
    -- now create a enable script as well
    SPOOL do_enable.sql
    SELECT 'ALTER TABLE '
           || table_name
            || chr(10)
            || 'ENABLE CONSTRAINT '
            || constraint_name
            || ';'
      FROM user_constraints
    WHERE constraint_type = 'R'
       AND status = 'ENABLED'
    SELECT 'ALTER trigger '
           || trigger_name
            || ' ENABLE;'
      FROM user_triggers
    WHERE status = 'ENABLED'
    SPOOL OFF
    SET FEEDBACK ONif you run this script on a TESTdatabase you will end up with a do_disable.sql and a do_enable.sql script on youre local directory.
    Running do disable will disable all the currently enabled triggers and contraints.
    Running do_enable.sql will enable the previously disables triggers and contraints.
    be sure to test before executing this on a real live production database.
    Make sure you have a good backup!

  • Transfer data from one database to another without identities but keep the relation b/w PK and Foreign key

    Hi,
    I need to transfer data from one database to another database (both are identical databases). 
    1. Not transferring identity columns (primary keys). the destination table might have the same key.
    2. keep the PK's and FK's relation b/w parent and child table
    3. I have 4 levels 
    Example: tableA (col1 int identity(1,1) , col2, col3)
    tableB (col1 int identity(1,1) ,
    col2 , col3) -- col2 has the foreign key relation with tableA.col1
    tableC (col1 int identity(1,1) ,
    col2, col3) -- col2  has the foreign key relation with tableB.col1
    tableD (col1 int identity(1,1) , col2, col3) -- col2  has the foreign key relation with tableC.col1
    please advise me.
    Thanks in advance

    Try the below:
    /********************************SAMPLE TARGET***************************************************************/
    Use MSDNSamples
    create table TableA(LevelValueId int identity(1,1) primary key, name varchar(100))
    Insert into TableA(name) Select 'R1'
    Insert into TableA(name) Select 'R2'
    create Table TableB(ChildId int identity(100,1),name varchar(100), LevelValueID int references TableA(LevelValueId))
    Insert into TableB(name,LevelValueID) Select 'Childname1',1
    /********************************SAMPLE TARGET***************************************************************/
    /********************************SAMPLE SOURCE***************************************************************/
    Use Sample
    create table TableA(LevelValueId int identity(1,1) primary key, name varchar(100))
    Insert into TableA(name) Select 'C1'
    Insert into TableA(name) Select 'C2'
    create Table TableB(ChildId int identity(100,1),name varchar(100), LevelValueID int references TableA(LevelValueId))
    Insert into TableB(name,LevelValueID) Select 'Kidname1',1
    /********************************SAMPLE SOURCE***************************************************************/
    USe MSDNSamples
    /********************************MIGRATION INTERMEDIATE TABLE***************************************************************/
    --Migration table
    Create table Mg_TableA(LevelValueId int, NewValueId int)
    /********************************MIGRATION INTERMEDIATE TABLE***************************************************************/
    /********************************ACTUAL MIGRATION FOR MASTER TABLE***************************************************************/
    MERGE INTO TableA
    USING sample.dbo.TableA AS tv
    ON 1 = 0
    WHEN NOT MATCHED THEN
    INSERT(name) Values(tv.name)
    Output tv.levelValueId ,inserted.LevelValueid INTO
    Mg_TableA;
    /********************************ACTUAL MIGRATION FOR MASTER TABLE***************************************************************/
    /********************************ACTUAL MIGRATION FOR CHILD TABLE***************************************************************/
    Insert into TableB (name,LevelValueID)
    Select A.name,B.NewValueId From sample.dbo.TableB A
    Inner join Mg_TableA B on A.LevelValueID = B.LevelValueId
    /********************************ACTUAL MIGRATION FOR CHILD TABLE***************************************************************/
    /********************************TEST THE VALUES***************************************************************/
    Select * From TableA
    Select * From Mg_TableA
    Select * From TableB
    /********************************TEST THE VALUES***************************************************************/
    Drop table TableB,Tablea,Mg_TableA
    Use Sample
    Drop Table TableB,Tablea

  • How can I create a new entry without using LOV for foreign keys.

    Referring to TUHRA sample application based on HR database schema. JDeveloper 10.1.3.0.4
    How can I create a new employee without using LOV for the foreign key "job_id".
    On the first page I would like to choose the job_title from adf read-only table.
    After clicking on the "create new employee button" a creation form appears in which the job_id field is set with previous selection.
    Regards M.Winkler
    Edited by: user3541283 on 06.10.2008 03:44
    Edited by: user3541283 on 06.10.2008 03:50

    Hi,
    usually the foreign key is only set if the VO you select is dependent from a master. If e.g. you have DepartmentsVO1 that has an EmployeeVO3 as its nested VO, then creating a new instance of employees automatically add the foreign key. If you add EmployeesVO1, which is not dependent to DepartmensVO1, then the foreign key is not set. So if this is the case in THURA (keep in mind that this is not an Oracle demo but a sample used in a book about ADF) then all you need is to take the independent VO when building the new employee form.
    Frank

  • Unable to drop foreign key on a version-enabled table

    Hi,
    We're using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit and I'm trying to delete a foreign key from a version-enabled table.
    The constraint shows in ALL_WM_RIC_INFO view. I run exec dbms_wm.beginddl('tablename'), when I inspect the generated <tablename>_LTS I don't see any referential integrity constraints generated on that table ? The constraint i'm trying to delete is from a version-enabled table to a non-version enabled table if that makes a difference.
    From what I understand the referential integrity constraint would be generated and I would be able to run something like:
    ALTER TABLE <tablename>_LTS DROP CONSTRAINT <constraintname>.
    I tried running the above statement using the RIC_NAME from ALL_WM_RIC_INFO view but it fails predictably with:
    ORA-02443: Cannot drop constraint - nonexistent constraint
    Cause: alter table drop constraint <constraint_name>
    Action: make sure you supply correct constraint name.

    as I ran into this today as well I feel like answering this question, as I suppose that the thread opener did the same mistake as I did, and maybe
    some others do it as well :)
    of course you need to open a DDL session on the parent table as well in order to drop foreign key constraints, just as you do when you add them.
    so the correct order to make it work would be:
    EXECUTE DBMS_WM.BeginDDL('PARENT_TABLE');
    EXECUTE DBMS_WM.BeginDDL('CHILD_TABLE');
    ALTER TABLE CHILD_TABLE_LTS
    DROP CONSTRAINT FOREIGN_KEY_NAME
    EXECUTE DBMS_WM.CommitDDL('CHILD_TABLE');
    EXECUTE DBMS_WM.CommitDDL('PARENT_TABLE');I felt kind of stupid that it took me 1 hour to figure this out ;)
    regards,
    Andreas

Maybe you are looking for