Drop parent table

how to drop a parent table???
if there is hundreds of child table,then it is not possible to disable all the Foreign key one by one...

810045 wrote:
how to drop a parent table???
if there is hundreds of child table,then it is not possible to disable all the Foreign key one by one...Why not?
Assuming you need 30 sec to disable a FK manually. And you have like 200 child tables (I doubt that you have that much, but lets just check the maximum amount).
Then you would need like 1 h 40 min of concentrated disableing. I think this is very well possible.

Similar Messages

  • Drop parent table with disabled child constraints?

    I have a table I would like to drop and recreate. I do not want to have to recreate all the foreign key constraints again. Can I disable the foreign key constraints, drop the table and then recreate the table and enable the foreign key constraints?
    Thanks,
    John E.

    No.
    The Triggers,Indexes,Constraints etc, assocated with a table are bound to the table they are defined for.
    They owe their existance to the existance of the table.
    If the table goes, so do the constraints.
    If you have Oracle9i, can use DBMS_METADATA to generate the DDL script of the table before dropping it.

  • Dropping a table gives an error

    When I try to drop a table it gives the following error?
    SQL> drop table FLOWS_010600.SYS_IOT_OVER_55056;
    drop table FLOWS_010600.SYS_IOT_OVER_55056
    ERROR at line 1:
    ORA-25191: cannot reference overflow table of an index-organized table
    what should i do, please help!

    Hi ,
    You cannot refer the overflow table ...
    You have to drop the parent index-organized table containing the specified overflow table...!!!!
    Regards,
    Simon

  • Ora-00600 error when dropping a table

    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    When I tried to drop a table, I got 600 error:
    SQL> desc DEV.ATTR_IDX$EX
    Name Null? Type
    NODE_ID NOT NULL NUMBER
    COL1 NUMBER
    SQL> show user;
    USER is "DEV"
    SQL> select count(*) from DEV.ATTR_IDX$EX;
    COUNT(*)
    0
    SQL> drop table DEV.ATTR_IDX$EX;
    drop table DEV.ATTR_IDX$EX
    ERROR at line 1:
    ORA-00600: internal error code, arguments: [15265], [], [], [], [], [], [], [],
    SQL> drop table DEV.ATTR_IDX$EX purge;
    drop table DEV.ATTR_IDX$EX purge
    ERROR at line 1:
    ORA-00600: internal error code, arguments: [15265], [], [], [], [], [], [], [],
    I guess this is because it had a parent table, which I dropped (I used "drop table <parent_table>", and it did not give me error, very strange).
    SQL> select dbms_metadata.get_ddl('TABLE','ATTR_IDX$EX') from dual;
    DBMS_METADATA.GET_DDL('TABLE','ATTR_IDX$EX')
    CREATE TABLE "DEV"."ATTR_IDX$EX"
    ( "NODE_ID" NUMBER NOT NULL ENABLE,
    "COL1" NUMBER,
    FOREIGN KEY ("NODE_ID")
    REFERENCES () ON DELETE CASCADE ENABLE
    ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"
    MONITORING
    Try to drop FK constraints yields the same error.
    So now how can I drop this table table, any work around?
    Thanks.

    This is a bug. There is no Patch avaialble for this yet. This error is seen where recyclebin is enabled. Possible workaround is to disable the recyclebin.
    This happens with the dictionary corruption due to inconsistency between obj$ and seg$.
    This is a correct answer but still i would suggest to contact Oracle support.

  • How to delete the duplicate rows present in the parent table & insert the latest duplicate record into the parent table linked with the child table.

    I have a master table and i need to import the rows into the parent and child table.
    Master table name is Flatfile_Inventory
    Parent Table name is INVENTORY
    Child Tables name are INVENTORY_AMOUNT,INVENTORY_DETAILS,INVENTORY_VEHICLE,
    Error details will be goes to LOG_INVENTORY_ERROR
    I have 4 duplicate rows in the Flatfile_Inventory which i have already inserted in the Parent and child table.
    Again when i run the query using stored procedure,
    its tells that all the 4 rows are duplicate and will move to the Log_Inventory_Error.
    I need is if i have the duplicate rows in the flatfile_Inventory when i start inserting into the parent and child table the already inserted row have the unique ID i
    must identify it and delete that row in the both parent and chlid table.And latest row must get inserted into the Parent and child table from Flatfile_Inventory.
    Please help me to write the query i have attached the Full stored procedure Script..
    Arunraj Kumar

    Hi Santhosh,
    This is my Script.
    -- =============================================
    -- Stored Procedure for FLATFILE_INVENTORY
    -- =============================================
    -- Drop stored procedure if it already exists
       DROP PROCEDURE SP_Flatfile_Inventory
    GO
    CREATE PROCEDURE SP_Flatfile_Inventory
    AS
    --USE IconicMarketing
    GO
    DECLARE
    @FileType  varchar(50)  ,
    @ACDealerID  varchar(50)  ,
    @ClientDealerID  varchar(50)  ,
    @DMSType  varchar(50)  ,
    @StockNumber  varchar(50)  ,
    @InventoryDate  datetime  ,
    @StockType  varchar(100)  ,
    @DMSStatus  varchar(50)  ,
    @InvoicePrice  numeric(18, 2)  ,
    @CostPack  varchar(50)  ,
    @SalesCost  numeric(18, 2)  ,
    @HoldbackAmount  numeric(18, 2)  ,
    @ListPrice  numeric(18, 2)  ,
    @MSRP  varchar(max)  ,
    @LotLocation  varchar(50)  ,
    @TagLine  varchar(max)  ,
    @Certification  varchar(max)  ,
    @CertificationNumber  varchar(max)  ,
    @VehicleVIN  varchar(50)  ,
    @VehicleYear  bigint  ,
    @VehicleMake  varchar(50)  ,
    @VehicleModel  varchar(50)  ,
    @VehicleModelCode  varchar(50)  ,
    @VehicleTrim  varchar(50)  ,
    @VehicleSubTrimLevel  varchar(max)  ,
    @Classification  varchar(max)  ,
    @TypeCode  varchar(100)  ,
    @VehicleMileage  bigint  ,
    @EngineCylinderCount  bigint  ,
    @TransmissionType  varchar(50)  ,
    @VehicleExteriorColor  varchar(50)  ,
    @VehicleInteriorColor  varchar(50)  ,
    @CreatedDate  datetime  ,
    @LastModifiedDate  datetime  ,
    @ModifiedFlag  varchar(max)  ,
    @InteriorColorCode  varchar(50)  ,
    @ExteriorColorCode  varchar(50)  ,
    @PackageCode  varchar(50)  ,
    @CodedCost  varchar(50)  ,
    @Air  varchar(100)  ,
    @OrderType  varchar(max)  ,
    @AgeDays  bigint  ,
    @OutstandingRO  varchar(50)  ,
    @DlrAccessoryRetail  varchar(50)  ,
    @DlrAccessoryCost  varchar(max)  ,
    @DlrAccessoryDesc  varchar(max)  ,
    @ModelDesc  varchar(50)  ,
    @Memo1  varchar(1000)  ,
    @Memo2  varchar(max)  ,
    @Weight  varchar(max)  ,
    @FloorPlan  numeric(18, 2)  ,
    @Purchaser  varchar(max)  ,
    @PurchasedFrom  varchar(max)  ,
    @InternetPrice  varchar(50)  ,
    @InventoryAcctDollar  numeric(18, 2)  ,
    @VehicleType  varchar(50)  ,
    @DealerAccessoryCode  varchar(50)  ,
    @AllInventoryAcctDollar  numeric(18, 2)  ,
    @BestPrice  varchar(50)  ,
    @InStock  bigint  ,
    @AccountingMake  varchar(50)  ,
    @GasDiesel  varchar(max)  ,
    @BookValue  varchar(10)  ,
    @FactoryAccessoryDescription  varchar(max)  ,
    @TotalReturn  varchar(10)  ,
    @TotalCost  varchar(10)  ,
    @SS  varchar(max)  ,
    @VehicleBody  varchar(max)  ,
    @StandardEquipment  varchar(max)  ,
    @Account  varchar(max)  ,
    @CalculatedPrice  varchar(10)  ,
    @OriginalCost  varchar(10)  ,
    @AccessoryCore  varchar(10)  ,
    @OtherDollar  varchar(10)  ,
    @PrimaryBookValue  varchar(10)  ,
    @AmountDue  varchar(10)  ,
    @LicenseFee  varchar(10)  ,
    @ICompany  varchar(max)  ,
    @InvenAcct  varchar(max)  ,
    @Field23  varchar(max)  ,
    @Field24  varchar(max)  ,
    @SalesCode  varchar(max)  ,
    @BaseRetail  varchar(10)  ,
    @BaseInvAmt  varchar(10)  ,
    @CommPrice  varchar(10)  ,
    @Price1  varchar(10)  ,
    @Price2  varchar(10)  ,
    @StickerPrice  varchar(10)  ,
    @TotInvAmt  varchar(10)  ,
    @OptRetail  varchar(max)  ,
    @OptInvAmt  varchar(10)  ,
    @OptCost  varchar(10)  ,
    @Options  varchar(max)  ,
    @Category  varchar(max)  ,
    @Description  varchar(max)  ,
    @Engine  varchar(max)  ,
    @ModelType  varchar(max)  ,
    @FTCode  varchar(max)  ,
    @Wholesale  varchar(max)  ,
    @Retail  varchar(max)  ,
    @Draft  varchar(max)  ,
    @Inventoryid int;
    DECLARE Inventory_Cursor CURSOR FOR 
    SELECT * from [dbo].[FLATFILE_INVENTORY];
    OPEN Inventory_Cursor
    FETCH NEXT FROM Inventory_Cursor 
    INTO @FileType   ,
    @ACDealerID     ,
    @ClientDealerID     ,
    @DMSType     ,
    @StockNumber     ,
    @InventoryDate    ,
    @StockType    ,
    @DMSStatus     ,
    @InvoicePrice     ,
    @CostPack     ,
    @SalesCost     ,
    @HoldbackAmount     ,
    @ListPrice     ,
    @MSRP     ,
    @LotLocation     ,
    @TagLine     ,
    @Certification     ,
    @CertificationNumber     ,
    @VehicleVIN     ,
    @VehicleYear     ,
    @VehicleMake     ,
    @VehicleModel     ,
    @VehicleModelCode     ,
    @VehicleTrim     ,
    @VehicleSubTrimLevel     ,
    @Classification     ,
    @TypeCode    ,
    @VehicleMileage     ,
    @EngineCylinderCount     ,
    @TransmissionType     ,
    @VehicleExteriorColor     ,
    @VehicleInteriorColor     ,
    @CreatedDate    ,
    @LastModifiedDate    ,
    @ModifiedFlag     ,
    @InteriorColorCode     ,
    @ExteriorColorCode     ,
    @PackageCode     ,
    @CodedCost     ,
    @Air    ,
    @OrderType     ,
    @AgeDays     ,
    @OutstandingRO     ,
    @DlrAccessoryRetail     ,
    @DlrAccessoryCost     ,
    @DlrAccessoryDesc     ,
    @ModelDesc     ,
    @Memo1 ,
    @Memo2     ,
    @Weight     ,
    @FloorPlan     ,
    @Purchaser     ,
    @PurchasedFrom     ,
    @InternetPrice     ,
    @InventoryAcctDollar     ,
    @VehicleType     ,
    @DealerAccessoryCode     ,
    @AllInventoryAcctDollar     ,
    @BestPrice     ,
    @InStock     ,
    @AccountingMake     ,
    @GasDiesel     ,
    @BookValue     ,
    @FactoryAccessoryDescription     ,
    @TotalReturn     ,
    @TotalCost     ,
    @SS     ,
    @VehicleBody     ,
    @StandardEquipment     ,
    @Account     ,
    @CalculatedPrice     ,
    @OriginalCost     ,
    @AccessoryCore     ,
    @OtherDollar     ,
    @PrimaryBookValue     ,
    @AmountDue     ,
    @LicenseFee     ,
    @ICompany     ,
    @InvenAcct     ,
    @Field23     ,
    @Field24     ,
    @SalesCode     ,
    @BaseRetail     ,
    @BaseInvAmt     ,
    @CommPrice     ,
    @Price1     ,
    @Price2     ,
    @StickerPrice     ,
    @TotInvAmt     ,
    @OptRetail     ,
    @OptInvAmt     ,
    @OptCost     ,
    @Options     ,
    @Category     ,
    @Description     ,
    @Engine     ,
    @ModelType     ,
    @FTCode     ,
    @Wholesale     ,
    @Retail     ,
    @Draft     ;
    WHILE @@FETCH_STATUS = 0
    BEGIN
        PRINT @VehicleVIN    ;
    -- ****************** insert into Inventory Table ***********
    INSERT INTO INVENTORY 
    IconicDealerID,
    StockNumber,
    DMSType,
    InventoryDate
    VALUES (@ClientDealerID,@StockNumber,@DMSType,@InventoryDate);
    set @Inventoryid = scope_identity();
    PRINT @Inventoryid;
    --Insert into Inventory_Details Table
    INSERT INTO [INVENTORY_DETAILS]
    InventoryID,
    StockType,
    DMSStatus,
    LotLocation,
    TagLine,
    Certification,
    CertificationNumber,
    CreatedDate,
    LastModifiedDate,
    ModifiedFlag,
    PackageCode,
    OrderType,
    AgeDays,
    OutstandingRO,
    Memo1,
    Memo2,
    Purchaser,
    PurchasedFrom,
    DealerAccessoryCode,
    InStock,
    AccountingMake,
    SS,
    Account,
    AccessoryCore,
    ICompany,
    InvenAcct,
    Field23,
    Field24,
    SalesCode,
    Draft,
    FTCode
    VALUES (
    @InventoryID,
    @StockType,
    @DMSStatus,
    @LotLocation,
    @TagLine,
    @Certification,
    @CertificationNumber,
    @CreatedDate,
    @LastModifiedDate,
    @ModifiedFlag,
    @PackageCode,
    @OrderType,
    @AgeDays,
    @OutstandingRO,
    @Memo1,
    @Memo2,
    @Purchaser,
    @PurchasedFrom,
    @DealerAccessoryCode,
    @InStock,
    @AccountingMake,
    @SS,
    @Account,
    @AccessoryCore,
    @ICompany,
    @InvenAcct,
    @Field23,
    @Field24,
    @SalesCode,
    @Draft,
    @FTCode
    --Insert into Inventory_Amount Table
    INSERT INTO [dbo].[INVENTORY_AMOUNT]
    InventoryID,
    AllInventoryAcctDollar,
    OtherDollar,
    PrimaryBookValue,
    AmountDue,
    LicenseFee,
    CalculatedPrice,
    OriginalCost,
    BookValue,
    TotalReturn,
    TotalCost,
    DlrAccessoryRetail,
    DlrAccessoryCost,
    DlrAccessoryDesc,
    InternetPrice,
    InventoryAcctDollar,
    BestPrice,
    Weight,
    FloorPlan,
    CodedCost,
    InvoicePrice,
    CostPack,
    SalesCost,
    HoldbackAmount,
    ListPrice,
    MSRP,
    BaseRetail,
    BaseInvAmt,
    CommPrice,
    Price1,
    Price2,
    StickerPrice,
    TotInvAmt,
    OptRetail,
    OptInvAmt,
    OptCost,
    Wholesale,
    Retail
    VALUES (
    @InventoryID,
    @AllInventoryAcctDollar,
    @OtherDollar,
    @PrimaryBookValue,
    @AmountDue,
    @LicenseFee,
    @CalculatedPrice,
    @OriginalCost,
    @BookValue,
    @TotalReturn,
    @TotalCost,
    @DlrAccessoryRetail,
    @DlrAccessoryCost,
    @DlrAccessoryDesc,
    @InternetPrice,
    @InventoryAcctDollar,
    @BestPrice,
    @Weight,
    @FloorPlan,
    @CodedCost,
    @InvoicePrice,
    @CostPack,
    @SalesCost,
    @HoldbackAmount,
    @ListPrice,
    @MSRP,
    @BaseRetail,
    @BaseInvAmt,
    @CommPrice,
    @Price1,
    @Price2,
    @StickerPrice,
    @TotInvAmt,
    @OptRetail,
    @OptInvAmt,
    @OptCost,
    @Wholesale,
    @Retail
    --Insert into Inventory_Vehicle Table
    INSERT INTO [dbo].[INVENTORY_VEHICLE]
    InventoryID,
    InteriorColorCode,
    ExteriorColorCode,
    Air,
    ModelDesc,
    VehicleType,
    VehicleVIN,
    VehicleYear,
    VehicleMake,
    VehicleModel,
    VehicleModelCode,
    VehicleTrim,
    VehicleSubTrimLevel,
    Classification,
    TypeCode,
    VehicleMileage
    VALUES (
    @InventoryID,
    @InteriorColorCode,
    @ExteriorColorCode,
    @Air,
    @ModelDesc,
    @VehicleType,
    @VehicleVIN,
    @VehicleYear,
    @VehicleMake,
    @VehicleModel,
    @VehicleModelCode,
    @VehicleTrim,
    @VehicleSubTrimLevel,
    @Classification,
    @TypeCode,
    @VehicleMileage
    -- Move cursor to Next record 
        FETCH NEXT FROM Inventory_Cursor 
    INTO @FileType   ,
    @ACDealerID     ,
    @ClientDealerID     ,
    @DMSType     ,
    @StockNumber     ,
    @InventoryDate    ,
    @StockType    ,
    @DMSStatus     ,
    @InvoicePrice     ,
    @CostPack     ,
    @SalesCost     ,
    @HoldbackAmount     ,
    @ListPrice     ,
    @MSRP     ,
    @LotLocation     ,
    @TagLine     ,
    @Certification     ,
    @CertificationNumber     ,
    @VehicleVIN     ,
    @VehicleYear     ,
    @VehicleMake     ,
    @VehicleModel     ,
    @VehicleModelCode     ,
    @VehicleTrim     ,
    @VehicleSubTrimLevel     ,
    @Classification     ,
    @TypeCode    ,
    @VehicleMileage     ,
    @EngineCylinderCount     ,
    @TransmissionType     ,
    @VehicleExteriorColor     ,
    @VehicleInteriorColor     ,
    @CreatedDate    ,
    @LastModifiedDate    ,
    @ModifiedFlag     ,
    @InteriorColorCode     ,
    @ExteriorColorCode     ,
    @PackageCode     ,
    @CodedCost     ,
    @Air    ,
    @OrderType     ,
    @AgeDays     ,
    @OutstandingRO     ,
    @DlrAccessoryRetail     ,
    @DlrAccessoryCost     ,
    @DlrAccessoryDesc     ,
    @ModelDesc     ,
    @Memo1 ,
    @Memo2     ,
    @Weight     ,
    @FloorPlan     ,
    @Purchaser     ,
    @PurchasedFrom     ,
    @InternetPrice     ,
    @InventoryAcctDollar     ,
    @VehicleType     ,
    @DealerAccessoryCode     ,
    @AllInventoryAcctDollar     ,
    @BestPrice     ,
    @InStock     ,
    @AccountingMake     ,
    @GasDiesel     ,
    @BookValue     ,
    @FactoryAccessoryDescription     ,
    @TotalReturn     ,
    @TotalCost     ,
    @SS     ,
    @VehicleBody     ,
    @StandardEquipment     ,
    @Account     ,
    @CalculatedPrice     ,
    @OriginalCost     ,
    @AccessoryCore     ,
    @OtherDollar     ,
    @PrimaryBookValue     ,
    @AmountDue     ,
    @LicenseFee     ,
    @ICompany     ,
    @InvenAcct     ,
    @Field23     ,
    @Field24     ,
    @SalesCode     ,
    @BaseRetail     ,
    @BaseInvAmt     ,
    @CommPrice     ,
    @Price1     ,
    @Price2     ,
    @StickerPrice     ,
    @TotInvAmt     ,
    @OptRetail     ,
    @OptInvAmt     ,
    @OptCost     ,
    @Options     ,
    @Category     ,
    @Description     ,
    @Engine     ,
    @ModelType     ,
    @FTCode     ,
    @Wholesale     ,
    @Retail     ,
    @Draft     ;
    END 
    CLOSE Inventory_Cursor;
    DEALLOCATE Inventory_Cursor;
    GO
    SET ANSI_PADDING OFF
    GO
    Arunraj Kumar

  • SQL Server 2012 Management Studio:In the Database, how to print out or export the old 3 dbo Tables that were created manually and they have a relationship for 1 Parent table and 2 Child tables?How to handle this relationship in creating a new XML Schema?

    Hi all,
    Long time ago, I manually created a Database (APGriMMRP) and 3 Tables (dbo.Table_1_XYcoordinates, dbo.Table_2_Soil, and dbo.Table_3_Water) in my SQL Server 2012 Management Studio (SSMS2012). The dbo.Table_1_XYcoordinates has the following columns: file_id,
    Pt_ID, X, Y, Z, sample_id, Boring. The dbo.Table_2_Soil has the following columns: Boring, sample_date, sample_id, Unit, Arsenic, Chromium, Lead. The dbo.Table_3_Water has the following columns: Boring, sample_date, sample_id, Unit, Benzene, Ethylbenzene,
    Pyrene. The dbo.Table_1_XYcoordinates is a Parent Table. The dbo.Table_2_Soil and the dbo.Table_3_Water are 2 Child Tables. The sample_id is key link for the relationship between the Parent Table and the Child Tables.
    Problem #1) How can I print out or export these 3 dbo Tables?
    Problem #2) If I right-click on the dbo Table, I see "Start PowerShell" and click on it. I get the following error messages: Warning: Failed to load the 'SQLAS' extension: An exception occurred in SMO while trying to manage a service. 
    --> Failed to retrieve data for this request. --> Invalid class.  Warning: Could not obtain SQL Server Service information. An attemp to connect to WMI on 'NAB-WK-02657306' failed with the following error: An exception occurred in SMO while trying
    to manage a service. --> Failed to retrieve data for this request. --> Invalid class.  .... PS SQLSERVER:\SQL\NAB-WK-02657306\SQLEXPRESS\Databases\APGriMMRP\Table_1_XYcoordinates>   What causes this set of error messages? How can
    I get this problem fixed in my PC that is an end user of the Windows 7 LAN System? Note: I don't have the regular version of Microsoft Visual Studio 2012 in my PC. I just have the Microsoft 2012 Shell (Integrated) program in my PC.
    Problem #3: I plan to create an XML Schema Collection in the "APGriMMRP" database for the Parent Table and the Child Tables. How can I handle the relationship between the Parent Table and the Child Table in the XML Schema Collection?
    Problem #4: I plan to extract some results/data from the Parent Table and the Child Table by using XQuery. What kind of JOIN (Left or Right JOIN) should I use in the XQuerying?
    Please kindly help, answer my questions, and advise me how to resolve these 4 problems.
    Thanks in advance,
    Scott Chang    

    In the future, I would recommend you to post your questions one by one, and to the appropriate forum. Of your questions it is really only #3 that fits into this forum. (And that is the one I will not answer, because I have worked very little with XSD.)
    1) Not sure what you mean with "print" or "export", but when you right-click a database, you can select Tasks from the context menu and in this submenu you find "Export data".
    2) I don't know why you get that error, but any particular reason you want to run PowerShell?
    4) If you have tables, you query them with SQL, not XQuery. XQuery is when you query XML documents, but left and right joins are SQL things. There are no joins in XQuery.
    As for left/right join, notice that these two are equivalent:
    SELECT ...
    FROM   a LEFT JOIN b ON a.col = b.col
    SELECT ...
    FROM   b RIGHT JOIN a ON a.col = b.col
    But please never use RIGHT JOIN - it gives me a headache!
    There is nothing that says that you should use any of the other. In fact, if you are returning rows from parent and child, I would expect an inner join, unless you want to cater for parents without children.
    Here is an example where you can study the different join types and how they behave:
    CREATE TABLE apple (a int         NOT NULL PRIMARY KEY,
                        b varchar(23) NOT NULL)
    INSERT apple(a, b)
       VALUES(1, 'Granny Smith'),
             (2, 'Gloster'),
             (4, 'Ingrid-Marie'),
             (5, 'Milenga')
    CREATE TABLE orange(c int        NOT NULL PRIMARY KEY,
                        d varchar(23) NOT NULL)
    INSERT orange(c, d)
       VALUES(1, 'Agent'),
             (3, 'Netherlands'),
             (4, 'Revolution')
    SELECT a, b, c, d
    FROM   apple
    CROSS  JOIN orange
    SELECT a, b, c, d
    FROM   apple
    INNER  JOIN orange ON apple.a = orange.c
    SELECT a, b, c, d
    FROM   apple
    LEFT   OUTER JOIN orange ON apple.a = orange.c
    SELECT a, b, c, d
    FROM   apple
    RIGHT  OUTER JOIN orange ON apple.a = orange.c
    SELECT a, b, c, d
    FROM   apple
    FULL OUTER JOIN orange ON apple.a = orange.c
    go
    DROP TABLE apple, orange
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Deleting a row from parent table

    Dear Guru's
    I am having two table with parent - child relationship. My problem is when I am deleting a row from parent table the curresponding child row from child table also should be deleted.
    My Primary table 'Employee, EMPID Primary key
    Child table 'Privilage' inthis EMPID referencing the EMPID of Employee table
    My need is when I am deleting a row from parent table the curresponding child row from child table also should be deleted
    I issued the SQL query like,
    delete from employee where empid='12345' cascade constraints;
    Then it showing me error like,
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    Please resolve my issue , Its Top urgent
    Thanks & Cheers
    Antony

    Choosing How Foreign Keys Enforce Referential Integrity
    Oracle Database allows different types of referential integrity actions to be enforced, as specified with the definition of a FOREIGN KEY constraint:
    Prevent Delete or Update of Parent Key The default setting prevents the deletion or update of a parent key if there is a row in the child table that references the key. For example:
    CREATE TABLE Emp_tab ( 
    FOREIGN KEY (Deptno) REFERENCES Dept_tab);Delete Child Rows When Parent Key Deleted The ON DELETE CASCADE action allows parent key data that is referenced from the child table to be deleted, but not updated. When data in the parent key is deleted, all rows in the child table that depend on the deleted parent key values are also deleted. To specify this referential action, include the ON DELETE CASCADE option in the definition of the FOREIGN KEY constraint. For example:
    CREATE TABLE Emp_tab (
        FOREIGN KEY (Deptno) REFERENCES Dept_tab 
            ON DELETE CASCADE); Set Foreign Keys to Null When Parent Key Deleted The ON DELETE SET NULL action allows data that references the parent key to be deleted, but not updated. When referenced data in the parent key is deleted, all rows in the child table that depend on those parent key values have their foreign keys set to null. To specify this referential action, include the ON DELETE SET NULL option in the definition of the FOREIGN KEY constraint. For example:
    CREATE TABLE Emp_tab (
        FOREIGN KEY (Deptno) REFERENCES Dept_tab 
            ON DELETE SET NULL);
    SQL> conn scott/tiger
    Connected.
    SQL> create table ppk ( no number primary key);
    Table created.
    SQL> begin for inn in 1..10 loop insert into ppk values (inn); end loop; end;
    PL/SQL procedure successfully completed.
    SQL> create table ffk ( no number references ppk(no));
    Table created.
    SQL> begin for inn in 1..10 loop insert into ffk values (inn); end loop; end;
    PL/SQL procedure successfully completed.
    SQL> drop table ppk cascade constraints;
    Table dropped.Message was edited by:
    user52
    Message was edited by:
    user52
    Message was edited by:
    user52

  • How to delete parent table data even though it has child records

    hi all,
    How to delete parent table data even though it has child records.
    ex: delete from pa_request cascade constraints;
    But this command is not working .
    Regards,
    P Prakash

    833560 wrote:
    ex: delete from pa_request cascade constraints;cascade constraints is DROP table option. It can't be used with DELETE. You need to delete child rows first or drop foreign keys and recreate them with ON DELETE CASCADE. Then:
    delete from pa_request will automatically delete child rows. However, personally I don't like ON DELETE CASCADE. You can, by mistake, delete half of your database without even realizing it.
    SY.

  • Sql server partition parent table and reference not partition child table

     
    Hi,
    I have two tables in SQL Server 2008 R2, Parent and Child Table.  
    Parent has date time, and it is partitioned monthly,  there is a Child table which just refer the Parent table using Foreign key relation.   
    is there any problem the non-partitioned child table referring to a partitioned parent table?
    Thanks,
    Areef

    The tables will need to be offline for the operation. "Offline" here, means that you wrap the entire operation in a transaction. Ideally, this transaction would:
    1) Drop the foreign key.
    2) Use ALTER TABLE SWITCH to drop the old data.
    3) Use ALTER PARTITION FUNCTION to drop the old empty partition.
    4) Use ALTER PARTITION FUNCTION to add a new empty partition.
    5) Reapply the foreign keys WITH CHECK.
    All but the last operation are metadata-only operation (provided that you do them right). To perform the last operation, SQL Server must scan the child tbale and verify that all keys are present in the parent table. This can take some time for larger tables.
    During the transaction, SQL Server holds Sch-M locks on the table, which means that are entirely inaccessible, even for queries running with NOLOCK.
    You avoid this the scan by applying the fkey constraint WITH NOCHECK, but this can have impact on query plans, as SQL Server will not consider the constraint as trusted.
    An alternative which should not be entirely dismissed is to use partitioned
    views instead. With partitioned views, the foreign keys are not an issue, because each partition is a pair of tables, with its own local fkey.
    As for the second question: it appears to be completely pointless to partition the parent, but not the child table. Or does the child table only have rows for a smaller set of the rows in the parent?
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Can't delete from parent table if FK constraint on the out-of-line table

    Using Oracle XML DB 11g
    I am using out-of-line storage table to store a collection of XML elements in conjuction with storeVarrayAsTable="true". So what I have is a parent table containing a nested table of VARRAY of REFs to rows in the out-of-line table.
    In addition, I have a foreign key constraint placed on a column in the out-of-line table.
    My problem is that I am not able to delete rows from the parent table when the FK constraint is placed on the out-of-line table. Only when I drop the FK constraint does the deletion work - all associated rows in the nested table and out-of-line table
    gets deleted correctly.
    With the FK constraint, deleting the child document like this
    dbms_xdb.deleteResource('/project-1.xml')
    gives me this error:
    ORA-31018: Error deleting XML document
    ORA-03001: unimplemented feature
    *Cause:  The XMLType object pointed to by the given REF could not
    be deleted because either the REF was invalid or it pointed to a non-existent table.
         *Action:  Either use FORCE deletion or supply a valid REF.
    I have tried deleting with the FORCE options as well with no success.
    Using DBMS_XDB.DELETE_RECURSIVE_FORCE option doesn't produce an error, but doesn't perform the deletion either.
    Here is the XML Schema:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xlink="http://www.w3.org/1999/xlink"
    elementFormDefault="qualified" attributeFormDefault="unqualified" xdb:storeVarrayAsTable="true">
    <xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="http://www.w3.org/1999/xlink.xsd"/>
    <xs:element name="project" xdb:defaultTable="PROJECT_TAB">
    <xs:complexType xdb:SQLType="PROJECT_TYP">
    <xs:sequence>
    <xs:element name="resourceList" minOccurs="0" xdb:SQLName="RESOURCE_LIST">
    <xs:complexType xdb:SQLType="RESOURCE_LIST_TYP">
    <xs:sequence>
    <xs:element name="aResource" type="refType" minOccurs="0" maxOccurs="unbounded" xdb:SQLInline="false"
    xdb:SQLName="A_RESOURCE_REF" xdb:defaultTable="RESOURCE_REF_TAB"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    <xs:attribute name="aguid" type="xs:string" use="required" xdb:SQLName="AGUID"/>
    </xs:complexType>
    </xs:element>
    <xs:element name="aResource" xdb:defaultTable="A_RESOURCE_TAB">
    <xs:complexType xdb:SQLType="A_RESOURCE_TYP">
    <xs:complexContent>
    <xs:extension base="contactType">
    <xs:attribute name="aguid" type="xs:string" use="required" xdb:SQLName="AGUID"/>
    </xs:extension>
    </xs:complexContent>
    </xs:complexType>
    </xs:element>
    <xs:complexType name="contactType" xdb:SQLType="CONTACT_TYP">
    <xs:sequence>
    <xs:element name="name" type="xs:string" xdb:SQLName="NAME"/>
    <xs:element name="email" type="xs:string" minOccurs="0" xdb:SQLName="EMAIL"/>
    <xs:element name="phone" type="xs:string" xdb:SQLName="PHONE"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="refType" xdb:SQLType="REF_TYP">
    <xs:attribute ref="xlink:href" use="required"/>
    <xs:attribute name="oref" type="xs:string" use="optional" xdb:SQLName="OREF"/>
    </xs:complexType>
    </xs:schema>
    I registered the schema using structured storage with these options:
    BEGIN
    DBMS_XMLSCHEMA.registerschema(
    SCHEMAURL => 'LSDProjects.xsd',
    SCHEMADOC => xdbURIType('/home/LSDProject2/LSDProjects.xsd').getClob(),
    LOCAL => TRUE, -- local
    GENTYPES => TRUE, -- generate object types
    GENBEAN => FALSE, -- no java beans
    GENTABLES => TRUE -- generate object tables
    END;
    The PK and FK constraints were added like this:
    -- Add PK constraints on aResource/@aguid attributes
    ALTER TABLE A_RESOURCE_TAB ADD CONSTRAINT A_RESOURCE_AGUID_IS_UNIQUE UNIQUE (XMLDATA."AGUID");
    -- Add FK constraint on out-of-line table
    ALTER TABLE RESOURCE_REF_TAB
    ADD (CONSTRAINT ref_resource_aguid_is_valid FOREIGN KEY (XMLDATA."OREF")
    REFERENCES A_RESOURCE_TAB(XMLDATA."AGUID"));
    Here are the XML instance documents:
         where resource-1.xml looks like this :
    <aResource aguid="resource-1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="LSDProjects.xsd">
         <name>Jane Doe</name>
         <email>[email protected]</email>
    <phone/>
    </aResource>
         and project-1.xml looks like this :
         <project aguid="project-1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="LSDProjects.xsd"
                   xmlns:xlink="http://www.w3.org/1999/xlink">               
              <resourceList>
                   <aResource xlink:href="/resource-1.xml" oref="resource-1"/>                         
              </resourceList>     
         </project>
    where <project> document contains a collection of <aResource> elements stored in the out-of-line table and
    project/@oref attribute is a foreign key to the primary aResource/@aguid attribute.
    Can someone shed some light on why I am unable to delete "project-1.xml" from the repository when the FK constraint is applied onto the out-of-line table.
    Any advice/suggestions would be appreciated. Thanks!

    Thank you for the quick reply, mdrake.
    I am currently prototyping and testing out (best) ways to achieve data integrity with XML data in XML DB.
    I have instance documents that makes cross references to values in other instance documents
    (not of the same root nodes). What I'm trying to enforce is a referential constraint between the documents
    so that a document cannot be inserted if the referenced document doesn't exists.
    In this situation, a <project> document contains a collection of elements with @oref attributes.
    The collection is stored in an out-of-line table.
    For example:
    <project>
    <resourceList>
    <aResource ... oref="resource-1"/>
    <aResource ... oref="resource-2"/>
    </resourceList>
    </project>
    The @oref (FK) attribute above references a @aguid (PK) attribute in <aResource> document (below):
    <aResource aguid="resource-1"> .... </aResource>
    Basically, I want to ensure that the value of
    /project/resourceList/aResource/@oref
    correspond to a valid
    /aResource/@aguid
    Note that I was able to add the FK constraint on the OOL table without any issues.
    And the constraint did work as expected as I was not allowed to insert a <project> document
    that referenced a non-existent /aResource/@aguid.
    The problem was that I could not delete the <project> document from the XML DB repository
    once the FK contraint was added. Deleting with the DELETE_RECURSIVE_FORCE option did not give
    me any errors - is just didn't do anything.
    I guess there are certain limitations with using out-of-line tables.
    BTW, sorry the examples are hard to read as the indentations are removed when posting.

  • Deleting records from child to parent table

    I have ran into a situation where i will have to delete all the records of the child table and then the records of parent table and i was able to write a query to get the column,table both for parent,child and stuck up in deleting them using query and
    i will not be able to use Cascade...My validation criteria is applicable for the child tables and parent table...am trying to compare last modified date of each table...Kindly help me with an approach
    DECLARE @mytable VARCHAR(30) SET @mytable = 'tablea'
    DECLARE @Order INT SET @Order = 0
    DECLARE @Count INT
    declare @tblname varchar(100),@query NVARCHAR(max),@parent varchar(100)
    if OBJECT_ID('tempdb..#OrderList','U') is not null
    DROP TABLE #OrderList
    if OBJECT_ID('tempdb..#temp','U') is not null
    DROP TABLE #temp
    CREATE TABLE #TEMP
    OrderNo INT,
    TableName VARCHAR(50),
    tid varchar(100),
    childtable varchar(100),
    cid varchar(100)
    CREATE TABLE #OrderList
    RecordNo INT,
    OrderNo INT,
    TableName VARCHAR(50),
    tid varchar(100),
    childtable varchar(100),
    cid varchar(100)
    create table #t
    taname varchar(100)
    ;with tempcte (level,parent,pcol,child,ccol)
    as
    SELECT 0,SO2.name, SC2.name,SO1.name, SC1.name
    FROM dbo.sysforeignkeys FK
    INNER JOIN dbo.syscolumns SC1
    ON FK.fkeyid = SC1.id AND FK.fkey = SC1.colid
    INNER JOIN dbo.syscolumns SC2
    ON FK.rkeyid = SC2.id AND FK.rkey = SC2.colid
    INNER JOIN dbo.sysobjects SO1
    ON FK.fkeyid = SO1.id
    INNER JOIN dbo.sysobjects SO2
    ON FK.rkeyid = SO2.id
    INNER JOIN dbo.sysobjects FO
    ON FK.constid = FO.id
    WHERE SO2.Name = 'tablea'
    union all
    SELECT level+1,SO2.name, SC2.name,SO1.name, SC1.name
    FROM dbo.sysforeignkeys FK
    INNER JOIN dbo.syscolumns SC1
    ON FK.fkeyid = SC1.id AND FK.fkey = SC1.colid
    INNER JOIN dbo.syscolumns SC2
    ON FK.rkeyid = SC2.id AND FK.rkey = SC2.colid
    INNER JOIN dbo.sysobjects SO1
    ON FK.fkeyid = SO1.id
    INNER JOIN dbo.sysobjects SO2
    ON FK.rkeyid = SO2.id
    INNER JOIN dbo.sysobjects FO
    ON FK.constid = FO.id
    inner join tempcte t
    on SO2.Name = t.child
    insert into #TEMP
    OrderNo,
    TableName,
    tid,
    childtable,
    cid
    select
    level,parent,pcol,child,ccol from tempcte
    select * from #TEMP
    INSERT INTO #OrderList
    SELECT Row_number() OVER (ORDER BY OrderNo, TableName),
    #TEMP.OrderNo,
    #TEMP.TableName,
    #TEMP.tid,
    #temp.childtable,
    #TEMP.cid
    FROM #TEMP
    SET @Count = (SELECT Max(RecordNo)
    FROM #OrderList)
    select * from #OrderList

    Am looking for a logic to delete the records..Please provide some query to better understand..
    Thats easy, refer the below link: You may check string and then execute if everything looks ok to you.
    Ref:http://social.msdn.microsoft.com/Forums/en-US/bc36c6b6-1aca-43aa-bc95-7518fdb6fe4c/delete-data-from-multiple-tables?forum=transactsql
    declare @Deletecommand varchar(max)
    ;with object_cte(tblid,tblname,rtblid,rtblname,level)
    as
    select distinct o.object_id as tblid,OBJECT_NAME(o.object_id) as tblname,cast(null as int),cast(null as sysname),
    0 as level
    from sys.objects o
    inner join sys.foreign_keys f
    on f.parent_object_id = o.object_id
    where o.is_ms_shipped=0
    and o.type='u' and OBJECT_NAME(o.object_id) like '/BIO/A%'
    union all
    select t.object_id as tblid,OBJECT_NAME(t.object_id) as tblname,o.tblid,o.tblname,o.level + 1
    from object_cte o
    inner join sys.foreign_keys f
    on f.parent_object_id = o.tblid
    join sys.objects t
    on t.object_id = f.referenced_object_id
    where t.is_ms_shipped=0
    and t.type='u'
    and OBJECT_NAME(o.object_id) like '/BIO/A%'
    select @Deletecommand =(select 'DELETE FROM ' + tblname + ';' from
    select row_Number() over (partition by tblname order by level) as rn,* from object_cte
    )t
    where rn=1
    order by level
    for xml path(''))
    print @Deletecommand
    --exec (@Deletecommand)

  • Why is the FK parent table read

    0
    SQL Server 2012 Enterprise. I have two tables with a FK relationship. The referencing column in the child table is NOT NULL. The FK is trusted. I create a view that joins the two tables with an INNER JOIN on the foreign key column and no filter. When I SELECT
    COUNT(*) from the view, it returns the count of rows in the child table (as expected), but looking at actual execution plan, it reads the parent table to do so. I see no reason to read from the parent table. The trusted FK on a NOT NULL column in the
    child table means that for every row in the child table there HAS to be a corresponding row in the parent table, so reading the parent table should be unnecessary. If I change the view's join to an OUTER JOIN, the parent table is not read with a SELECT COUNT(*)
    from the view. Is this a shortcoming in the optimizer (not really a bug), or am I missing something? Here's an example:
    USE tempdb;
    GO
    IF OBJECT_ID('dbo.vChild') IS NOT NULL DROP VIEW dbo.vChild;
    IF OBJECT_ID('dbo.Child') IS NOT NULL DROP TABLE dbo.Child;
    IF OBJECT_ID('dbo.Parent') IS NOT NULL DROP TABLE dbo.Parent;
    CREATE TABLE dbo.Parent (PKey int NOT NULL PRIMARY KEY,
     SomeCol varchar(10) NOT NULL);
    GO
    CREATE TABLE dbo.Child (PKey int NOT NULL,
     SeqNum int NOT NULL,
     CONSTRAINT ChildPK PRIMARY KEY (PKey, SeqNum));
    ALTER TABLE dbo.Child WITH CHECK ADD CONSTRAINT FK_Parent_Child FOREIGN KEY(PKey)
     REFERENCES dbo.Parent (PKey);
    GO
    select is_not_trusted, * from sys.foreign_keys
     WHERE [name] = 'FK_Parent_Child';
    GO
    CREATE VIEW dbo.vChild AS
    SELECT C.PKey, C.SeqNum, P.SomeCol
     FROM dbo.Child AS C
     JOIN dbo.Parent AS P
      ON C.PKey = P.PKey
    GO
    SELECT COUNT(*) FROM dbo.vChild;
    Thanks, Vern
    Vern Rabe

    I got the same plan as you and I am running SP1 and CU4. I've installed CU4 because of another bug
    Confusing error message
    Here is my plan as a text:
    StmtText
      |--Compute Scalar(DEFINE:([Expr1004]=CONVERT_IMPLICIT(int,[Expr1007],0)))
           |--Stream Aggregate(DEFINE:([Expr1007]=Count(*)))
                |--Nested Loops(Inner Join, OUTER REFERENCES:([C].[PKey]))
                     |--Clustered Index Scan(OBJECT:([tempdb].[dbo].[Child].[ChildPK] AS [C]))
                     |--Clustered Index Seek(OBJECT:([tempdb].[dbo].[Parent].[PK__Parent__5E190D18084EC2A6] AS [P]), SEEK:([P].[PKey]=[tempdb].[dbo].[Child].[PKey] as [C].[PKey]) ORDERED FORWARD)
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • ORA 2266 -- Drop parent partition with no child records exists

    Hi Team ,
    Here I have a parent partitioned table and child refrenced non-partition table .
    To drop parent partition I am doing
    1)delete from child
    2)delete from parent partition
    3)alter table drop parent partition
    ---and its working fine .
    I am trying to do below which is not working , Could you please guide me why it is not
    1)delete from child
    2)alter table drop parent partition -- throwing below error
    Summarizing ,
    Why I am not able to drop/trunc a parent partition(no corresponding rows exists in child tables) where as able to do after deleting the rows from parent partition .
    From Doc :
    Error: ORA 2266
    Text: table has some unique/primary keys that are referenced by some foreign k
    eys
    Cause: Attempt to drop the table while the table still has some unique/
    primary keys that are referenced by some foreign keys.
    Action: Remove all such references to the keys before dropping the table
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE     11.2.0.2.0     Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    Oracle decides what the rules are & you must conform to them
    bcm@bcm-laptop:~$ oerr ora 2266
    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";

  • Error while dropping a table

    Hi All,
    i got an error while dropping a table which is
    ORA-00600: internal error code, arguments: [kghstack_free1], [kntgmvm: collst], [], [], [], [], [], [], [], [], [], []
    i know learnt that -600 error is related to dba. now how to proceed.
    thanks and regards,
    sri ram.

    00600 errors should be raised as service request with Oracle as it implies some internal bug.
    You can search oracle support first to see if anyone has had the same class of 00600 error, and then if not (and therefore no patch) raise your issue with Oracle.
    http://support.oracle.com

  • Ora-00604,ora-01422 error while dropping the table

    Hi gurus,
    I am using Oracle 10g R2 on windows 2000 platform,while dropping the table the following error occured.
    ORA-00604 : error occurred at recursive sql level 1.
    ORA-01422: exact fetch returns more than requested number of rows.
    Need urgent help.
    Thanks in advance

    Is there an AFTER EVENT trigger defined on this database? Can you check that?
    Secondly, was this database migrated from earlier version? I remember having seen this problem on 9i (it was 9.2.0.1 or 9.2.0.2; I can't recall exactly).

Maybe you are looking for