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

Similar Messages

  • Foreign Key Constraint Failure on Self-Referencing Table

    In a recent data deletion project, I ran into a problem where Oracle allowed for a record (the parent) to be deleted when there still existed a child record in the same table which referred to the parent.
    An abbreviated version of the table is as follows:
    create table test (
    template_id number not null,
    customer_id number null,
    parent_id number null,
    constraint pk_test primary key (template_id),
    constraint r_parent foreign key (parent_id) references test (template_id));
    The parent and child records are as follows:
    Parent: template_id = 100, customer_id = 200, parent_id = null
    Child: template_id = 101, customer_id = null, parent_id = 100
    Records were deleted from this table using:
    DELETE FROM test WHERE customer_id = 200;
    When this statement is executed, is it being executed as part of 155 delete statements using PL/SQL, and tens of thousands of records from 155 tables are being deleted. These delete statements have been ordered taking into account foreign key constraints. All 155 statements are being deleted in a single transaction. The delete statement above was the 23rd statement of the set to be executed. I would have expected when this delete statement was executed, an error would have been thrown. However, all 155 delete statements successfully complete, and after committing the results, the child record above still exists in the DB as an orphan. I also tried executing the first 23 statements manually in SQL*Plus (still one transaction), and the problem still occurs: the parent is deleted and the child is orphaned.
    If I execute the very simple example above, I do indeed get an referential constraint error.
    Has anyone ever encountered this situation? And does anyone have any ideas how to go about troubleshooting this problem. We need to know the cause of this, as we have a small handful of table with a similar self-referential foreign key constraint set-up.
    Thank you very much in advance,
    Mark

    First of all, the very simple example that I outlined above I have already tried and it worked: when I attempted to delete the parent a referential integrity error was thrown as one would expect. This small example was my test case to see if I could reproduce what I'm seeing in our application in a more manageable and demonstrable example. But as it worked, I'm still perplexed in reconciling the differences between what I'm seeing in our application (which I can't demonstrate in this help group) and the test case. When I used the test case in my first posting in this thread, I used it to help describe the problem I'm encountered, even though that small example works.
    Below is more of the table you've asked for.
    OWNER           CONSTRAINT_NAME          CONSTRAINT_TYPE     TABLE_NAME     SEARCH_CONDITION     R_OWNER            R_CONSTRAINT_NAME     DELETE_RULE     STATUS          DEFERRABLE            DEFERRED         VALIDATED     GENERATED     BAD     RELY     LAST_CHANGE           INDEX_OWNER  INDEX_NAME       INVALID     VIEW_RELATED
    "DOCPADMIN"     "R_TEMPLATE_PARENT"     "R"             "DCR_TEMPLATE"      (null)                  "DOCPADMIN"     "XPKDCR_TEMPLATE"     "NO ACTION"  "ENABLED"   "NOT DEFERRABLE"    "IMMEDIATE"  "VALIDATED"      "USER NAME"     (null)     (null)     "2010-01-13 19:01:21"     (null)        (null)         (null)       (null)
    "DOCPADMIN"     "XPKDCR_TEMPLATE"       "P"             "DCR_TEMPLATE"      (null)                       (null)     (null)                      (null)          "ENABLED"     "NOT DEFERRABLE"    "IMMEDIATE"      "VALIDATED"     "USER NAME"     (null)     (null)     "2010-01-13 15:48:31"     (null)     "XPKDCR_TEMPLATE"   (null)     (null)Overall, I haven't said that Oracle's FK mechanism is broken. What I've said is that I've got a situation that I'm trying to understand. My first attempt at my test case didn't work because the test case worked as it should. I'm trying to figure out another course of action to try and figure this situation out.

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

  • Generated Script fails when attempting to drop Foreign Key Constraint

    I made some changes to my database.  I used the generate script process to generate a drop and create script to these tables.  The generated script first ran Alter Table Drop Constraints to drop the Foreign Key constraints and then did Drop tables
    and then did create table to construct the script with the proper changes.
    However, when we attempted to run the script, all of the Drop constraint statements failed reporting that there was no such constraint.  Then the drop table scripts failed because of the existence of the very foreign key constraints  that SQL Server
    had just stated did not exist.
    BOL states that the statement "DROP { [ CONSTRAINT ] constraint_name | COLUMN column_name } " is  "Used in a CHECK, FOREIGN KEY, UNIQUE, or PRIMARY KEY constraint."  So why couldn't I drop those specified Foreign
    Key constraints in a script generated by SQL Server itself.
    Edward R. Joell MCSD MCDBA

    Are you sure there are no Constraints on other tables which are causing your issue?
    If a foreign key from table abc refences table def it will cause the drop to fail.
    If your script is already attempting to drop such constraints, have you checked that they are dropping from the correct table (and not the table that would be the target of the drop)?
    I discovered two things yesterday and one thing today about generated scripts.
    When you generated a script to drop and create a set of tables and you mark it to include foreign keys, the generated script will first create a set a scripts to drop the foreign keys , then will create a set of statements for each table that will,
    first, again drop the same foreign keys that it did earlier, then drop the table.  If there is no "if exists" statement for each statement, the drop constraint will fail.
    The script generated by the generate scripts wizard, even when you set the Drop and Create option in the advanced tab, unlike the scripts generated when you right click a table and select Drop and Create from the context menu, does not by default create
    an "If Exists" statement before the attempt to drop anything.
    You can make the generate Scripts wizard generate an "if exists" statement by changing the "Include if NOT EXISTS" option on the advanced tab to true. However, while the script generator will find all of the foreign keys that show that
    table as the parent_id, it will not show the FK constraints on tables which are not being dropped and created.  Nor can you find them by querying the sys.foreign_keys view using the standard type of Foreign Key "If Exists" statement because
    it would do a query like
    SELECT *
    FROM sys.foreign_keys
    WHERE object_id = OBJECT_ID(N'[dbo].[FK_prc_ContractSubLines_prc_PRSubLines]')
    AND parent_object_id = OBJECT_ID(N'[dbo].[prc_ContractSubLines]')
    And the script generator does not care even if you show an option like "Generate Scripts For Dependent Objects", it will not generate a drop script for the foreign constraints on other tables that reference your table.  I have not even found
    a way to get back the results of a query on the sys.foreign_keys view that will show those keys that reference your table. The only thing I been able to do is to open the table in design and check out the list of relationships in your table and see open each
    relationship and see which table is the "foreign key table" rather than the primary key table. This will make writing drop and create scripts very very long and tedious. As you would have to  create addional Alter tables scripts to do a drop
    and create foreign keys on each table referencing yours and manually place them into your scripts at correct locations. This is almost as bad as the Oracle SQL Developer's generate script results which (at least in 2010) so screws up the order of the generated
    script that it is trying to create foreign keys on tables it has not created yet.
    So Patrick I see that you thought about the foreign keys on other tables.  I wish I had read your post before spending the morning troubleshooting this issue based on this morning's script that ran and crashed embarrassingly. 
    I would like to know if someone has a query to reveal all of the foreign keys that reference your table from another table using the sys views.  As it is I have to open each table in design to get a list of FKs that reference it.
    Edward R. Joell MCSD MCDBA

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

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

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

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

  • Using FOreign key constraints on tables in database.

    I am student and novice in the field of ORACLE and PL/SQL and Database Creation. I had created a database consisting tables and got problem while applying foreign key constraints.
    CUST_MSTR
    CREATE TABLE "DBA_BANKSYS"."CUST_MSTR"("CUST_NO" VARCHAR2(10),
    "FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25), "LNAME" VARCHAR2(25),
    "DOB_INC" DATE NOT NULL,      "OCCUP" VARCHAR2(25), "PHOTOGRAPH" VARCHAR2(25),
    "SIGNATURE" VARCHAR2(25), "PANCOPY" VARCHAR2(1),      "FORM60" VARCHAR2(1));
    (CUST_NO is PRIMARY KEY, )
    -- EMP_MSTR
    CREATE TABLE "DBA_BANKSYS"."EMP_MSTR"("EMP_NO" VARCHAR2(10),
    "BRANCH_NO" VARCHAR2(10), "FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25),
    "LNAME" VARCHAR2(25), "DEPT" VARCHAR2(30), "DESIG" VARCHAR2(30));
    (EMP_NO is primary key )
    --NOMINEE_MSTR
    CREATE TABLE "DBA_BANKSYS"."NOMINEE_MSTR"("NOMINEE_NO" VARCHAR2(10),
    "ACCT_FD_NO" VARCHAR2(10), "NAME" VARCHAR2(75), "DOB" DATE,
    RELATIONSHIP" VARCHAR2(25));
    (NOMINEE_NO is primary key )
    --ADDR_DTLS
    CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
    "CODE_NO" VARCHAR2(10),      "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
    "ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
    "PINCODE" VARCHAR2(6));
    ( ADDR_NO is primary key )
    Problem: I want to apply foreign key constraints on ADDR_DTLS table so that Before inserting value in ADDR_DTLS table it must check, VALUE in ADDR_DTLS.CODE_NO must be PRESENT either in attribute value CUST_MSTR.CODE_NO or EMP_MSTR.CODE_NO or NOMINEE_MSTR.CODE_NO table .
    I applied the foreign key constraints using this syntax
    CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
    "CODE_NO" VARCHAR2(10),      "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
    "ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
    "PINCODE" VARCHAR2(6),
    constraints fk_add foreign key CODE_NO references CUST_MSTR. CODE_NO,
    constraints fk_add1 foreign key CODE_NO references EMP_MSTR. CODE_NO,
    constraints fk_add2 foreign key CODE_NO references NOMINEE_MSTR.CODE_NO);
    (foreign key)
    ADDR_DTLS.CODE_NO ->CUST_MSTR.CUST_NO
    ADDR_DTLS.CODE_NO ->NOMINEE_MSTR.NOMINEE_NO
    ADDR_DTLS.CODE_NO ->BRANCH_MSTR.BRANCH_NO
    ADDR_DTLS.CODE_NO ->EMP_MSTR.EMP_NO
    When I applied foreign key constraints this way, its gives a error called foreign key constraints violation. (I understand that, its searches the attribute value of ADDR_DTLS.CODE_NO in all the three tables must be present then the value will be inserted. But I want, if the value is in any of the three table then its should insert the value or its gives an error.)
    Please help me out, though i put the question and i want too know how to apply the forign key in this way. and is there any other option if foreign key implementation is not pssible.

    If you are on 11g you can use ON DELETE SET NULL:
    CREATE TABLE addr_dtls
    ( addr_no          NUMBER(6)  CONSTRAINT addr_pk PRIMARY KEY
    , addr_cust_no     CONSTRAINT addr_cust_fk    REFERENCES cust_mstr    ON DELETE SET NULL
    , addr_emp_no      CONSTRAINT addr_emp_fk     REFERENCES emp_mstr     ON DELETE SET NULL
    , addr_nominee_no  CONSTRAINT addr_nominee_fk REFERENCES nominee_mstr ON DELETE SET NULL
    , addr_type        VARCHAR2(1)
    , addr1            VARCHAR2(50)
    , addr2            VARCHAR2(50)
    , city             VARCHAR2(25)
    , state            VARCHAR2(25)
    , pincode          VARCHAR2(6) );In earlier versions you'll need to code some application logic to do something similar when a parent row is deleted, as otherwise the only options are to delete the dependent rows or raise an error.
    btw table names can be up to 30 characters and don't need to end with MSTR or DTLS, so for example CUSTOMERS and ADDRESSES might be more readable than CUST_MSTR and ADDR_DTLS. Also if the Customer/Employee/Nominee PKs are generated from a sequence they should be numeric.
    Edited by: William Robertson on Aug 15, 2010 6:47 PM

  • Import table data in right order to avoid violating foreign key constraints

    Gentlemen
    I am trying to import table data into an existing 10g schema using datapump import in table mode.
    However, in order to avoid violating foreign key constraints, the tables must be loaded in a specified order. I tried specifying the order in the TABLES parameter:
    TABLES=table1,table2,table3 etc.
    However, datapump seems to chose its own order leading to errors like the following:
    ORA-31693: Table data object "SCHEMAX"."TABLE3" failed to load/unload and is being skipped due to error:
    ORA-02291: integrity constraint (SCHEMAX.TABLE3_TABLE1#FK) violated - parent key not found
    I want to try to avoid having to disable all foreign keys because there are hundreds of them.
    Any advice?
    Yours
    Claus Jacobsen, Denmark

    Thanks Anantha.
    Since I am only loadding data (the constraints are already defined in the target database), I am not sure whether this approach would work. Meanwhile I have solved the problem of moving data from one system to another using another, tedious and far from elegant approach that I would prefer to not eloborate on:-)
    However, I have also discovered another probable reason why the foreign key constraints were violated, other than wrong order of table data loading. It turns out almost every single table in the schema contains a trigger supposed to generate a unique row ID from a sequence on insert such as:
    CREATE OR REPLACE TRIGGER "SCHEMAX"."TABLEX#B_I_R"
    BEFORE INSERT
    ON TABLEX
    FOR EACH ROW
    DECLARE
    BEGIN
    SELECT tablex_seq.nextval INTO :NEW.ID FROM dual;
    END;
    If the import mechanism fires this trigger, and the sequences in the source and the target systems are not synchronized, then I guess that referred records a more than likely to end up with wrong ID's compared to the row ID's in the referring rows?
    Spooky. Anybody can confirm this theory?
    Yours
    Claus
    Message was edited by:
    user586249

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

  • Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths

    I am trying to introduce a constraint on the sales_details table
    ALTER TABLE [dbo].[SALES_DETAILS] WITH CHECK ADD constraint fk_sd_vat FOREIGN KEY([VAT])
    REFERENCES [dbo].[VAT Rate] ([VAT]) on update cascade on delete cascade
    GO
    I am getting the error saying
    Msg 1785, Level 16, State 0, Line 1
    Introducing FOREIGN KEY constraint 'fk_sd_vat' on table 'SALES_DETAILS' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
    Msg 1750, Level 16, State 0, Line 1
    Could not create constraint. See previous errors.
    What could be the reason,Please suggest me the solution for  this,
    Thanks,

    Hi Erland,
    This is my DDl
    CREATE TABLE [dbo].sales_details(
    [BNUM] [varchar](20) NOT NULL,
    [CNAME] [varchar](30) NOT NULL,
    [CNUM] [int] NOT NULL FOREIGN KEY([CNUM])REFERENCES [dbo].[Customer] ([CNum]),
    [ITNAME] [varchar](100) NOT NULL,
    [ITEM#] [int] NOT NULL ,
    [QTY] [int] NOT NULL,
    [UNIT] [varchar](5) NOT NULL,
    [PRICE] [float] NOT NULL,
    [BASIC] [float] NOT NULL,
    [DISCOUNT] [float] NOT NULL,
    [FRQTY] [int] NOT NULL,
    [BADDR] [varchar](300) NULL,
    [CADDR] [varchar](300) NOT NULL,
    [BDATE] [datetime] NOT NULL,
    [VAT] [float] NOT NULL
    ALTER TABLE [dbo].[SALES_DETAILS] WITH CHECK ADD constraint cons1 FOREIGN KEY([ITNAME])
    REFERENCES [dbo].[New Item] ([Item Description]) on cascade update
    GO
    ALTER TABLE [dbo].[SALES_DETAILS] WITH CHECK ADD constraint FOREIGN KEY([VAT])
    REFERENCES [dbo].[VAT Rate] ([VAT]) on cascade update
    GO
    I am getting the error when i execute second Alter statement.
    Thanks,
    Check if VAT Rate table has any FK with cascaded options?
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Is this a BUG???  Database Export not including Foreign Key Constraints

    I'm using SQL Developer 1.5.4 with both the 59.47 and 59.59 patches installed. I want to do a database export from a 10g XE schema, and include all objects in the resulting DDL. So, I select ALL the checkboxes in the export wizard and when I get to Step 3 to specify objects, I don't see any of my constraints in the listbox... no foreign key constraints, no primary key constraints, no check constraints, nothing. Is this a bug, or is there a workaround, or what could I possibly be doing wrong? We want to be able to use the database export feature to easily transport and track modifications to our entire schema using source control compare.
    Any help or alternate suggestions would be apprieciated.
    Thanks,
    Matt

    Thanks skutz, we just figured that out this morning. Also, it should be noted that you need to be logged in as the owner of the schema otherwise selecting nothing in the filter will give you nothing, but selecting items in the filter will give you those items even if you're not connected as the schema owner. I wonder if that is the detail of the Bug 8679318.
    Edited by: mattsnyder on Jul 14, 2009 9:24 AM

  • Query the name of the parent table in a foreign key constraint

    Hello,
    Does anyone know how to query for the parent table name in a foreign key constraint? I don't see that relationship in ALL_CONS_COLUMNS or ALL_CONSTRAINTS.
    Thanks in advance,
    Michael

    or try this...
    SELECT rc.TABLE_NAME "PK_Table_Name",cc.TABLE_NAME "FK_Table_Name",
           case when cc.column_name = rc.column_name
                then c.TABLE_NAME || '(' || cc.COLUMN_NAME || ')'
                else r.TABLE_NAME || '(' || rc.COLUMN_NAME || ') = ' ||c.TABLE_NAME || '(' || cc.COLUMN_NAME || ')' end as "TABLE_NAME(COLUMN_NAME)"
    from all_constraints c,
         all_constraints r,
         all_cons_columns cc,
         all_cons_columns rc
    WHERE
         r.table_name = upper('emp')
    and      c.CONSTRAINT_TYPE = 'R'
    and     c.R_OWNER = r.OWNER
    and     c.R_CONSTRAINT_NAME = r.CONSTRAINT_NAME
    and     c.CONSTRAINT_NAME = cc.CONSTRAINT_NAME
    and     c.OWNER = cc.OWNER
    and     r.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
    and     r.OWNER = rc.OWNER
    and     cc.POSITION = rc.POSITION
    ORDER BY r.TABLE_NAME;

  • Foreign key constraint on multi-column primary key accepts 1 empty column!?

    Hi, we have a reference table with a two-column primary key. In the child table there is a non-mandatory foreign key constraint to this table. So if both child columns are null it's ok too. But now we see that if one of the two child table columns that build up the foreign key is null, the other column can have any (non-existant in the master-tabel) value you like!? That does not make sense.
    Can anyone explain this to me???
    Regards, Paul.

    Paul, I believe that this is in accordance to the ANSI SQL standard requirement for the treatment of nulls in a multi-column FK. In any case Oracle specifically states this is the way FK work From the 10 Concepts manual, Ch 21 Data Integrity, topic Nulls and Foreign Keys:
    The relational model permits the value of foreign keys either to match the referenced primary or unique key value, or be null. If any column of a composite foreign key is null, then the non-null portions of the key do not have to match any corresponding portion of a parent key. <<HTH -- Mark D Powell --

Maybe you are looking for