Primary and Foreign Keys

I've attempted to identify a primary and foreign key in these two tables, but I am getting a bunch of errors re duplicate keys and column names needing to be unique. Can someone explain to me what I am doing wrong? I have watched numerous tutorials. Perhaps
the primary and foreign key I have identified don't meet the criteria?
CREATE TABLE StockNames
-- Added Primary key to [stock_symbol]
[stock_symbol] VARCHAR(5) NOT NULL CONSTRAINT PK_stock_symbol PRIMARY KEY,
[stock_name] VARCHAR(150) NOT NULL,
[stock_exchange] VARCHAR(50) NOT NULL,
GO
stock_symbol stock_name stock_exchange
AEA American External Accessories NYSE
ASP All Sports Portal NYSE
AIT Anthony Interest Technology NYSE
ATV American Technology Vehicles NYSE
ACM Anderson Charles and Mitchell NYSE
ACH American Career Helpers NYSE
AVA Alleviate America NYSE
and the second table
CREATE TABLE DailyPricesA (
[stock_symbol] VARCHAR (5) NOT NULL CONSTRAINT FK_stocksymbol REFERENCES [StockNames]([stock_symbol]),
[date] VARCHAR (15) NOT NULL,
[stock_price_open] FLOAT (53) NOT NULL,
[stock_price_high] FLOAT (53) NOT NULL,
[stock_price_low] FLOAT (53) NOT NULL,
[stock_price_close] FLOAT (53) NOT NULL,
[stock_volume] INT NOT NULL,
[stock_price_adj_close] FLOAT (53) NOT NULL,
stock_exchange stock_symbol date stock_price_open stock_price_high stock_price_low stock_price_close stock_volume stock_price_adj_close
NYSE AEA 8/02/2010 4.42 4.42 4.21 4.24 205500 4.24
NYSE AEA 5/02/2010 4.42 4.54 4.22 4.41 194300 4.41
NYSE AEA 4/02/2010 4.55 4.69 4.39 4.42 233800 4.42

Hi Stan,
I have removed "stock_exchange" - that removed that error. These are the other errors I am experiencing:Msg
2714, Level 16, State 6, Line 8
There is already an object named 'DailyPricesA' in the database.
Msg 2714, Level 16, State 6, Line 36
There is already an object named 'StockNames' in the database.
Msg 2627, Level 14, State 1, Line 47
Violation of PRIMARY KEY constraint 'PK__StockNam__117C59C768B2BB7F'. Cannot insert duplicate key in object 'dbo.StockNames'. The duplicate key value is (AA).
The statement has been terminated.
Msg 1913, Level 16, State 1, Line 54
The operation failed because an index or statistics with name 'SNIndex' already exists on table 'DailyPricesA'.
And the code:
USE NYSEDatabaseProject
-- Drop the table to clean up database.
--DROP TABLE DailyPricesA
--GO
-- Create the table.
CREATE TABLE DailyPricesA (
[stock_symbol] VARCHAR (5) NOT NULL CONSTRAINT FK_stocksymbol REFERENCES [StockNames]([stock_symbol]),
[date] VARCHAR (15) NOT NULL,
[stock_price_open] FLOAT (53) NOT NULL,
[stock_price_high] FLOAT (53) NOT NULL,
[stock_price_low] FLOAT (53) NOT NULL,
[stock_price_close] FLOAT (53) NOT NULL,
[stock_volume] INT NOT NULL,
[stock_price_adj_close] FLOAT (53) NOT NULL,
-- Add a foreign key.
-- [stock_symbol] VARCHAR (5) NOT NULL CONSTRAINT FK_stocksymbol REFERENCES [StockNames]([stock_symbol]),
BULK INSERT DailyPricesA
from 'C:\Users\fenwky\NYSE_daily_prices_A.csv'
-- firstrow = 2 skips the header row, field terminator =',' deterines the separator, and rowterminator defines where the row ends
with (firstrow = 2, fieldterminator = ',', rowterminator = '\n')
GO
-- Create an index named DPAIndex, for the columns stock_symbol//'DPAIndex' already exists on table 'DailyPricesA'
--CREATE INDEX DPAIndex
--ON DailyPricesA (stock_symbol);
-- Drop the table to clean up database.
-- DROP TABLE StockNames
-- GO
CREATE TABLE StockNames
-- Added Primary key to [stock_symbol]
[stock_symbol] VARCHAR(5) NOT NULL CONSTRAINT PK_stock_symbol PRIMARY KEY,
[stock_name] VARCHAR(150) NOT NULL,
[stock_exchange] VARCHAR(50) NOT NULL,
GO
-- Insert the CSV into the table named Stocknames
BULK INSERT StockNames
from 'C:\Users\fenwky\NYSE_stock_names.csv'
-- firstrow = 2 skips the header row, field terminator =',' deterines the separator, and rowterminator defines where the row ends
with (firstrow = 2, fieldterminator = ',', rowterminator = '\n')
GO
-- Create an index named SNIndex, for the columns stock_symbol and stock_exchange.
CREATE INDEX SNIndex
ON DailyPricesA (stock_symbol);
-- Select all from DailyPricesA
select * from StockNames

Similar Messages

  • Lack of Primary and Foreign Keys and Efficiency

    I am reverse engineering a Maximo database. I am shock that it does not have Primary or foreign keys define for 590 out of 620 tables.
    My question is does the lack of Primary and Foreign key relationships adversely impact the efficiency of an Oracle database? I think it does IBM techs do not think it does.
    Anyone has the answer?

    does the lack of Primary and Foreign key relationships adversely impact the efficiency of an Oracle database? Not necessarily. There are many large OLTP databases that do not define PKs and FKs.
    It is true that the presence of constraint defintions is used by the optimizer. However,
    what matters is how the application is written and how the optimizer handles it.
    Remember that Oracle Databases have been in production since before constraint definitions were introduced.
    Hemant K Chitale
    Edited by: Hemant K Chitale on Jun 9, 2010 10:05 AM

  • Lost about 60-75% of my primary and foreign keys when Migrating from SQL Server 7

    Hi All,
    I did an almost successful migration between SQL Server 7.0 and Oracle9i.
    What happened:
    I seem to have lost my primary and foreign keys in the migration. The funny thing is when I viewed the constraints and indexes in Toad, they were there. However when I tried to enabled those constraints nothing happened.
    I really don't know how I can fixed this, but I don't understand why I didn't get a warning or an error message in the Migration Workbench (latest version).
    I did ignore the following errors, could that have anything to do with the keys being lost.
    Failed to create User:omwb_emulation; ORA-1920: user name "OMWB_EMULATION" conflicts with another user or role name
    Failed to create User:guest;ORA-01920: user name "GUEST" conflicts with another user or role name
    These users do not own any objects therefore I ignored them.
    Please advise
    Thanks

    Hi Joe,
    Not sure why you are able to see these objects and yet not able to enable them. Did you encounter any errors during the create Oracle Model phase?? Did you encounter any errors during the final Migrate phase?
    Also, it is really important to have a tablespace created before an attempt is made to create tables and indexes in the destination Oracle database.
    Regards
    John

  • Oracle 9i primary and foreign key constraint

    I had created table in the following way
    create table dept(deptno number,dname varchar2(20));
    create table emp(empno number primary key,ename varchar2(25), deptno number references dept(deptno));
    One can get constraint name and constraint type from user_constraints table. But I want to know name of the column of table from which column is used as foreign key in another table. How to get such information?

    SQL> Select *From user_cons_columns  A
      2   Where Constraint_Name In (Select r_Constraint_Name
      3                           From User_Constraints B
      4        Where Table_Name='EMP'
      5          And Constraint_Type='R'
      6          Group By r_Constraint_Name
      7          )
      8  /
    OWNER                          CONSTRAINT_NAME                TABLE_NAME                     COLUMN_NAME                       
    SCOTT                          PK_DEPTNO                      DEPT                           DEPTNO                             Edited by: babaravi on Oct 5, 2009 3:34 PM

  • Primary key and Foreign key on same column

    Hi, I am able to create below tables , primary and foreign keys as below.
    But Is this valid design? Can I define a column (ckey2 in table "child") as
    primary key and as well as foreign key?
    CREATE TABLE parent (
    col1 NUMBER,
    col2 NUMBER
    CREATE TABLE child (
    ckey1 NUMBER,
    ckey2 NUMBER,
    ckey3 NUMBER
    alter table parent add constraint parent_pk primary key( col1 );
    alter table child add constraint child_pk primary key( ckey2 );
    alter table child add constraint child_fk foreign key( ckey2 ) references parent( col1);
    Thanks.

    Can I define a column (ckey2 in table "child") as primary key and as well as foreign key?You mean you want to define a one-to-one relationship between parent and child tables.. why would you want to do that ? You might as well merge the 2 tables into one.

  • Primary Key and Foreign Key Constraints

    Hi All,
    I would like to know PRIMARY KEY and FOREIGN KEY constraints on existing oracle tables. Could any one suggest me how to find out.
    Thanks,
    RED

    You can query DBA_CONSTRAINTS to get a list of all the constraints on table A and/or table B. The documentation I linked to gives a full list of the data you can see in DBA_CONSTRAINTS, but it includes things like the referenced table name and referenced constraint name for a foreign key constraint. If A is a parent of B or B is a parent of A, you could match up the parent's primary key constraint to the child's foreign key constraint.
    More generally, though, if you don't know that one of the tables is a parent of the other, figuring out how to join the two tables is probably not something that can be done using just the Oracle data dictionary. You would probably need an understanding of the data model being used to figure out what intermediate table(s) needed to be joined in order to relate rows in A to rows in B.
    Justin

  • How to transfer database table contain null values, primary key, and foreign key to the another database in same server. using INSERT method.

    how to transfer database table contain null values, primary key, and foreign key to the another database in same server. using INSERT method.  thanks

    INSERT targetdb.dbo.tbl (col1, col2, col3, ...)
       SELECT col1, col2, col3, ...
       FROM   sourcedb.dbo.tbl
    Or what is your question really about? Since you talke about foreign keys etc, I suspect that you want to transfer the entire table definition, but you cannot do that with an INSERT statement.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Mapping in OWB with primary key and foreign key relationship

    Hi all,
    I am new to this datawarehousing field. I have just started my career. I have to now create a mapping in owb where a table has a field which is a primary key of another table in the same staging area. If you guys could help me out with the a method it can be created that would be very helpful to me.
    I thought of 2 ideas,
    1. If I can use a look up, but then I am not sure if i can use a lookup for primary key, foreign key relationship. If I can use also, I do not know how to use that.
    2. What if I can directly take that the first table and link the primary key of that table to the second table which uses that primary key of the first table as one of its fields.
    I do not know how feasible these methods are. Please guys help me out.
    Thanks in advance.

    I have a similar case where table a and table b having relation but table a got inserted with data and table b is empty so there no values for foriegn key column in table b to realte with table a.
    Now i want to load table b foriegn key with primary key column values of table a.
    how can we do this in owb
    thanks
    kumar

  • Primary key and Foreign Key

    Hello,
             I have a question which was asked in an interview
    Can a Primary key in a table also act as a foreign key in the same table ?
    If yes than please provide a simple example
    Thanks
    www.techgulf.blogspot.com

    See this illustration
    create table t
    id int identity(1,1) not null primary key,
    val varchar(100)
    create table t2
    id int not null primary key,
    val varchar(100)
    -- make pk itself as fk to table t
    alter table t2 add constraint fk_t2 foreign key (id) references t(id)
    --some test values to t
    insert t (val)
    values ('test'),('test1'),('test2')
    -- populate t2 first two suceeds
    insert t2(id,val)
    values (1,'iuyi')
    insert t2(id,val)
    values (2,'ef24r')
    -- this will fail as we dont have record with id 4 in t
    insert t2(id,val)
    values (4,'weqw')
    --check the output
    select * from t
    select * from t2
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

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

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

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

  • Before delete trigger and foreign key relationship

    Hi,
    I am analysing one database for migration. On one parent table there is before delete trigger , to delete records from child. Also there is foreign key relationship on child table for this parent table.
    When I am deleting a row from parent, message gets displayed as "there are child records found."
    I would like to know, if there is foreign key relatioship then delete trigger on parent does't work, what is exactly happening?

    Could you post that trigger code and the Oracle version as well?
    With basic assumptions, I can't reproduce what you have stated here.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> create table parent (id number primary key);
    Table created.
    SQL> create table child (id number);
    Table created.
    SQL> alter table child add constraint fk_parent foreign key (id) references parent;
    Table altered.
    SQL> create or replace trigger bdr_parent
      2  before delete on parent
      3  for each row
      4  begin
      5  delete from child where id = :old.id;
      6  end;
      7  /
    Trigger created.
    SQL> insert into parent (id) values (1);
    1 row created.
    SQL> insert into child (id) values (1);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> delete from parent where id = 1;
    1 row deleted.
    SQL> select * from parent;
    no rows selected
    SQL> select * from child;
    no rows selected
    SQL> rollback;
    Rollback complete.
    SQL> alter table child drop constraint fk_parent;
    Table altered.
    SQL> alter table child add constraint fk_parent foreign key (id) references parent on delete cascade;
    Table altered.
    SQL> delete from parent where id = 1;
    delete from parent where id = 1
    ERROR at line 1:
    ORA-04091: table SCOTT.CHILD is mutating, trigger/function may not see it
    ORA-06512: at "SCOTT.BDR_PARENT", line 2
    ORA-04088: error during execution of trigger 'SCOTT.BDR_PARENT'
    SQL>

  • Primary keys and foreign keys

    Hi,
    is there a script available for changing the value of a primary key which automaticly
    detect all foreigs keys refering to this primary key and change them as well?
    William Oorschot

    I don't have the script now. but you can make a procedure of ur own.
    using a join on user_constraints, and user_cons_columns you can find out all the columns in all the tables which are referencing the particular primary key. once you have the table and the referencing columns, you can change the value of those columns with the new value.
    you'll have to call this procedure from a before row level trigger.
    HTH
    Naveen

  • How to update the Primay and Foreign Key Defaults for a tabular form?

    I created a tabular form and told it to use an existing sequence for the PK. I can't find where to update the sequence the form is using, can someone point me in the right direction?
    Thanks,
    -- John
    Message was edited by:
    johnniebillings

    Thanks for the update, but I have already created and compiled the trigger. The problem is when I insert a row the tabular form tries to generate the sequence (because that is what I told the wizard to do when I created it).
    However, I have since created the trigger and I want the tabular form to no longer use the sequence directly. How do I update this?
    Thanks,
    -- John

  • TIPS(9):PARENT-CHILD(FOREIGN KEY) 관계를 갖는 MASTER TABLE의 PRIMARY KEY 확인.

    제품 : SQL*PLUS
    작성날짜 : 1996-10-21
    TIPS(9) : PARENT-CHILD관계를 갖는 TABLE의
    PRIMARY key, FOREIGN key의 COLUMN 명과 POSITION 확인
    ==============================================================
    ** Name : Show_Position.Sql
    ** Usage : @Show_Positions Parent_Table Child_Table
    ** Description : Shows Primary And Foreign Key Positions
    ** WARNING : 이 문장은 해당 Table의 Constraint생성시 Naming
    ** Convention을 따른 경우에 적용되도록 되어 있다.
    SET VERIFY OFF
    CLEAR BREAK
    BREAK ON CONSTRAINT_NAME ON TABLES
    SELECT SUBSTR(CONSTRAINT_NAME,1,27) CONSTRAINT_NAME,
    SUBSTR(TABLE_NAME,1,15) TABLES,
    SUBSTR(COLUMN_NAME,1,15) COL_NAME,
    SUBSTR(POSITION,1,3) POSITION,
    SUBSTR(OWNER,1,7) OWNER
    FROM USER_CONS_COLUMNS
    WHERE TABLE_NAME = UPPER('&1')
    AND CONSTRAINT_NAME LIKE 'PK%'
    UNION
    SELECT SUBSTR(CONSTRAINT_NAME,1,27) CONSTRAINT_NAME,
    SUBSTR(TABLE_NAME,1,15) TABLES,
    SUBSTR(COLUMN_NAME,1,25) COL_NAME,
    SUBSTR(POSITION,1,3) POSITION,
    SUBSTR(OWNER,1,7) OWNER
    FROM USER_CONS_COLUMNS
    WHERE TABLE_NAME = UPPER('&2')
    AND CONSTRAINT_NAME LIKE 'FK%'
    ORDER BY 1 DESC , 4 ASC;
    < 실행 예 >
    SQL> @SHOW_POSITIONS EMP_SERVICE EMP_SERVICE_LOG
    CONSTRAINT_NAME TABLES COL_NAME POS
    PK_EMP_SERVICE EMP_SERVICE EMP_ID 1
    CUST_ID 2
    FK_EMP_SERVICE_LOG_EC EMP_SERVICE_LOG EMP_ID 1
    CUST_ID 2

    제품 : SQL*PLUS
    작성날짜 : 1996-10-21
    TIPS(9) : PARENT-CHILD관계를 갖는 TABLE의
    PRIMARY key, FOREIGN key의 COLUMN 명과 POSITION 확인
    ==============================================================
    ** Name : Show_Position.Sql
    ** Usage : @Show_Positions Parent_Table Child_Table
    ** Description : Shows Primary And Foreign Key Positions
    ** WARNING : 이 문장은 해당 Table의 Constraint생성시 Naming
    ** Convention을 따른 경우에 적용되도록 되어 있다.
    SET VERIFY OFF
    CLEAR BREAK
    BREAK ON CONSTRAINT_NAME ON TABLES
    SELECT SUBSTR(CONSTRAINT_NAME,1,27) CONSTRAINT_NAME,
    SUBSTR(TABLE_NAME,1,15) TABLES,
    SUBSTR(COLUMN_NAME,1,15) COL_NAME,
    SUBSTR(POSITION,1,3) POSITION,
    SUBSTR(OWNER,1,7) OWNER
    FROM USER_CONS_COLUMNS
    WHERE TABLE_NAME = UPPER('&1')
    AND CONSTRAINT_NAME LIKE 'PK%'
    UNION
    SELECT SUBSTR(CONSTRAINT_NAME,1,27) CONSTRAINT_NAME,
    SUBSTR(TABLE_NAME,1,15) TABLES,
    SUBSTR(COLUMN_NAME,1,25) COL_NAME,
    SUBSTR(POSITION,1,3) POSITION,
    SUBSTR(OWNER,1,7) OWNER
    FROM USER_CONS_COLUMNS
    WHERE TABLE_NAME = UPPER('&2')
    AND CONSTRAINT_NAME LIKE 'FK%'
    ORDER BY 1 DESC , 4 ASC;
    < 실행 예 >
    SQL> @SHOW_POSITIONS EMP_SERVICE EMP_SERVICE_LOG
    CONSTRAINT_NAME TABLES COL_NAME POS
    PK_EMP_SERVICE EMP_SERVICE EMP_ID 1
    CUST_ID 2
    FK_EMP_SERVICE_LOG_EC EMP_SERVICE_LOG EMP_ID 1
    CUST_ID 2

  • One-to-many/foreign keys howto

    I have a situation where I'm trying to assemble a web of data and not make
    JDO mad.
    Here's the structure. I load this data in in batches, with an entry being
    placed in a load history table (H) to track each batch. Each batch
    contains primary (M) records associated with 0..n qualifying records from
    one or both of two auxiliary tables (D, L). All liberally salted with
    primary and foreign keys for referential integrity, and most of the keys
    are compounds, since the "M" identifiers get recycled for each batch load.
    Or, in other words, the "M" key is an ID plus an H key.
    Here's a map:
    H--0..n-->M
    __ +--0..n-->D
    __ +--0..n-->L
    Just to make things even more fun, the primary key of the H table is an
    Oracle 8 "DATE" type, which -- unlike ANSI SQL -- is actually a
    "TIMESTAMP". Kodo is rendering this as a java.util.Date rather than
    java.sql.Date, which is fine, because I need the full millisecond
    resolution. Interestingly, when I altered the schema type to "timestamp",
    load operations failed because the "column value was too big" according to
    Oracle.
    Also adding to the enjoyment, the actual order of presentation of data is
    that ALL M records come in, then ALL D records and finally ALL L records.
    I create my own H when the load starts.
    Now ideally, the whole shooting match will be a single pass/fail
    transaction, but that's for later.
    Right now, I can create the H, no problem and M's no problem. However,
    adding the D's and L's fails come commit time:
    kodo.util.FatalUserException: Attempt to set column "OFAC_ADDRESS.LOAD_ID"
    to two different values: "7/9/04 9:41 AM", "7/9/04 9:41 AM" This can occur
    when you fail to set both sides of a two-sided relation between objects,
    or when you map different fields to the same column, but you do not keep
    the values of these fields in synch.
    The granularity of the timestamps printed isn't making life easier, so I
    double-checked the D record's actual local value
    ADDRESS SERIALIZER A: Fri Jul 09 09:41:58 EDT 2004/Fri Jul 09 09:41:58 EDT
    2004
    ADDRESS SERIALIZER B: 1089380518179/1089380518179 (getTime())
    ADDRESS SERIALIZER C: -1541174818/-1541174818 (hashCode())
    I think I need a clearer understanding of what actions cascade here and
    what actions require manual help. For M, I did a setH(H) plus a
    setHid(H.getId()) and that made it happy. For D's and L's, of course, I
    also have to do a setM(M), where, because of the way the data comes in, I
    had to lookup the previously-stored M based on the M.id plus H.id.
    Now the parent objects contain sets of child objects. In theory, I should
    be adding the newly-created children to those sets, but in practice,
    setting the parent on the child appears to cause this to happen
    automagically, though I still have to manually set the local value of the
    foreign key field.
    I really need to find a good FM to RT. Online (and in the Kodo docs), I
    find a lot about setting up the XML for one-to-many mapping, but the Java
    coding side is taken as obvious. Regrettably, few things are obvious to me.
    I suppose I should excerpt the schema just for completeness:
    <table name="LOAD_HISTORY">
    <pk name="SYS_C0036906" column="LOAD_ID"/>
    <column name="LIST_TYPE" type="varchar" size="32"/>
    <column name="LOADED_BY" type="varchar" size="32"/>
    <column name="LOAD_ID" type="date" not-null="true" size="7"/>
    <column name="SUNSET_TIME" type="date" size="7"/>
    <fk name="FK_LOADHISTORY_LOADEDBY" delete-action="exception"
    to-table="OFAC.OFAC_USERS" column="LOADED_BY"/>
    </table>
    <table name="OFAC_ADDRESS">
    <pk name="SYS_C0036904">
    <on column="ADDRESS_ID"/>
    <on column="LOAD_ID"/>
    </pk>
    <column name="ADDRESS" type="varchar" size="125"/>
    <column name="ADDRESS_ID" type="decimal" not-null="true"
    size="22"/>
    <column name="CITY" type="varchar" size="64"/>
    <column name="COUNTRY" type="varchar" size="64"/>
    <column name="ID" type="decimal" size="22"/>
    <column name="LOAD_ID" type="date" not-null="true" size="7"/>
    <column name="REMARKS" type="varchar" size="300"/>
    <fk name="FK_OFACADDRESS_ID" delete-action="exception"
    to-table="OFAC.OFAC_MAIN">
    <join column="ID" to-column="ID"/>
    <join column="LOAD_ID" to-column="LOAD_ID"/>
    </fk>
    <fk name="FK_OFACADDRESS_LOADID" delete-action="exception"
    to-table="OFAC.LOAD_HISTORY" column="LOAD_ID"/>
    </table>
    <table name="OFAC_ALIAS">
    <pk name="SYS_C0036905">
    <on column="ALIAS_ID"/>
    <on column="LOAD_ID"/>
    </pk>
    <column name="ALIAS" type="varchar" size="200"/>
    <column name="ALIAS_ID" type="decimal" not-null="true"
    size="22"/>
    <column name="ID" type="decimal" size="22"/>
    <column name="LOAD_ID" type="date" not-null="true" size="7"/>
    <column name="REMARKS" type="varchar" size="300"/>
    <fk name="FK_OFACALIAS_ID" delete-action="exception"
    to-table="OFAC.OFAC_MAIN">
    <join column="ID" to-column="ID"/>
    <join column="LOAD_ID" to-column="LOAD_ID"/>
    </fk>
    <fk name="FK_OFACALIAS_LOADID" delete-action="exception"
    to-table="OFAC.LOAD_HISTORY" column="LOAD_ID"/>
    </table>
    <table name="OFAC_MAIN">
    <pk name="SYS_C0036903">
    <on column="ID"/>
    <on column="LOAD_ID"/>
    </pk>
    <column name="ID" type="decimal" not-null="true" size="22"/>
    <column name="LOAD_ID" type="date" not-null="true" size="7"/>
    <column name="REMARKS" type="varchar" size="300"/>
    <fk name="FK_OFACMAIN_LOADID" delete-action="exception"
    to-table="OFAC.LOAD_HISTORY" column="LOAD_ID"/>
    </table>

    Hi Greg,
    I'm just using the unmodified schema-to-mapping output. The one thing that
    might be unusual is that I've broken up related tables into discrete
    packages, but I believe all the items in question are in this package.
    Here it is:
    <?xml version="1.0" encoding="UTF-8"?>
    <mapping>
    <package name="com.everbank.finance.ofac3.jdo.sdn">
    <class name="LoadHistory">
    <jdbc-class-map type="base" table="OFAC.LOAD_HISTORY"/>
    <jdbc-version-ind type="state-image"/>
    <field name="listType">
    <jdbc-field-map type="value" column="LIST_TYPE"/>
    </field>
    <field name="loadId">
    <jdbc-field-map type="value" column="LOAD_ID"/>
    </field>
    <field name="ofacAddress">
    <jdbc-field-map type="one-many"
    ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ADDRESS"/>
    </field>
    <field name="ofacAlias">
    <jdbc-field-map type="one-many"
    ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ALIAS"/>
    </field>
    <field name="ofacMains">
    <jdbc-field-map type="one-many"
    ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_MAIN"/>
    </field>
    <field name="ofacUsers">
    <jdbc-field-map type="one-one" column.USER_ID="LOADED_BY"/>
    </field>
    <field name="runInfoLoadIdents">
    <jdbc-field-map type="one-many"
    ref-column.LOAD_ID="LOAD_ID" table="OFAC.RUN_INFO_LOAD_ID"/>
    </field>
    <field name="sunsetTime">
    <jdbc-field-map type="value" column="SUNSET_TIME"/>
    </field>
    </class>
    <class name="OfacAddress">
    <jdbc-class-map type="base" table="OFAC.OFAC_ADDRESS"/>
    <jdbc-version-ind type="state-image"/>
    <field name="address">
    <jdbc-field-map type="value" column="ADDRESS"/>
    </field>
    <field name="addressId">
    <jdbc-field-map type="value" column="ADDRESS_ID"/>
    </field>
    <field name="addressMp1">
    <jdbc-field-map type="value" column="ADDRESS_MP1"/>
    </field>
    <field name="addressMp2">
    <jdbc-field-map type="value" column="ADDRESS_MP2"/>
    </field>
    <field name="city">
    <jdbc-field-map type="value" column="CITY"/>
    </field>
    <field name="cityMp1">
    <jdbc-field-map type="value" column="CITY_MP1"/>
    </field>
    <field name="cityMp2">
    <jdbc-field-map type="value" column="CITY_MP2"/>
    </field>
    <field name="country">
    <jdbc-field-map type="value" column="COUNTRY"/>
    </field>
    <field name="countryMp1">
    <jdbc-field-map type="value" column="COUNTRY_MP1"/>
    </field>
    <field name="countryMp2">
    <jdbc-field-map type="value" column="COUNTRY_MP2"/>
    </field>
    <field name="loadHistory">
    <jdbc-field-map type="one-one" column.LOAD_ID="LOAD_ID"/>
    </field>
    <field name="loadId">
    <jdbc-field-map type="value" column="LOAD_ID"/>
    </field>
    <field name="ofacMain">
    <jdbc-field-map type="one-one" column.ID="ID"
    column.LOAD_ID="LOAD_ID"/>
    </field>
    <field name="remarks">
    <jdbc-field-map type="value" column="REMARKS"/>
    </field>
    </class>
    <class name="OfacAlias">
    <jdbc-class-map type="base" table="OFAC.OFAC_ALIAS"/>
    <jdbc-version-ind type="state-image"/>
    <field name="alias">
    <jdbc-field-map type="value" column="ALIAS"/>
    </field>
    <field name="aliasId">
    <jdbc-field-map type="value" column="ALIAS_ID"/>
    </field>
    <field name="aliasMp1">
    <jdbc-field-map type="value" column="ALIAS_MP1"/>
    </field>
    <field name="aliasMp2">
    <jdbc-field-map type="value" column="ALIAS_MP2"/>
    </field>
    <field name="aliasType">
    <jdbc-field-map type="value" column="ALIAS_TYPE"/>
    </field>
    <field name="loadHistory">
    <jdbc-field-map type="one-one" column.LOAD_ID="LOAD_ID"/>
    </field>
    <field name="loadId">
    <jdbc-field-map type="value" column="LOAD_ID"/>
    </field>
    <field name="ofacMain">
    <jdbc-field-map type="one-one" column.ID="ID"
    column.LOAD_ID="LOAD_ID"/>
    </field>
    <field name="remarks">
    <jdbc-field-map type="value" column="REMARKS"/>
    </field>
    </class>
    <class name="OfacMain">
    <jdbc-class-map type="base" table="OFAC.OFAC_MAIN"/>
    <jdbc-version-ind type="state-image"/>
    <field name="callSign">
    <jdbc-field-map type="value" column="CALL_SIGN"/>
    </field>
    <field name="callSignMp1">
    <jdbc-field-map type="value" column="CALL_SIGN_MP1"/>
    </field>
    <field name="callSignMp2">
    <jdbc-field-map type="value" column="CALL_SIGN_MP2"/>
    </field>
    <field name="grt">
    <jdbc-field-map type="value" column="GRT"/>
    </field>
    <field name="id">
    <jdbc-field-map type="value" column="ID"/>
    </field>
    <field name="loadHistory">
    <jdbc-field-map type="one-one" column.LOAD_ID="LOAD_ID"/>
    </field>
    <field name="loadId">
    <jdbc-field-map type="value" column="LOAD_ID"/>
    </field>
    <field name="matchInfos">
    <jdbc-field-map type="one-many" ref-column.ID="ID"
    ref-column.LOAD_ID="LOAD_ID" table="OFAC.MATCH_INFO"/>
    </field>
    <field name="ofacAddress">
    <jdbc-field-map type="one-many" ref-column.ID="ID"
    ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ADDRESS"/>
    </field>
    <field name="ofacAlias">
    <jdbc-field-map type="one-many" ref-column.ID="ID"
    ref-column.LOAD_ID="LOAD_ID" table="OFAC.OFAC_ALIAS"/>
    </field>
    <field name="pName">
    <jdbc-field-map type="value" column="P_NAME"/>
    </field>
    <field name="pNameMp1">
    <jdbc-field-map type="value" column="P_NAME_MP1"/>
    </field>
    <field name="pNameMp2">
    <jdbc-field-map type="value" column="P_NAME_MP2"/>
    </field>
    <field name="program">
    <jdbc-field-map type="value" column="PROGRAM"/>
    </field>
    <field name="remarks">
    <jdbc-field-map type="value" column="REMARKS"/>
    </field>
    <field name="sName">
    <jdbc-field-map type="value" column="S_NAME"/>
    </field>
    <field name="sNameMp1">
    <jdbc-field-map type="value" column="S_NAME_MP1"/>
    </field>
    <field name="sNameMp2">
    <jdbc-field-map type="value" column="S_NAME_MP2"/>
    </field>
    <field name="sdnType">
    <jdbc-field-map type="value" column="SDN_TYPE"/>
    </field>
    <field name="ssn">
    <jdbc-field-map type="value" column="SSN"/>
    </field>
    <field name="title">
    <jdbc-field-map type="value" column="TITLE"/>
    </field>
    <field name="tonnage">
    <jdbc-field-map type="value" column="TONNAGE"/>
    </field>
    <field name="vesselFlag">
    <jdbc-field-map type="value" column="VESSEL_FLAG"/>
    </field>
    <field name="vesselOwner">
    <jdbc-field-map type="value" column="VESSEL_OWNER"/>
    </field>
    <field name="vesselOwnerMp1">
    <jdbc-field-map type="value" column="VESSEL_OWNER_MP1"/>
    </field>
    <field name="vesselOwnerMp2">
    <jdbc-field-map type="value" column="VESSEL_OWNER_MP2"/>
    </field>
    <field name="vesselType">
    <jdbc-field-map type="value" column="VESSEL_TYPE"/>
    </field>
    </class>
    </package>
    </mapping>
    Als, just for giggles, the JDO file
    <?xml version="1.0" encoding="UTF-8"?>
    <jdo>
    <package name="com.everbank.finance.ofac3.jdo.sdn">
    <class name="LoadHistory"
    objectid-class="com.everbank.finance.ofac3.jdo.LoadHistoryId">
    <field name="loadId" primary-key="true"/>
    <field name="ofacAddress">
    <collection element-type="OfacAddress"/>
    <extension vendor-name="kodo" key="inverse-owner"
    value="loadHistory"/>
    </field>
    <field name="ofacAlias">
    <collection element-type="OfacAlias"/>
    <extension vendor-name="kodo" key="inverse-owner"
    value="loadHistory"/>
    </field>
    <field name="ofacMains">
    <collection element-type="OfacMain"/>
    <extension vendor-name="kodo" key="inverse-owner"
    value="loadHistory"/>
    </field>
    <field name="runInfoLoadIdents">
    <collection
    element-type="com.everbank.finance.ofac3.jdo.match.RunInfoLoadIdent"/>
    <extension vendor-name="kodo" key="inverse-owner"
    value="loadHistory"/>
    </field>
    </class>
    <class name="OfacAddress"
    objectid-class="com.everbank.finance.ofac3.jdo.OfacAddressId">
    <field name="addressId" primary-key="true"/>
    <field name="loadId" primary-key="true"/>
    </class>
    <class name="OfacAlias"
    objectid-class="com.everbank.finance.ofac3.jdo.OfacAliasId">
    <field name="aliasId" primary-key="true"/>
    <field name="loadId" primary-key="true"/>
    </class>
    <class name="OfacMain"
    objectid-class="com.everbank.finance.ofac3.jdo.OfacMainId">
    <field name="id" primary-key="true"/>
    <field name="loadId" primary-key="true"/>
    <field name="matchInfos">
    <collection
    element-type="com.everbank.finance.ofac3.jdo.match.MatchInfo"/>
    <extension vendor-name="kodo" key="inverse-owner"
    value="ofacMain"/>
    </field>
    <field name="ofacAddress">
    <collection element-type="OfacAddress"/>
    <extension vendor-name="kodo" key="inverse-owner"
    value="ofacMain"/>
    </field>
    <field name="ofacAlias">
    <collection element-type="OfacAlias"/>
    <extension vendor-name="kodo" key="inverse-owner"
    value="ofacMain"/>
    </field>
    </class>
    </package>
    Greg Campbell wrote:
    Hi Tim,
    Could you send the your mapping information corresponding to the class that
    maps to table: OFAC_ADDRESS. In particular, I'm looking for what fields
    map to OFAC_ADDRESS.LOAD_ID. This will hopefully give us a hint as to
    what's going wrong.
    Thanks,
    Greg
    "Tim Holloway" <[email protected]> wrote in message
    news:[email protected]...
    I have a situation where I'm trying to assemble a web of data and not make
    JDO mad.
    <snipped>

Maybe you are looking for