Creating Column in table or use Foreign Key

I have a bunch of tables that are year specific, so I need to store the year in the record. I'm not sure if I should create a column in each table called 'year' or create a master 'Year' table and use a foreign key to it in all my other tables. Any advice?
PK_ID NUMBER Constraint pk1
PRIMARY KEY
YEAR VARCHAR2(4)
--- or----
PK_ID NUMBER Constraint pk1
PRIMARY KEY
FK_YEAR NUMBER Constraint fk_year
REFERENCES year_table(PK_ID)

Does your "year" entity have any attributes ?
Why do you have a year, which to most people seems to be a number, stored as a varchar2(4) ? And what are you going to do about the Y10K problem ?
How about making the ID of year the numeric value of the year you are storing - then you have eat your cake and have it ;)
Seriously, though, why do you want a table to say that the year 2008 is the year identified by a meaningless unique number ?
Regards
Jonathan Lewis
http:/jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk

Similar Messages

  • How we relate two tables using foreign key(fk)?

    hi to all,
        what are the conditions has to follow to relate two tables.I.e.,
    the two tables have same primary keys(pk). if we relate these two tables in one table the pk and fk will be the same then how that table in active.

    Hi
    To relate two tables..we have foreign key relationship.
    In one table v have primary key and in the second table, the same key is foreign key for that table..
    To relate two tables, we can use JOINS
    If there is already a suitable foreign key between two tables used in the view, these tables can be linked with a join condition from this foreign key.
    Create a view on tables TAB1 and TAB2. TAB1 is the primary table of the view. TAB2 is the secondary table of the view. TAB1 is the check table for TAB2. The foreign key fields are assigned to the check table fields as follows:
    TAB1-FIELD_A assigned to TAB2-FIELD_1
    TAB1-FIELD_A assigned to TAB2-FIELD_1
    The join condition of the view generated from the foreign key is then:
    CREATE VIEW ... AS SELECT ... WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = TAB1-FIELD_B.
    Join conditions can also be copied from generic and constant foreign keys. If a constant is assigned to a field in the foreign key, it is also assigned to the field in the join condition. There is no join condition for a generic relationship in the foreign key.
    The foreign key between tables TAB1 (check table) and TAB2 (foreign key table) is defined as follows:
    TAB1-FIELD_A assigned to TAB2-FIELD_1
    TAB1-FIELD_B generic
    TAB1-FIELD_C assigned to constant ‘C’
    The join condition for the view generated from the foreign key is in this case:
    CREATE VIEW ... AS SELECT ... WHERE TAB2-FIELD_1 = TAB1-FIELD_A AND TAB2-FIELD_2 = ‘C’.
    Hope it helps
    Reward if useful.

  • How to insert data into two tables linke with foreign key..

    I have two tables
    1)EMP(emp_ID,username,emp_type_code)
    emp_ID is primary key, emp_type_code is a foreign key references emptype table.
    2)emptype(emp_type_code,emp_type_descripton)
    emp_type_code is primary key
    Could anyone help me ..how to insert data into EMP table. How to insert data into two tables linke with foreign key..

    CREATE TABLE "CATDB"."DWDIMUSER"
    "USER_ID" NUMBER(10,0) NOT NULL ENABLE,
    "SPECIALTY_ID" NUMBER(10,0),
    "FULLNAME" VARCHAR2(20 BYTE),
    "FNAME" VARCHAR2(20 BYTE),
    "LNAME" VARCHAR2(20 BYTE),
    "USER_SUBTYPE" VARCHAR2(20 BYTE),
    CONSTRAINT "DIMUSER_PK" PRIMARY KEY ("USER_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE,
    CONSTRAINT "DIMUSER_DIMSPECIALTY_FK" FOREIGN KEY ("SPECIALTY_ID") REFERENCES "CATDB"."DWDIMSPECIALTY" ("SPECIALTY_ID") DISABLE
    CREATE TABLE "CATDB"."DIMSPECIALTY"
    "SPECIALTY_ID" NUMBER(10,0) NOT NULL ENABLE,
    "SPECIALTY_NAME" VARCHAR2(100 BYTE),
    CONSTRAINT "DIMSPECIALTY_PK" PRIMARY KEY ("SPECIALTY_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE
    INSERT INTO DIMUSER (FullName, FNAME, LNAME, USER_TYPE, USER_SUBTYPE)
    SELECT DISTINCT
    Engineer AS FullName,
    regexp_substr(Engineer , '[^,| ]+', 1, 1) as FName,
    regexp_substr(Engineer , '[^,| ]+', 1, 2) as LName ,
    'Engineer'
    FROM EMPLOYEELOOKUP;
    INSERT INTO DIMSPECIALTY (SPECIALTY_NAME)
    SELECT DISTINCT SPECIALITY
    FROM EMPLOYEELOOKUP;
    COMMIT;
    CREATE TABLE employeelookup ...IS A TABLE THAT HAS ALL THE DATA NEDED TO BE FILLED IN BOTHE TABLES...
    CREATE TABLE "CATDB"."EMPLOYEELOOKUP"
    "EMPLOYEELOOKUP_ID" NUMBER(10,0) NOT NULL ENABLE,
    "ENGINEER" VARCHAR2(25 BYTE),
    "SPECIALTY" VARCHAR2(20 BYTE),
    CONSTRAINT "DIMSPECIALTY_PK" PRIMARY KEY ("EMPLOYEELOOKUP_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE
    DATA IN EMPLOYEELOOKUP
    Engineer, Specialty,
    John, Dow, Electronis,
    Dow, Jons, Technician
    Stan Smithers Sales
    Mark, Richards Marketing
    Jenny, Lane Marketing
    John, Lee Sales
    I NEED TO LOAD THE FOREIGN KEY IN DIMUSER FROM THE DIMSPECIALTY TABLE?
    BY USING THE LOOKUP TABLE TO MARCH THE NAMES UNDER THE Engineer COLUMN, SPECIALTY COLUMNE DISTICTIVLY BY JOINING THE DIMSPECILTY TO RISTIVE THE PRIMARY KEY AND FILL IT IN THE DIMUSER TABLE AS A FOREIGNE KEY.

  • Not use foreign keys.

    I would like to know if is it bad if I don't want to use foreign keys? is it just a constraint? Is it useful? If I wont use delete on cascade for example is it mandatory to use foreign keys? Please help me with this doubt.
    Thanks.

    A Small example:
    DROP TABLE T_TABLES ;
    CREATE TABLE T_TABLES AS
    SELECT ROWNUM AS ID, OWNER, TABLE_NAME
    FROM   ALL_TABLES;
    ALTER TABLE T_TABLES ADD CONSTRAINTS PK_TABLES PRIMARY KEY(ID);
    DROP TABLE T_TABLE_COLUMNS ;
    CREATE TABLE T_TABLE_COLUMNS AS
      SELECT T.ID, TC.OWNER, TC.TABLE_NAME, TC.COLUMN_NAME, TC.DATA_TYPE
      FROM   ALL_TAB_COLS TC
               JOIN T_TABLES T ON (T.OWNER = TC.OWNER AND T.TABLE_NAME = TC.TABLE_NAME)
      WHERE  T.TABLE_NAME NOT IN ('T_TABLES', 'T_TABLE_COLUMNS'); -- EXCEPT THESE TWO TABLES
    EXPLAIN PLAN FOR
    SELECT *
    FROM   T_TABLE_COLUMNS
    WHERE  ID IN (SELECT ID FROM T_TABLES);
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
    | Id  | Operation          | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |                 | 27823 |  3586K|    63   (7)| 00:00:01 |
    |   1 |  NESTED LOOPS      |                 | 27823 |  3586K|    63   (7)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| T_TABLE_COLUMNS | 27823 |  3233K|    60   (2)| 00:00:01 |
    |*  3 |   INDEX UNIQUE SCAN| PK_TABLES       |     1 |    13 |     0   (0)| 00:00:01 |
    --ADD FOREIGN KEY
    ALTER TABLE T_TABLE_COLUMNS ADD CONSTRAINT FK_TABLES FOREIGN KEY(ID) REFERENCES T_TABLES(ID);
    -- SAME QUERY AGAIN
    EXPLAIN PLAN FOR
    SELECT *
    FROM   T_TABLE_COLUMNS
    WHERE  ID IN (SELECT ID FROM T_TABLES);
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
    -- NO JOIN ANYMORE
    | Id  | Operation         | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |                 | 27823 |  3233K|    60   (2)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| T_TABLE_COLUMNS | 27823 |  3233K|    60   (2)| 00:00:01 |
    -------------------------------------------------------------------------------------FKs can even save you from joins.

  • Database adapter - table related by foreign key - not picking

    Hi All,
    we have a Invoke which picks data from database by using the query feature(not polling) of db adapter.
    we are picking data from multiple tables.
    there is foreign key relation between tables,which we have defined at the db adapter.
    Parent - > child 1
    > child 2 > child 3
    > child 4 > child 5
    So we have a case where parent has 3 rows but children tabls have 3000+.
    This error is happening in such cases.
    Please let me know.
    <2009-08-06 16:58:54,833> <ERROR> <default.collaxa.cube.engine> The execution of this instance "90045" for process "XXSOA_ESP4G_ROUT_ABC_SRC" is supposed to be in a jta transaction, but the transaction is not present or in active state, please turn on the application server transaction debug logs to get more information.
    <2009-08-06 16:58:54,842> <WARN> <default.collaxa.cube> <BaseCubeSessionBean::logError> Error while invoking bean "activity manager": Failed due to unhandled bpel fault.
    <2009-08-06 16:58:54,852> <ERROR> <default.collaxa.cube.engine.dispatch> <DispatchHelper::handleMessage> failed to handle message
    ORABPEL-02182
    JTA transaction is not present or the transaction is not in active state.
    The current JTA transaction is not present or it is not in active state when processing activity or instance "90,045". The reason is The execution of this instance "90045" for process "XXSOA_ESP4G_ROUT_ABC_SRC" is supposed to be in a jta transaction, but the transaction is not present or in active state, please turn on the application server transaction debug logs to get more information..
    Please consult your administrator regarding this error.
         at com.collaxa.cube.engine.CubeEngine.store(CubeEngine.java:5514)
         at com.collaxa.cube.engine.CubeEngine.endRequest(CubeEngine.java:5799)
         at com.collaxa.cube.engine.CubeEngine.expireActivity(CubeEngine.java:2086)
         at com.collaxa.cube.ejb.impl.ActivityManagerBean.expireActivity(ActivityManagerBean.java:174)
         at com.collaxa.cube.ejb.impl.ActivityManagerBean.expireActivity(ActivityManagerBean.java:145)
         at sun.reflect.GeneratedMethodAccessor76.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.evermind.server.ejb.interceptor.joinpoint.EJBJoinPointImpl.invoke(EJBJoinPointImpl.java:35)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
         at com.evermind.server.ejb.interceptor.system.JAASInterceptor$1.run(JAASInterceptor.java:31)
         at com.evermind.server.ThreadState.runAs(ThreadState.java:693)
         at com.evermind.server.ejb.interceptor.system.JAASInterceptor.invoke(JAASInterceptor.java:34)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
         at com.evermind.server.ejb.interceptor.system.TxRequiredInterceptor.invoke(TxRequiredInterceptor.java:50)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
         at com.evermind.server.ejb.InvocationContextPool.invoke(InvocationContextPool.java:55)
         at com.evermind.server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:87)
         at ActivityManagerBean_LocalProxy_4bin6i8.expireActivity(Unknown Source)
         at com.collaxa.cube.engine.dispatch.message.instance.ExpirationMessageHandler.handle(ExpirationMessageHandler.java:43)
         at com.collaxa.cube.engine.dispatch.DispatchHelper.handleMessage(DispatchHelper.java:141)
         at com.collaxa.cube.engine.dispatch.BaseDispatchTask.run(BaseDispatchTask.java:58)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
         at java.lang.Thread.run(Thread.java:595)
    <2009-08-06 16:58:54,853> <ERROR> <default.collaxa.cube.engine.dispatch> <DispatchHelper::handleMessage> Not fatal connection error ... not retrying: class com.collaxa.cube.engine.UnhandledFaultException: Failed due to unhandled bpel fault.
    <2009-08-06 16:58:54,854> <ERROR> <default.collaxa.cube.engine.dispatch> <BaseDispatchTask::run> Failed to handle dispatch message ... exception ORABPEL-05002
    Message handle error.
    An exception occurred while attempting to process the message "com.collaxa.cube.engine.dispatch.message.instance.ExpirationMessage"; the exception is: JTA transaction is not present or the transaction is not in active state.
    The current JTA transaction is not present or it is not in active state when processing activity or instance "90,045". The reason is The execution of this instance "90045" for process "XXSOA_ESP4G_ROUT_ABC_SRC" is supposed to be in a jta transaction, but the transaction is not present or in active state, please turn on the application server transaction debug logs to get more information..
    Please consult your administrator regarding this error.
    ORABPEL-05002
    Message handle error.
    An exception occurred while attempting to process the message "com.collaxa.cube.engine.dispatch.message.instance.ExpirationMessage"; the exception is: JTA transaction is not present or the transaction is not in active state.
    The current JTA transaction is not present or it is not in active state when processing activity or instance "90,045". The reason is The execution of this instance "90045" for process "XXSOA_ESP4G_ROUT_ABC_SRC" is supposed to be in a jta transaction, but the transaction is not present or in active state, please turn on the application server transaction debug logs to get more information..
    Please consult your administrator regarding this error.
         at com.collaxa.cube.engine.dispatch.DispatchHelper.handleMessage(DispatchHelper.java:206)
         at com.collaxa.cube.engine.dispatch.BaseDispatchTask.run(BaseDispatchTask.java:58)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
         at java.lang.Thread.run(Thread.java:595)

    Also for above issue , we increased the timeout in transaction manager
    transaction-timeout and syncMaxWaitTime properties as follows:
    Property     File Location     This Value Must Be...     Example
    transaction-timeout     SOA_Oracle_Home\j2ee\home\config\transaction-manager.xml     Larger than the transaction-timeout value in orion-ejb-jar.xml and the syncMaxWaitTime value.     7200
    transaction-timeout     SOA_Oracle_Home\j2ee\home\application-deployments\orabpel\ejb_ob_engine\orion-ejb-jar.xml     Less than the transaction-timeout value in transaction-manager.xml.
    Note: You must set all transaction-timeout properties that display in this file.     3600
    syncMaxWaitTime     SOA_Oracle_Home\bpel\domains\domain_name\config\domain.xml
    where domain_name is the name of the domain to which you are deploying.     Less than the transaction-timeout value in orion-ejb-jar.xml.     240
    2.     
    The above refernece was useful in resolcing our issue.
    Regards
    Arc

  • Access table cells using tab key with iterators

    Hi,
    I use a tableview with iterator and allow users to mouseclick certain column cells. I capture these user interactions using server event "onCellClick". But I cannot access these cells using tab key instead of mouse click. But tab key is a must for visibly challenged users.      Is there any way to access table cells using tab keys (with iterators)?
    I use icons in those cells to replace  check box and change the icons to differentiate checked/unchecked status.

    Hi Craig,
    Thanks for your effort.
    But I was able to solve my problem. I don't think I gave all the information to simulate my problem in your environment. I used images in certain table cells and was not able to access those cells using tab key or access key. Tag <b><img></b> doesn't have the attributes <b>tabindex</b> and <b>access key</b>.
    I solved the problem by surrounding the <b><img></b> by anchor tag <<b>A>,</b> which has both attributes. I did these changes within the iterator method <b>RENDER_CELL_START</b> using CL_BSP_BEE_TABLE.
    In the event handling, I had to do separate processing for  mouse click event and key press event for those cells.
    For visibly challenged users:
    They can access those cells by tab key or access key and the key press event is used to capture when they hit enter key.
    So this problem is irrelevant to service packages (SP38,..).

  • Cannot solve ORA-30756 "cannot create column or table of type that..."

    Hi there!
    I'm working on some excersises for the university but just can't get rid of this error.
    First, here's my SQL:
    [http://pastebin.com/f1266a668]
    And here is what I get:
    TYPE "LieferserviceTyp" Kompiliert.
    TYPE "ArtikelTyp" Kompiliert.
    TYPE "LebensmittelTyp" Kompiliert.
    TYPE "HaushaltswarenTyp" Kompiliert.
    TYPE "ArtikelInArtKombiTyp" Kompiliert.
    TYPE "ArtikelKombiTyp" Kompiliert.
    TYPE "ArtikelInKatalogTyp" Kompiliert.
    TYPE "KatalogTyp" Kompiliert.
    Fehler beim Start in Zeile 60 in Befehl:
    CREATE TABLE "Artikel" OF "ArtikelTyp" (
    PRIMARY KEY("artnr")
    Fehler bei Befehlszeile:60 Spalte:0
    Fehlerbericht:
    SQL-Fehler: ORA-30756: Spalte oder Tabelle mit einem Objekttyp, der ein Supertyp-Attribut enthält, kann nicht erstellt werden
    30756. 00000 - "cannot create column or table of type that contains a supertype attribute"
    *Cause:    The user tried to create a column or table of an object type that
    contains a supertype attribute. This is not supported because
    it leads to infinite recursion in our current storage model.
    Note that creating a column of a type implies that we
    create columns corresponding to all subtype attributes as well.
    *Action:   Change the type definition to contain a supertype REF attribute
    instead of the supertype object attribute.
    Fehler beim Start in Zeile 67 in Befehl:
    CREATE TABLE "Kataloge" OF "KatalogTyp" (
    PRIMARY KEY("katalog_id")
    Fehler bei Befehlszeile:67 Spalte:0
    Fehlerbericht:
    SQL-Fehler: ORA-30756: Spalte oder Tabelle mit einem Objekttyp, der ein Supertyp-Attribut enthält, kann nicht erstellt werden
    30756. 00000 - "cannot create column or table of type that contains a supertype attribute"
    *Cause:    The user tried to create a column or table of an object type that
    contains a supertype attribute. This is not supported because
    it leads to infinite recursion in our current storage model.
    Note that creating a column of a type implies that we
    create columns corresponding to all subtype attributes as well.
    *Action:   Change the type definition to contain a supertype REF attribute
    instead of the supertype object attribute.
    Fehler beim Start in Zeile 76 in Befehl:
    DROP TABLE "Artikel"
    Fehlerbericht:
    SQL-Fehler: ORA-00942: Tabelle oder View nicht vorhanden
    00942. 00000 - "table or view does not exist"
    *Cause:   
    *Action:
    Fehler beim Start in Zeile 77 in Befehl:
    DROP TABLE "Kataloge"
    Fehlerbericht:
    SQL-Fehler: ORA-00942: Tabelle oder View nicht vorhanden
    00942. 00000 - "table or view does not exist"
    *Cause:   
    *Action:
    DROP TYPE "KatalogTyp" erfolgreich.
    DROP TYPE "ArtikelInKatalogTyp" erfolgreich.
    DROP TYPE "ArtikelKombiTyp" erfolgreich.
    DROP TYPE "ArtikelInArtKombiTyp" erfolgreich.
    DROP TYPE "HaushaltswarenTyp" erfolgreich.
    DROP TYPE "LebensmittelTyp" erfolgreich.
    DROP TYPE "ArtikelTyp" erfolgreich.
    DROP TYPE "LieferserviceTyp" erfolgreich.
    The comments are in german but the structure should be clear I think.
    Any help appreciated!

    Unfortunately it's a bad idea to store your code samples (or screenshots or whatever) on an external site, because not everybody can get access to such sites, especially if their workplace has limitations on websites that can be visited.
    you're pastebin.com is one such site that I cannot access, so I can't see your code.
    If you want to paste code and/or data on the forums remember to put the tag: {noformat}{noformat} before _and_ after it, so that the formatting is maintained and it's easier for us to read.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Performance degradation when using foreign keys

    Hi,
    I face drastic performance degradation when I add foreign keys to a table and perform insert / update on that table.
    I have a row store table to  which I need to insert around 1,50,000 records.
    If the table has no foreign key reference it takes maximum of 5 seconds but if the same table has references to other tables (in my case there are 3 references), the processing speed reduces drastically to 2 minutes.
    Is there any solution / best practice that can help me in gaining performance (processing speed) in this situation?
    Thanks
    S.Srivatsan

    Hi Sri,
    When you perform one insert in any database table which is having foreign key relationships, it will check the corresponding parent tables to check whether the master data is available or not. If your table is having 2 foreign key relationship, it happen twice per insert. Hence the performance will degrade. This is one of the reasons why ECC  doesn't establish foreign key relationship in the back end database. The case is not just for INSERT, for UPDATE & DELETE the same is applicable.
    Sreehari

  • How to fetch column data using foreign key in adf table ?

    I have created a adf table using a view that has a group id and user id column. I want to display the user name ( from user table) and group name from group table. I had created view links to the corresponding tables from the user_group view ( whose iterator is used to render the table).
    It sort of works. I dragged the user name from the embedded user iterator in user_group iterator. It does find the correct user name but if I have more than one row, it displays the user name of the last row user in all rows !
    Is there a solution to this problem ?

    Well, I saw in the view query for the association view ( for Many-Many) that the SQL already had the joins with the two ( master) tables to the association table. So I went ahead and added the descriptive columns to the select clause. Then the selected columns showed up in the attribute list by themselves ( without my intervention). So far so good.
    Then I recreated the adf table attribute by dragging these newly selected attribute to the page. I still see that the value of the attribute is the same in all the rows - this time it is the value for the FIRST row. It doesn't correspond to the foreign key for that particular row.
    IS THIS A BUG ? Has anyone else ever done this ?

  • Binding for table produces list for other tables using foreign key and crea

    Using
    software Jdev 11G, WLS 11G, Oracle DB 11G, Windows Vista platform
    technology EJB 3.0, jspx, backing beans, session bean
    I cannot create a namedquery on my secondary table. The method for the column uses the entity object rather than the name and value of the column.
    For instance,
    (Coketruck) table has inventory records(Products) table
    Coketruck has one to many to the Products table
    Products has a many to one to the Coketruck
    I need to return the products from the product table based on the CokeTruck but I cannot create a namedQuery because the method in the Product table is an entity object type instead of a long that I can use to look up all the products based off the column truck_id.
    This is what I was expecting…
    Private Long truckId;
    public Long getTruckId() {
    return truckId;
    public void setTruckId (Long truckId) {
    this. truckId = truckId;
    Instead this is what I have…
    @ManyToOne
    @JoinColumn(name = "TRUCK_ID")
    private Coketruck coketruck;
    this. coketruck = coketruck
    public Coketruck getCoketruck() {
    return coketruck;
    public void set Coketruck (Coketruck coketruck) {
    this. coketruck = coketruck;
    How do I do a query on the Product table to return all the products that are in the coketruck?
    If I do the following it expects for me to pass the Entity Object which I cannot use as search criteria for my find method.
    @NamedQuery(name = "Products.findById", query = "select o from Products o where o.truckId = :truckId")
    On a different note but the same song…
    I noticed that when I look at my Session Bean Data Contols that the coketruck already has a list of the products. I have created a jsp page with a backing bean and have been able to use the namedquery on the coketruck entity to retrieve the productList. Unfortunately I need to sort the products by type and was also not able to find where to perform the work to be able to iterate through the productList to get my desired display. Therefore I started looking at doing another namedquery that would only retrieve the product_type ordering by the truckId.
    Seems I have come full circle… I don’t care what method I have to use to get the info back.
    Any help is greatly appreciated!

    user9005175 wrote:
    Hi!
    I work on an application wich uses a shopping cart stored in a database. The shopping cart uses two tables:
    CART: Holds information common for one shopping cart: the user it is connected to etc.
    - Primary key: CART_ID
    CART_ROW: One row in the cart, e.g. one new product to buy.
    - Primary key: ROW_ID
    - Foreign key: CART_ROW.CART_ID references CART.CART_ID
    From the code the rows in the cart are collected per cart, as is modelled by the foreign key. There exists one more relationship, which we use in the code, but which is not modelled by a foreign key in the database. One row can be dependent on another row, which makes the other row a parent.
    CART_ROW has a column PARENT_ID which references CART_ROW.ROW_ID.
    Should we add a foreign key for PARENT_ID? Or are there any questions to consider when it is a foreign key to the same table?
    I suggest to add foreign key it wont harm the performance (except while on insert when there would be validation for the foreign key). But it would prevent users to insert wrong/corrupt data either through code or directly by loggin in the database.
    A while ago we added indexes, both on ROW_ID and on PARENT_ID. Could the index on PARENT_ID have been harmful, since there is no foreign key?
    Index on parent_id would only be harmful if you do not make use of index after creating it (i.e. there is no query which make use of this index).
    And if you decide to have a foreign key on parent_id then I suggest to have index too on parent_id as it would be helpful atleast when you delete any record in this table.
    Best regards!

  • Two columns in the same table that are foreign keys to the same master key

    i want to create a table let say X, which have two columns that are foreign key that reference the same column in the master table, so does this count as bad database design.

    here is the full ddl for the two table, where in the second table there are two columns that represent the primary key and they are also two foreign keys to the same columns in the master table (items)
    Desc item table;
    Item_id
    Item_name
    Item_price
    Item_quantitiy
    Create table item_recommendation ( item_id varchar(20), recommended_item varchar(20),
    CONSTRAINT recom_primary PRIMARY KEY (item_id, recommended_item),
    CONSTRAINT F1 FOREIGN KEY (item_id) REFERENCES items(item_id), ),
    CONSTRAINT F2 FOREIGN KEY (recommended_item) REFERENCES items(item_id));

  • 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

  • Table with n foreign key vs n tables or n foreign key vs 1 table?

    Hi,
    we have a scenario with n tables containing some attributes one table for one category of attribute (es: color, role, type, etc..) of a principal entity and 1 table for the principal entity with n foreign keys vs every attribute table.
    Some propose to create a unique table called attributes in which put every attribute with an attributetype for each record.
    My question is: the principal entity will have n foreign keys vs the same attribute table. Is this perfomant? which is the best solution?
    Thanks in advance.
    v.

    >
    we have a scenario with n tables containing some attributes one table for one category of attribute (es: color, role, type, etc..) of a principal entity and 1 table for the principal entity with n foreign keys vs every attribute table.
    Some propose to create a unique table called attributes in which put every attribute with an attributetype for each record.
    My question is: the principal entity will have n foreign keys vs the same attribute table. Is this perfomant? which is the best solution?
    >
    Ask those 'Some propose' how a foreign key to the 'same attribute table' will prevent the WRONG value from being used for a column.
    1. Principal entity has a column for 'color' and a column for 'role'.
    2. There are FKs on the 'color' column and the 'role' column that both point to the 'same attribute table'
    3. Legal values for 'color' are: 1, 2, 3
    4. Legal values for 'role' are: 10, 20, 30
    What prevents someone from updating the 'color' column to a value of 20?
    Ask those 'Some propose' how your one attribute table will store attributes that are of different datatypes.
    1. 'color' uses numbers: 1, 2, 3
    2. 'type' uses strings: 'type1', 'type2', 'type3'
    3. 'holiday' uses dates: 12/25/2013, 01/01/2014
    How do your 'Some propse' plan to store ALL of those values in one column? They are likely to say they will use VARCHAR2.
    Ok - so how do you keep someone from updating 'holiday' to a value of 'type2' or a value of '3'?
    You can't easily validate the data to begin with and you can't easily prevent 'dirty' data from getting into the system.
    You also can't easily explain to ANYONE, for example new developers, how to properly use and maintain the table.
    I haven't heard you mention even ONE potential benefit to doing things the way that 'Some propose'. So - DON'T DO THAT!

  • How can I have multiple instances of a column that itself holds a foreign key reference?

    I am new to Visual Studio so to start learning it I first of all downloaded a sample available at https://code.msdn.microsoft.com/ADPNET-Entity-Framework-2d1160cb and started working around it. Since I have fairly good knowledge of VB6 and SQL it did
    not take much time for me to understand the whole pattern the sample is based on. Had Microsoft given a detail explanation or a walk through of the sample it would have been much easier to understand the basics. However, I somehow managed to work around it
    and have build a small desktop application in wpf using Entity Framework and MVVM. But a point has come where I have got completely stuck up finding no way out. The problem is as under:
    I have two tables. 1 Advocate and 2 Party. Table Advocate would contain names of advocates and would have a primary key. Similarly Party would have names and their respective primary keys.
    Then I have another two tables 1. Case and 2 CaseDetail. Table Case would simply hold three columns: 1. CaseId 2. CaseNo and 3. Year. Table CaseDetail would have CaseDetailId as a primary key the CaseId as a Foreign Key. Now what I need is that a particular
    case could have multiple advocates and multiple petitioners. So the table CaseDetail would have two columns to hold advocateId and PartyId as a Foreign Keys. 
    If you look at the sample referred above you would not find how to deal with such a case. When I follow the pattern of the sample I get host of design time and runtime errors. 
    Therefore, please suggest what strategy should be adopted in a scenario described above while developing WPF application using Entity Framework and MVVM.

    I am new to Visual Studio so to start learning it I first of all downloaded a sample available at https://code.msdn.microsoft.com/ADPNET-Entity-Framework-2d1160cb and started working around it. Since I have fairly good knowledge of VB6 and SQL it did not
    take much time for me to understand the whole pattern the sample is based on. Had Microsoft given a detail explanation or a walk through of the sample it would have been much easier to understand the basics. However, I somehow managed to work around it and
    have build a small desktop application in wpf using Entity Framework and MVVM. But a point has come where I have got completely stuck up finding no way out. The problem is as under:
    I have two tables. 1 Advocate and 2 Party. Table Advocate would contain names of advocates and would have a primary key. Similarly Party would have names and their respective primary keys.
    Then I have another two tables 1. Case and 2 CaseDetail. Table Case would simply hold three columns: 1. CaseId 2. CaseNo and 3. Year. Table CaseDetail would have CaseDetailId as a primary key the CaseId as a Foreign Key. Now what I need is that a particular
    case could have multiple advocates and multiple petitioners. So the table CaseDetail would have two columns to hold advocateId and PartyId as a Foreign Keys. 
    If you look at the sample referred above you would not find how to deal with such a case. When I follow the pattern of the sample I get host of design time and runtime errors. 
    Therefore, please suggest what strategy should be adopted in a scenario described above while developing WPF application using Entity Framework and MVVM.

  • Copying tables that have Foreign Keys

    All my tables are using primary/foreign keys. If you look at the example below, I have a table 'stu_school' which has 3 foreign keys (FK_YEAR,FK_SCHOOL,FK_GRADE_LEVEL) pointing to 3 other tables. Every year I need to create a new record in the year table and copy the data from the previous year (with the FK_YEAR value) into the new year. Is there a better approach to moving this data over other than manually writing SQL statements and making sure they are done in the correct order (becuase of the keys).
    stu_school
    PK_ID
    FK_YEAR
    FK_SCHOOL
    FK_GRADE_LEVEL
    year
    PK_ID
    YEAR
    school
    PK_ID
    SCHOOL
    grade_level
    PK_ID
    FK_YEAR
    FK_SCHOOL
    GRADE_LEVEL

    Since this is going to be an annual task and should therefore be part of the application I suggest writing a pl/sql script that performs the necessary actions rather than use sql to generate the sql to perform the action. A pl/sql script would allow better activity logging and error handling appropriate for a repeating production task.
    IMHO -- Mark D Powell --

Maybe you are looking for

  • Apple reset screen turns on and off.

    I had my iPod plugged to my home stereo (via headphone jack). I was playing some songs to practice with my instrument. I needed to upload another song so I unplugged it from the stereo and connected it to my PC. When it sync'ed with iTunes, it detect

  • File Upload and Reading from Ex cel

    Hi ALL, In my jsp page I have the file form field (input type=file) by which i browse for a excel file in local system and when i select the file and clicks on the submit button. The excel file should be uploaded to server and at the same time the co

  • Is it true that iPhone 4s for Malaysia will not have "siri"?

    Well, iphone 4s is going to hit the Malaysian markets on 16 December, but i have noticed that it doesn't have Siri. Is it True?

  • Cannot telnet into router

    What do I do when all of a sudden I can't telnet into my router through any interfaces? I can ping the interfaces successfully, by IP and DNS name. Nothing has changed since the last successful login. error msg: Connecting To c3640...Could not open c

  • Premiere Pro 7.0 dropping random frames from original video

    Here is one of many problems I am running into. When I import original video into Adobe Premiere Pro 7.0 it always leaves out a few frames in random spots scattered throughout a clip (I'm guessing this is what is referred to as dropped frames). I fir