Foreign Key Error script Generation

here is
CREATE table script
create table employee_history
(empl_id_hist number,
empl_name varchar2(20)
alter table employee_history
add constraint emp_TO_empHIST foreign key (empl_id_hist)
references employee (empl_id);
Create table employee
(empl_id number,
ename varchar2(20));
some empl_id_hist values not in Master table employee.
now Foreign Key disabled.
for checking not valid empl_id_hist ids
I am trying to generate a script like this using Dynamic SQL.
select unique empl_id_hist from employee_history
where empl_id_hist not in (select empl_id from employee);
but i am getting same Column empl_id_hist (instead of empl_id ) in Subquery too
i.e
select unique EMPL_ID_HIST from employee_history
where EMPL_ID_HIST not in (select EMPL_ID_HIST from employee);
DECLARE
CNT NUMBER := 0;
V_SQL_STR VARCHAR2(255);
v_col_name VARCHAR2(255);
v_ind CHAR(1);
v_sql_where VARCHAR2(255);
CURSOR C1 IS
SELECT DECODE(c.position, 1, b.table_name, ' ') MASTER_TAB,
DECODE(c.position, 1, a.table_name, ' ') CHILD_TAB,
DECODE(c.position, 1, a.constraint_name, ' ') constraint_name,
c.column_name colname
from dba_constraints a,dba_constraints b, dba_cons_columns c
where a.status = 'DISABLED'
AND a.constraint_type = 'R'
AND a.constraint_name = c.constraint_name
and a.r_constraint_name = b.constraint_name (+)
order by b.table_name, a.table_name, c.position;
CURSOR c2(cons_name VARCHAR2) IS
SELECT column_name FROM User_Cons_Columns
WHERE constraint_name = cons_name
ORDER BY column_name;
BEGIN
FOR R1 IN C1 LOOP
v_col_name := '';
BEGIN
FOR r2 IN c2(r1.constraint_name) LOOP
cnt := cnt + 1;
IF cnt <= 1 THEN
V_ind := 'y';
V_SQL_sTR := 'SELECT UNIQUE A.'||R1.colname ||' FROM ' ||R1.CHILD_TAB ||' A' || chr(10);
V_SQL_STR := V_SQL_STR ||'WHERE A.'||R1.colname ||' NOT IN ';
V_SQL_STR := V_SQL_STR || '(SELECT B.'|| R1.colname ||' FROM ' || R1.MASTER_TAB ||' B);' ||chr(10);
V_COL_NAME := V_COL_NAME || R2.COLUMN_NAME ||',';
v_Sql_where := 'WHERE A.'||R2.COLUMN_NAME ||' = B.' || R2.COLUMN_NAME ||chr(10);
ELSE
v_ind := 'n';
v_Sql_where := v_Sql_where || 'AND A.'||R2.COLUMN_NAME ||' = B.' || R2.COLUMN_NAME ||chr(10);
V_COL_NAME := V_COL_NAME || R2.COLUMN_NAME ||',';
END IF;
END LOOP;
v_sql_where := v_sql_where ||');';
cnt := 0;
END;
IF v_ind = 'y' THEN
DBMS_OUTPUT.PUT_LINE(V_SQL_sTR);
ELSIF v_ind = 'n' THEN
v_sql_str := '';
v_col_name := SUBSTR(v_col_name,1,LENGTH(v_col_name) - 1) || '';
V_SQL_STR := 'SELECT UNIQUE '|| V_COL_NAME ;
V_SQL_STR := V_SQL_STR || ' FROM ' || R1.CHILD_TAB || ' A'|| CHR(10);
V_SQL_STR := V_SQL_STR || 'WHERE NOT EXISTS ( '||CHR(10);
V_SQL_STR := V_SQL_STR || 'SELECT 1 FROM ' ||R1.MASTER_TAB ||' B';
DBMS_OUTPUT.PUT_LINE(V_SQL_STR);
DBMS_OUTPUT.PUT_LINE(V_SQL_WHERE);
DBMS_OUTPUT.PUT_LINE('');
END IF;
v_ind := '';
END LOOP;
END;
thanks in advance

That's because with this cursor
CURSOR c2(cons_name VARCHAR2) IS
SELECT column_name FROM User_Cons_Columns
WHERE constraint_name = cons_name
ORDER BY column_name;You assume that the column names are the same in both tables. You will need to read from user_cons_columns twice, once with the fk constraint name, once with the pk constraint name.
SQL> create table parent (id number constraint parent_pk primary key) ;
Table cr&eacute;&eacute;e.
SQL> create table child (child_id number,
  2                      constraint child_fk1 foreign key (child_id)
  3                      references parent (id)
  4                     ) ;
Table cr&eacute;&eacute;e.
SQL> select
  2     a.column_name as parent_column_name,
  3     b.column_name as child_column_name
  4   from
  5     user_cons_columns a, user_cons_columns b
  6   where
  7     a.constraint_name = 'PARENT_PK'
  8     and b.constraint_name = 'CHILD_FK1'
  9     and a.position = b.position
10   order by
11     a.position ;
PARENT_COLUMN_NAME             CHILD_COLUMN_NAME
ID                             CHILD_ID

Similar Messages

  • EJB-QL (foreign key)- error

    hi everyone. i am stuck, cheked everything and don't know where to look. i hope someone will help me. i use websphere 5.0
    i have 2 cmp entity ejb with one-many relationship between them. I wrote QL query using foriegn key. when i generate EJB-RDB mapping the error appears in TASK saying " myTable o does not have a field myforeignkey". when i click on tast it opens ejb dep...descriptor. i check descriptor and foreign key is there.
    where should i look? when i run validation before mapping generation it doesn't produce any error.

    i am new to J2ee and i let websphere to generate all description code. I spend 4 hours looking for this error and i just can'f fix it. it looks fine to me. can you have a look? i know the code is big. if you get extra time then help me. i cut it down. there is two entity beans each with one attribute. order id has second attribute as foreign key -generatorhome_id.
    the full error is like this:
    WQRY0036E:OrderId o does not have a field generatorhome_id. when i click on it takes me to my created <query-method> findByFor
    please help if have time. the code should be straight forward. if you want me to simplify code so you can better understand then let me know.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar id="ejb-jar_ID">
         <display-name>EJB</display-name>
         <enterprise-beans>
              <entity id="OrderId">
                   <ejb-name>OrderId</ejb-name>
                   <local-home>com.ibm.pbw.ejb.OrderIdLocalHome</local-home>
                   <local>com.ibm.pbw.ejb.OrderIdLocal</local>
                   <ejb-class>com.ibm.pbw.ejb.OrderIdBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>com.ibm.pbw.ejb.OrderIdKey</prim-key-class>
                   <reentrant>False</reentrant>
                   <cmp-version>2.x</cmp-version>
                   <abstract-schema-name>OrderId</abstract-schema-name>
                   <cmp-field id="CMPAttribute_1088406971782">
                        <field-name>ind</field-name>
                   </cmp-field>
                   <cmp-field>
                        <description>Generated to support relationships. Do NOT delete.</description>
                        <field-name>generatorhome_id</field-name>
                   </cmp-field>
                   <ejb-local-ref id="EJBLocalRef_1088406284143">
                        <ejb-ref-name>ejb/GeneratorHome</ejb-ref-name>
                        <ejb-ref-type>Entity</ejb-ref-type>
                        <local-home>com.ibm.pbw.ejb.GeneratorHomeLocalHome</local-home>
                        <local>com.ibm.pbw.ejb.GeneratorHomeLocal</local>
                        <ejb-link>GeneratorHome</ejb-link>
                   </ejb-local-ref>
                   <query>
                        <description></description>
                        <query-method>
                             <method-name>findByFor</method-name>
                             <method-params>
                                  <method-param>int</method-param>
                             </method-params>
                        </query-method>
                        <ejb-ql>select object(o) from OrderId o where o.generatorhome_id = ?1</ejb-ql>
                   </query>
              </entity>
              <entity id="GeneratorHome">
                   <ejb-name>GeneratorHome</ejb-name>
                   <local-home>com.ibm.pbw.ejb.GeneratorHomeLocalHome</local-home>
                   <local>com.ibm.pbw.ejb.GeneratorHomeLocal</local>
                   <ejb-class>com.ibm.pbw.ejb.GeneratorHomeBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>com.ibm.pbw.ejb.GeneratorHomeKey</prim-key-class>
                   <reentrant>False</reentrant>
                   <cmp-version>2.x</cmp-version>
                   <abstract-schema-name>GeneratorHome</abstract-schema-name>
                   <cmp-field id="CMPAttribute_1088406971792">
                        <field-name>id</field-name>
                   </cmp-field>
                   <ejb-local-ref id="EJBLocalRef_1088406284153">
                        <ejb-ref-name>ejb/OrderId</ejb-ref-name>
                        <ejb-ref-type>Entity</ejb-ref-type>
                        <local-home>com.ibm.pbw.ejb.OrderIdLocalHome</local-home>
                        <local>com.ibm.pbw.ejb.OrderIdLocal</local>
                        <ejb-link>OrderId</ejb-link>
                   </ejb-local-ref>
              </entity>
         </enterprise-beans>
         <relationships>
              <ejb-relation>
                   <description></description>
                   <ejb-relation-name>GeneratorHome-OrderId</ejb-relation-name>
                   <ejb-relationship-role id="EJBRelationshipRole_1088406971782">
                        <ejb-relationship-role-name>generatorhome</ejb-relationship-role-name>
                        <multiplicity>Many</multiplicity>
                        <relationship-role-source>
                             <ejb-name>OrderId</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                             <cmr-field-name>generatorhome</cmr-field-name>
                        </cmr-field>
                   </ejb-relationship-role>
                   <ejb-relationship-role id="EJBRelationshipRole_1088406971783">
                        <ejb-relationship-role-name>orderid</ejb-relationship-role-name>
                        <multiplicity>One</multiplicity>
                        <relationship-role-source>
                             <ejb-name>GeneratorHome</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                             <cmr-field-name>orderid</cmr-field-name>
                             <cmr-field-type>java.util.Collection</cmr-field-type>
                        </cmr-field>
                   </ejb-relationship-role>
              </ejb-relation>
         </relationships>
    </ejb-jar>

  • Foreign key errors in sql plus

    Hello, im pretty new to sql and i am stuck on a project in my database management class and i was wondering if anyone can help us out. I don't know if it would be easier to send what i've done or just post the error so if anyone could help it will be appreciated.
    This is one part of the sql
    CREATE TABLE PREREQUISITE_T
         (COURSECODE                VARCHAR2(10)NOT NULL,
         PREREQUISITECODE          VARCHAR2(20),
    PRIMARY KEY (COURSECODE),
    PRIMARY KEY (PREREQUISITECODE),
    FOREIGN KEY (COURSECODE) REFERENCES COURSE_T(COURSECODE),
    FOREIGN KEY (PREREQUISITECODE));
    INSERT INTO PREREQUISITE_T VALUES ('23131', '3213');
    INSERT INTO PREREQUISITE_T VALUES ('23541', '4213');
    INSERT INTO PREREQUISITE_T VALUES ('23251', '3413');
    INSERT INTO PREREQUISITE_T VALUES ('56131', '3513');
    INSERT INTO PREREQUISITE_T VALUES ('75431', '3613');
    INSERT INTO PREREQUISITE_T VALUES ('45631', '3813');
    INSERT INTO PREREQUISITE_T VALUES ('65461', '3913');
    INSERT INTO PREREQUISITE_T VALUES ('45351', '5413');
    the error i get is
    ERROR at line 1:
    ORA-02298: cannot validate (STUDENT.SYS_C003016) - parent keys not found
    It works fine without the primary keys but when i put in foreign keys it is all messed up. If there a a tutorial or anyone could take a look at the rest of the code i can send it out. Any help is appreciated.

    probably u had given the column value not exists in the reference table.
    see the example
    create table tst(x number ,y number);
    alter table tst add constraints pk_x primary key(x);
    create table tst1(x number, y number);
    alter table tst1 add constraints fk_x foreign key(x) references tst(x);
    SQL> insert into tst values(&x,&y);
    Enter value for x: 1
    Enter value for y: 2
    old 1: insert into tst values(&x,&y)
    new 1: insert into tst values(1,2)
    1 row created.
    SQL> /
    Enter value for x: 2
    Enter value for y: 3
    old 1: insert into tst values(&x,&y)
    new 1: insert into tst values(2,3)
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> insert into tst1 values(&x,&y);
    Enter value for x: 2
    Enter value for y: 1
    old 1: insert into tst1 values(&x,&y)
    new 1: insert into tst1 values(2,1)
    1 row created.
    SQL> /
    Enter value for x: 5
    Enter value for y: 6
    old 1: insert into tst1 values(&x,&y)
    new 1: insert into tst1 values(5,6)
    insert into tst1 values(5,6)
    ERROR at line 1:
    ORA-02291: integrity constraint (SHFLDEV.FK_X) violated - parent key not found

  • Bug: no constraints/foreign keys when Scripter.Prefetch = true

    Kind of bug report, using assemblies version v11.0.0.0 and ScriptingOptions.DriAll = true.
    When you have tables with foreign keys or other constraints, these are not scripted when you pass urns of all tables to Scripter.Script which has Prefetch property set to true. I believe this is due to a bug in prefetching.
    To workaround, set Scripter.Prefetch = false. Strange enough, passing urns of subset of the tables works as well (even excluding one table only), which results in the "constraints are returned when passing single urn only" reported behavior.

    Hi, sure, sorry for late reply.
    This is the DB create script:
    DROP DATABASE [TestDB]
    USE [master]
    GO
    CREATE DATABASE [TestDB] CONTAINMENT = NONE ON PRIMARY
    ( NAME = N'TestDB', FILENAME = N'C:\Windows\Temp\Test.mdf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LOG ON
    ( NAME = N'TestLG', FILENAME = N'C:\Windows\Temp\Test.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
    GO
    ALTER DATABASE [TestDB] SET COMPATIBILITY_LEVEL = 110
    GO
    ALTER DATABASE [TestDB] SET ANSI_NULL_DEFAULT OFF
    ALTER DATABASE [TestDB] SET ANSI_NULLS OFF
    ALTER DATABASE [TestDB] SET ANSI_PADDING OFF
    ALTER DATABASE [TestDB] SET ANSI_WARNINGS OFF
    ALTER DATABASE [TestDB] SET ARITHABORT OFF
    ALTER DATABASE [TestDB] SET AUTO_CLOSE OFF
    ALTER DATABASE [TestDB] SET AUTO_CREATE_STATISTICS ON
    ALTER DATABASE [TestDB] SET AUTO_SHRINK OFF
    ALTER DATABASE [TestDB] SET AUTO_UPDATE_STATISTICS ON
    ALTER DATABASE [TestDB] SET CURSOR_CLOSE_ON_COMMIT OFF
    ALTER DATABASE [TestDB] SET CURSOR_DEFAULT GLOBAL
    ALTER DATABASE [TestDB] SET CONCAT_NULL_YIELDS_NULL OFF
    ALTER DATABASE [TestDB] SET NUMERIC_ROUNDABORT OFF
    ALTER DATABASE [TestDB] SET QUOTED_IDENTIFIER OFF
    ALTER DATABASE [TestDB] SET RECURSIVE_TRIGGERS OFF
    ALTER DATABASE [TestDB] SET DISABLE_BROKER
    ALTER DATABASE [TestDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
    ALTER DATABASE [TestDB] SET DATE_CORRELATION_OPTIMIZATION OFF
    ALTER DATABASE [TestDB] SET TRUSTWORTHY OFF
    ALTER DATABASE [TestDB] SET ALLOW_SNAPSHOT_ISOLATION OFF
    ALTER DATABASE [TestDB] SET PARAMETERIZATION SIMPLE
    ALTER DATABASE [TestDB] SET READ_COMMITTED_SNAPSHOT OFF
    ALTER DATABASE [TestDB] SET HONOR_BROKER_PRIORITY OFF
    ALTER DATABASE [TestDB] SET RECOVERY SIMPLE
    ALTER DATABASE [TestDB] SET MULTI_USER
    ALTER DATABASE [TestDB] SET PAGE_VERIFY CHECKSUM
    ALTER DATABASE [TestDB] SET DB_CHAINING OFF
    ALTER DATABASE [TestDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
    ALTER DATABASE [TestDB] SET TARGET_RECOVERY_TIME = 0 SECONDS
    ALTER DATABASE [TestDB] SET READ_WRITE
    GO
    USE [TestDB]
    GO
    CREATE TABLE [dbo].[KeySource] (
    [ID] [smallint] IDENTITY(1,1) NOT NULL,
    CONSTRAINT [PK_Reservation] PRIMARY KEY CLUSTERED ([ID] ASC)
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    CREATE TABLE [dbo].[KeyUse] (
    [UseID] [smallint] NOT NULL,
    [Row] [tinyint] NOT NULL,
    [Column] [tinyint] NOT NULL,
    CONSTRAINT [PK_KeySource] PRIMARY KEY CLUSTERED ([UseID] ASC, [Row] ASC, [Column] ASC)
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
    CONSTRAINT [IX_ReservationSeats] UNIQUE NONCLUSTERED ([Row] ASC, [Column] ASC)
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    ALTER TABLE [dbo].[KeyUse] WITH CHECK ADD CONSTRAINT [FK_Source_Use] FOREIGN KEY([UseID]) REFERENCES [dbo].[KeySource] ([ID])
    ON UPDATE CASCADE
    ON DELETE CASCADE
    ALTER TABLE [dbo].[KeyUse] CHECK CONSTRAINT [FK_Source_Use]
    ALTER TABLE [dbo].[KeyUse] WITH CHECK ADD CONSTRAINT [FK_Use_Use] FOREIGN KEY([UseID], [Row], [Column]) REFERENCES [dbo].[KeyUse] ([UseID], [Row], [Column])
    ALTER TABLE [dbo].[KeyUse] CHECK CONSTRAINT [FK_Use_Use]
    This is the code:
    ServerConnection serverConnection = new ServerConnection("server", "user", "pwd");
    Server server = new Server(serverConnection);
    Database database = server.Databases["TestDB"];
    Urn[] urns = database.EnumObjects(DatabaseObjectTypes.Table).Rows.OfType<DataRow>().Select(r => new Urn((string)r["Urn"])).Take(2).ToArray();
    Scripter s = new Scripter(server);
    s.Options.DriAll = true;
    StringCollection result = s.Script(urns);
    This is the result:
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    CREATE TABLE [dbo].[KeySource](
    [ID] [smallint] IDENTITY(1,1) NOT NULL
    ) ON [PRIMARY]
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    CREATE TABLE [dbo].[KeyUse](
    [UseID] [smallint] NOT NULL,
    [Row] [tinyint] NOT NULL,
    [Column] [tinyint] NOT NULL
    ) ON [PRIMARY]
    Note that the constraints are missing.
    As already noted, adding s.PrefetchObjects = false; line fixes this.
    But let's do the magic way - supplying less Urns than there actually is tables. To test this, add a dummy table to the DB:
    USE [TestDB]
    CREATE TABLE [dbo].[DummyTable]([Test] [nchar](10) NULL) ON [PRIMARY]
    Run the code again. Note that the Take(2) method limits the Urns supplied to the Scripter to the same set as before.
    However, the result is now:
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    CREATE TABLE [dbo].[KeySource](
    [ID] [smallint] IDENTITY(1,1) NOT NULL,
    CONSTRAINT [PK_Reservation] PRIMARY KEY CLUSTERED
    [ID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    CREATE TABLE [dbo].[KeyUse](
    [UseID] [smallint] NOT NULL,
    [Row] [tinyint] NOT NULL,
    [Column] [tinyint] NOT NULL,
    CONSTRAINT [PK_KeySource] PRIMARY KEY CLUSTERED
    [UseID] ASC,
    [Row] ASC,
    [Column] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
    CONSTRAINT [IX_ReservationSeats] UNIQUE NONCLUSTERED
    [Row] ASC,
    [Column] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    ALTER TABLE [dbo].[KeyUse] WITH CHECK ADD CONSTRAINT [FK_Source_Use] FOREIGN KEY([UseID])
    REFERENCES [dbo].[KeySource] ([ID])
    ON UPDATE CASCADE
    ON DELETE CASCADE
    ALTER TABLE [dbo].[KeyUse] CHECK CONSTRAINT [FK_Source_Use]
    ALTER TABLE [dbo].[KeyUse] WITH CHECK ADD CONSTRAINT [FK_Use_Use] FOREIGN KEY([UseID], [Row], [Column])
    REFERENCES [dbo].[KeyUse] ([UseID], [Row], [Column])
    ALTER TABLE [dbo].[KeyUse] CHECK CONSTRAINT [FK_Use_Use]
    By testing on larger database I have noticed it does not really matter which table is excluded from the list.
    Hope this helps,
    Jan

  • Foreign Key Error Message ORA - 01430

    I have a table name LSU_INTER_RESOURCES_T. I would like to add a foreign key constraint with the following command:
    alter table lsu_inter_message_t
    add constraint inter_message_id_fk
    inter_request_id REFERENCES lsu_inter_requests_t(inter_request_id) ON DELETE CASCADE;
    The system returned the error message:
    ORA - 01430: column being added already exists.
    if I drop the column inter_request_id I will lose data and when I create the constraint it places the column at the end of the table. Losing data is not an issue now because the table has no data but down the line I can see that this will be a real real hassle.
    I would like to have the foreign key column defined in the sequence I chose when I designed the table layout. That is to say I want all of the key columns placed at the begining of the table row layout.
    Can I move the column after I define it and how is this done? Is this a 10g feature?
    Thank you, Ned

    Try
    alter table lsu_inter_message_t
    add constraint inter_message_id_fk
    foreign key(inter_request_id ) REFERENCES lsu_inter_requests_t(inter_request_id) ON DELETE CASCADE;

  • No join predicate for this foreign key -error while importing the EUL

    Hello
    Anyone getting this error?I am trying to import 11i business areas into R12 EUL and I am getting this
    appreciate any feedback
    thanks
    kp

    Also check metalink note 1082644.1, this problem can be caused when importing into an Apps mode EUL using the EUL owner database account, rather than an eBusiness Suite user account.
    We've just had this exact problem, which was caused by something slightly different - an id column that was used in a join had been deleted. Discoverer does not cascade the delete, so the join was still in place, but with a blank formula. Disco reported no errors until an attempt was made to migrate this EUL from one environment to another. Deleting the join fixed the problem.
    HTH
    Matt

  • Ora-2270 Error while adding foreign key constraint on top a view

    While adding a constraint, referencing a foreign key column from a view raises error. However, it works fine over a table.
    Here's the sample script:
    create table t_temp (
    sample_id number,
    text varchar2(40))
    alter table t_temp add constraint temp_pk
    primary key (sample_id);
    create view tempvw as select sample_id,text from t_temp;
    create table t_sample (
    uniq_id number,
    sample_id number,
    sample_text varchar(40));
    =========
    ALTER TABLE t_sample ADD CONSTRAINT FK_sample_temp
         FOREIGN KEY (sample_id) REFERENCES t_temp (sample_id);
    This works fine.
    =========
    ==============
    The following raises ERROR....
    ALTER TABLE t_sample ADD CONSTRAINT FK_sample_temp1
         FOREIGN KEY (sample_id) REFERENCES tempvw (sample_id);
    Error starting at line 1 in command:
    ALTER TABLE t_sample ADD CONSTRAINT FK_sample_temp1
         FOREIGN KEY (sample_id) REFERENCES tempvw (sample_id)
    Error report:
    SQL Error: ORA-02270: no matching unique or primary key for this column-list
    02270. 00000 - "no matching unique or primary key for this column-list"
    *Cause:    A REFERENCES clause in a CREATE/ALTER TABLE statement
    gives a column-list for which there is no matching unique or primary
    key constraint in the referenced table.
    *Action:   Find the correct column names using the ALL_CONS_COLUMNS
    catalog view

    What exactly are you trying to accomplish by having a
    referential integrity constraint on a view (which is
    not allowed). PKs and FKs are allowed on views. DISABLE NOVALIDATE is the only allowed state for them. View constraints are used for query rewriting: http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/qradv.htm#sthref1457
    Regards,
    Dima

  • Error when sorting foreign key fields in a view

    Hello all
    I created a view and links to other views, and then created a table. In the table I put different attributes from the view and the views it is linked to. When I click the sort ascending or descending button in a column attribute that is in the original view, everything works fine. However if I click the same arrow button for a different column, one that is in a linked view, I get this error message.
    Definition OnlineTerminalId of type Attribute is not found in ObjektiView1.
    I do not understand why this does not work. It shows the values inside these linked views just fine. I did change names of some attributes in the database but I had the problem before then, and after I changed them all back so I doubt that is the issue.
    If anyone can help I would be much obliged

    Dino2dy wrote:
    Hmm, what I did is slightly different, but what my way does is give me the ability to create forms that change automatically when I click a row in a table, which I thought would be useful. I could do it your way too but I would have to do everything again from the beginning, which is something I am trying to avoid. There should be a way to fix this problem this way, as it would be kind of stupid to be able to show the data in the table but just not be able to sort or filter by it.You can still accomplish this by relating the combined VO with your children VOs using View Links, same as what you are doing now.
    Also that view would be HUGE as it is a single table that is connected to a lot of other tables via foreign keys, so my single view would cover 10 tables.Not necessarily. You don't have to include all Entities in your combined VO - just those that you want their attributes displayed on your table.
    Nick

  • Code generation - foreign key relationships

    I'm using the code/descriptor generation tab to generate classes from existing tables. It offers an option of choosing which relationships to generate, but seems to miss out some of the defined foreign key relationships in the database.
    I have three tables, CLIENTS, TXNS and REG
    The following constraints are defined in my database:
    TXN Primary Key: (TXN_ID)
    CLIENTS Primary Key :CLIENT_ID, TXN_ID)
    CLIENTS Foriegn KEy : TXN_ID references TXNS
    REG Primary Key: CLIENT_ID, TXN_ID
    REG Foreign Key: CLIENT_ID, TXN_ID references CLIENTS
    I select these three tables and choose generate classes and descriptors for selected tables. When the "Choose Relationships to generate" screen comes up, it only shows me the CLIENTS<-->TXNS relationship, but not the REG<-->CLIENTS relationship, even though the database foreign key constraints all look as though they've been defined in similar ways.
    thanks for any help.

    Hi Matt,
    I'm not surprised that you have an issue with this. One bugbear I have with Gateway is that for some reason the designers don't think any context beyond the immediate preceding navigation node is important. They don't support this within the same service,so it's hardly likley to work in a service reference.
    I may be wrong but I don't think GW is OData compliant in this respect. If I have the navigation path /blindservice/FromHereSet(1)/ToAPoints(22)/ToBPoints, it's rather restrictive to say I cannot see the initial key of '1' in the path when I am trying to resolve 'ToBPoints'. If that value - where I started - is key to the context, I have to know it.
    Currently the only way to access this context is to embed the 'key history' in the intermediate entities, i.e. /blindservice/FromHereSet(1)/ToAPoints(1,22)/ToBPoints. In my view that is corrupting the URl to suit the limitations of the SAP OData implementation. What's even more confusing/frustrating is that the technical request context appears to be able to store the stacked navigation keys but doesn't make use of this design. 
    I feel your pain
    Ron.

  • SQL Datamodeler ddl generation looses foreign keys

    My problem is that when I open my relational model, I select generate of DDL selection Oracle 10g as the physical. I can see the list of referential contraints under the Foreign Key tab. I generate once and all is fine, save the model and exit. I then restart the model and go through the same procedure. This time I can still see the entries under foreign keys tab but when I generate there are no foreign key entries. If I select 11g on the generate then they re-appear. Save it and go back in, select 11g and generate and they have gone again. Select 10g and generate and they are back.
    This means I cannot use the physical model attributes (users, synonyms etc) because I keep jumping from 10g to 11g generation models.
    Any ideas?
    Sql Modeler 2.0.0. build 584.

    Hi,
    I've got exactly this behaviour - and the exact same workaround to fix it. i.e. Save, change Physical to 11g and save again.
    Re-open, won't generate some physical parts correctly i.e. fk constraints.
    Swap to 10g and regenerate fine.
    You may have to import some fks manually from a DDL file into the physical model to make this happen? Modelled ones seem to work?
    If there a switch variable in the DM code gone awry?
    Nigel

  • Question about scripting of foreign keys

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

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

  • Error making Foreign Keys

    Hi,
    I get an error trying to create foreign keys.
    The message reads "Parent keys not found".
    I have the primary keys in my parent table.
    Any thoughts what it could be?
    Thanks,

    Hi All,
    Please check this:
    ORA-02298 cannot validate (string.string) - parent keys not found
    Cause: An ALTER TABLE ENABLE CONSTRAINT command failed because
    the table has orphaned child records.
    Action: Make sure that the table has no orphaned child records before issuing
    an ALTER TABLE ENABLE CONSTRAINT command. For more information
    about ALTER TABLE and ENABLE CONSTRAINT, see the Oracle9i SQL
    Reference.
    Peter D.

  • Error when adding Foreign Key

    Hi,
    Problem:
    When trying to add a Foreign Key via Edit Table | Foreign Key tab an error is thrown
    Error:
    "ORA-00942: table or view does not exit", Vendor code 942
    SQL Developer Generated DDL:
    ALTER TABLE "CNArticlesCODES"
    DROP CONSTRAINT "CNArticlesCODES_FK1"
    ALTER TABLE "CNArticlesCODES"
    ADD CONSTRAINT "CNArticlesCODES_FK1" FOREIGN KEY
    "ID"
    ) REFERENCES CNArticlesDATA
    "ID"
    ) ENABLE
    My work around:
    table name next to REFERENCES command in double quotes
    ALTER TABLE "CNArticlesCODES"
    ADD CONSTRAINT "CNArticlesCODES_FK1" FOREIGN KEY
    "UID"
    ) REFERENCES "CNArticlesCODES"
    "UID"
    ) ENABLE
    SQL Developer 1.0.0.15.57 on Windows XP SP2
    Oracle Database 10g Enterprise Edition Release 10.2.0.10 (Eval Lic) on Windows 2003 Web Edition 32 bit
    The 2 tables in this example where generated by MS DTS tool while importing data. This issue is not present when performing the above action on 2 tables generated using SQL Developer.
    I'm no database expert and new to Oracle (R&D stage of SQL Server to Oracle migration). So can some body tell me/point me at docs that explains what's going on here with the table names.
    Thanks

    Hopefully someone from oracle will see this and log it as a bug. If that doesn't happen and you have a support license, you can open up a ticket with them directly.
    As an aside.. if you are daring enough, the template for that is stored in one of the jars in an xml file. You can always edit it and add the quotes. Or..and you don't want to hear this.. you may want to rename everything to uppercase. It would hurt now, but could end up saving you time down the road. (adding quotes to every query is a pain)
    Eric

  • $$$ Non-fatal error (1202): Foreign Key 'FCM_1_CO_OWNER(Owner_Id) reference

    Hi All,
    We are getting below fatal error while repairing the repository. and we are using MDM SP07 Patch Level 27.
    Error Message: $$$ Non-fatal error (1202): Foreign Key u2018FCM_1_CO_OWNER(Owner_Id) referencing A2i_CM_Users (UserId)u2019 is missing.
    Can  anyone help me how to resolve this issue ?
    Thanks & Regards,
    Mahesh

    Hello,
    I guess you have upgraded your system and hence you are getting this error.
    I guess some lookup table are missing the reference in this.
    But the error says NON-FATAL, please check if you are getting the same error while checking the repository.
    My suggestion would be to unmount and mount the reposiory again.
    regards,
    Abhishek

  • 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

Maybe you are looking for

  • Upload Open Purchase orders

    Hi All, Our client is implementing SRM and the conversion is  from non-sap legacy system. Is there a way to upload all the Open PO's without manually keying it in. Thanks, Reena

  • Defective Parts removal in Service Order

    Hi, Customer's defective product is being repaired. For every part consumed for repair, a faulty part is removed from the product. The faulty parts have to be returned to the customer and customer will pay for the Service Charges and Parts consumed.

  • Unc path in SAP XI

    How we can develope an UNC Path in SAP XI? Try to Provide usefull links and code, if possible.

  • Freeze Last Frame in slideshow?

    I have created a basic slideshow in iPhoto for export to Quicktime (Pro). I would like the last image in the sequence to NOT fade out & remain onscreen until the viewer closes the file. There seem to be individual slide controls in Slidewshow mode, b

  • Where can I freaking find an iPhone 4???

    I am on a reserved waiting list at like 4-5 Apple stores here in Maryland. I have been for over a week and a half now, and im not getting any email notifications of my iPhone 4 being ready for pick up. 2 weeks ago I dropped my iPhone 3G in our pool,