Two column primary keys

Hello,
I am using two columns for my primary key. However when I crate a report and form pages, it doesn't work. The report page shows up but when I click on the edit icon next to each record it gives an error message.

Zahid Khan wrote:
Hi User (very common name!),
In the following simple page I am using empno and hiredate columns as primary key:
http://apex.oracle.com/pls/otn/f?p=9396:10
It would be easier to help you if you set up an example on OTN.
Thanks,
ZahidDear Zahid,
I looked at the application example you provided and the way the trigger ensures the trunc function is called on the date field before writing it to the db table, so the date retrieved from the db looks exactly the same as the date inserted.
CREATE TABLE "EMP_DATE_KEY"
(     "EMPNO" NUMBER,
     "ENAME" VARCHAR2(10),
     "HIREDATE" DATE,
     "SAL" NUMBER,
     "DEPTNO" NUMBER,
     CONSTRAINT "PK_EMP_DATE_KEY" PRIMARY KEY ("EMPNO", "HIREDATE") ENABLE
CREATE OR REPLACE TRIGGER "BIUD_EMP_DATE_KEYS"
before insert on emp_date_key
for each row
begin
select nvl(max(empno),0)+1, trunc(sysdate)
into :new.empno, :new.hiredate from emp_date_key;
end;
ALTER TRIGGER "BIUD_EMP_DATE_KEYS" ENABLE
Line: --------
However the database I am dealing with has not used the trunc function when creating the date field values and the primary key, by the way this db is very old and has a lot of data in it.
any suggestions?
Thanks,
user

Similar Messages

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

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

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

  • Fast Refresh using two non-primary key tables

    Hi,
    I have a materialized view based on two tables with an outer join clause. Both the tables do not have a primary key so I had created materialized view log with row-id on each of them but still I am not able to bring out the fast refresh option for the materialized view. My question is can I have a fast refresh option for materialized view built from two tables without primary keys and having an outer join clause????. If possible please send me some sample scripts for quicker understanding.
    Thanks and Regards,
    Sudhakar

    I was able to create a fast-refreshable MV, on tables without any PK. Unfortunately, I can't complete all the steps since my setup is a multi-master advanced replication (which ABSOLUTELY requires the tables to have PK's). Here are anyway the steps I took. Note that ORA102 is my (definition) master site, and MVDB is my MV site. The tables were created under user HR, and my master group is called "hr_repg". Here are my steps:
    HR on ora102 >create table countries_no_pk as select * from countries;
    Table created.
    HR on ora102 >create table regions_no_pk as select * from regions;
    Table created.
    HR on ora102 >create materialized view log on countries_no_pk with rowid;
    Materialized view log created.
    HR on ora102 >create materialized view log on regions_no_pk with rowid;
    Materialized view log created.
    REPADMIN on ora102 >exec dbms_repcat.suspend_master_activity('hr_repg')
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.68
    REPADMIN on ora102 >BEGIN
    2 DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
    3 gname => 'hr_repg',
    4 type => 'TABLE',
    5 oname => 'countries_no_pk',
    6 sname => 'hr',
    7 use_existing_object => TRUE,
    8 copy_rows => FALSE);
    9 END;
    10 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:05.19
    REPADMIN on ora102 >set timing off
    REPADMIN on ora102 >BEGIN
    2 DBMS_REPCAT.CREATE_MASTER_REPOBJECT (
    3 gname => 'hr_repg',
    4 type => 'TABLE',
    5 oname => 'regions_no_pk',
    6 sname => 'hr',
    7 use_existing_object => TRUE,
    8 copy_rows => FALSE);
    9 END;
    10 /
    PL/SQL procedure successfully completed.
    (note that you ABSOLUTELY need the rowid's in your select statement for an MV with joins):
    MVIEWADMIN on mvdb >CREATE MATERIALIZED VIEW hr.complex_mv refresh fast as
    2 select c.rowid "C_ROW_ID", r.rowid "R_ROW_ID", c.COUNTRY_ID, c.COUNTRY_NAME,
    3 c.REGION_ID, r.REGION_NAME from hr.regions_no_pk@ora102 r, hr.countries_no_pk@ora102 c
    4 where c.region_id = r.region_id (+);
    Materialized view created.
    MVIEWADMIN on mvdb >BEGIN
    2 DBMS_REPCAT.CREATE_MVIEW_REPOBJECT (
    3 gname => 'hr_repg',
    4 sname => 'hr',
    5 oname => 'complex_mv',
    6 type => 'SNAPSHOT',
    7 min_communication => TRUE);
    8 END;
    9 /
    PL/SQL procedure successfully completed.
    REPADMIN on ora102 >BEGIN
    2 DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT (
    3 sname => 'hr',
    4 oname => 'countries_no_pk',
    5 type => 'TABLE',
    6 min_communication => TRUE);
    7 END;
    8 /
    PL/SQL procedure successfully completed.
    (wait when the entries in DBA_REPCATLOG is empty)
    REPADMIN on ora102 >exec dbms_repcat.resume_master_activity('hr_repg')
    Hope that can help you. If that doesn't work, tell us where it bombs.
    Daniel

  • Link to file (blob) with 2 primary keys

    I am experiencing a problem in APEX 3.1.2 with viewing files uploaded through a simple form based on a table. If that table has a single column primary key, the link works perfectly. If the table has a two column primary key, the link throws a "pls/apex/apex_util.get_blob_file not found on server". I made a simple test case and if I change the table to use a 1 column PK, (and change the process on the APEX form to match), the link works. When I change the PK back to 2 columns (and the APEX processes), the link stops working on the same record. Is this a known issue? I couldn't find anything useful in Metalink or these forums.
    I may be missing something obvious, but could someone repeat this test case and let me know if you encounter the same thing?
    1) Create table called test_blob with columns
    id1 number
    id2 number
    file_blob blob
    filename varchar2
    mimetype varchar2
    update_date date
    and a primary key of id1 only
    2) Create an APEX form based on that table and configure the file browse item source with the mimetype fields, filename field, .... (You'll need to unhide the id1 field unless you bothered creating a trigger,etc to populate it)
    3) Upload the document, PDF, ... of your choice
    4) Go back to the form on that record and click the download link. It should work to open the file
    5) Change the primary key on the table to use id1 and id2 and change the processes on the APEX form to use the 2 column primary key
    6) Repeat step 4, but now the link no longer works. If you toggle back to the 1 column PK, the link works again.
    I worked around it by making a new column that concatenates id1 and id2 so I can move my application forward with a 1 column PK, but this is frustrating. BTW, I did try to use the get_blob_file_src API to work around the problem, but the link it generates is identical to that generated automatically so the same problem occurs.
    Rgds/Mark M.

    It rather depends on what access you have and what the keys are, but for my table:
    1) Drop existing primary key constraint
    2) Add a new column called something like key_id
    3) Change your trigger which currently sets your existing id to also set the new key_id by setting key_id := id1 || ' ' || id2;
    4) Add new primary key constraint for new column
    Note that to do these changes, you may need to empty the table.
    Rgds/Mark M.

  • Why should primary key be the first column in a table

    Hi,
    I'm trying to build a case to alter a table in production with a composite key . I have  PK columns at the start of table which is how it should be , but the issue is down the line , another column was added at the end and the same was added to composite
    key .
    issue is as PK arranges records physically where it creates a clustered index, as far as my knwoledge goes,  data is ordered initially by the three fields (composite keys) and then ordered again by another composite key field as they are not
    defined in a set , will this cause any performance bottle necks as it's a stage table to populate a fact if so how ??
     below is the table structure..
    Any help  in this regard is appreciated :)

    PRIMARY KEY as first column is just a convention.
    The PRIMARY KEY columns can be anywhere in a table.
    I don't see any advantage to the 5-column PRIMARY KEY.
    I would design it with INT IDENTITY (or SEQUENCE OBJECT) SURROGATE PRIMARY KEY.
    You can make the 5-columns a UNIQUE key or unique index.
    Kalman Toth Database & OLAP Architect
    Free T-SQL Scripts
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Primary Key Multiple Column with Date - parameter issue

    All,
    I am having an issue that I cannot find the answer to. I have looked high and low to no avail. Please help.
    The issue at hand is that I have a table that has a multiple column primary key and one of the columns happens to be a date and the other is a string. I have a basic search and I want an update picture in the results table that the users can click on and go to a different page to update that record. The issue is when I fire an action based on the update picture I also want to set parameters based on the record that I selected. So I set the string parameter and that works fine. The issue is with the date. When i set the date parameter it works but it chops off the timestamp. Later when I try to get this parameter 'pageContext.getParameter("dateParameter");' it will bring in a date like 15-Dec-2008 but I need the entire date and timestamp (i.e. 15-Dec-2008 10:20:33) to correctly identify the record.
    Please help!
    Thanks,
    Colby J

    Hi
    since every parameter go in url as a string format so u will never get the date parameter with complete timestamp,the solution would de
    1.) Set a fire action on update picture,give its event name as "update",
    2.) clicking on update picture will fire this event .
    3.) in processFormrequest method of controller
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    if ("update".equals(pageContext.getParameter("event")))
    // this will give the select row where update is clicked
    String rowReference = pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
    VORowImpl row = (EmployeeSummaryVORowImpl)am.findRowByRef(rowReference);
    Timestamp sdateVal=(String)row.getAttribute("Date value");
    // this will transfer the values to next page
    pageContext.putTransactionTransientValue("transferdvalue",sdateVal);
    // and in the next page u can get the value like this
    timestamp getDateVal=pageContext.getTransactionTransientValue("transferdvalue"l);
    hope this will resolve your issue,Please let me know if u face any issue
    thanx
    Pratap

  • Problem while inserting the same value on a primary key column

    hi all ,
    in my application there is a block with a pat_id column "primary key" ,
    if the user inserts the same value in this column , a message appears asking me if i want to save the changes or not ,
    i do not know what changes is the message asking about , and sure i do not want this message to appear to the user
    when he insert the same values by mistake ?
    thanks

    as a primary key field dont fill this with manually try use db seq.
    Use pre-insert trigger .

  • Problem with update of BLOB field in a table with compound primary key

    Hi,
    I've been developing an application in Application Express 3.1.2.00.02 that includes processing of BLOB data in one of the tables (ZPRAVA). Unfortunately, I've come across a strange behaviour when I tried to update value in a BLOB field for an existing record via a DML form process. Insert of a new record including the BLOB value is OK (the binary file uploads upon submiting the form without any problems). I haven't changed the DML process in any way. The form update process used to work perfectly before I'd included the BLOB field. Since than, I keep on getting this error when trying to update the BLOB field:
    ORA-20505: Error in DML: p_rowid=3, p_alt_rowid=ID, p_rowid2=CZ000001, p_alt_rowid2=PR_ID. ORA-01008: not all variables bound
    Unable to process row of table ZPRAVA.
    OK
    Some time ago, I've already created another application where I used similar form that operated on a BLOB field without problems. The only, but maybe very important, difference between both the cases is that the first sucessfull one is based on a table with a standard one-column primary key whereas the second (problematic one) uses a table with compound (composite) two-column PK (two varchar2 fields: ID, PR_ID).
    In both cases, I've followed this tutorial: [http://www.oracle.com/technology/obe/apex/apex31nf/apex31blob.htm]).
    Can anybody confirm my suspicion that Automatic Row Processing (DML) can be used for updating BLOB fields within tables with only single-column primary keys?
    Thanks in advance.
    Zdenek

    Is there a chance that the bug will be included in the next patch?No, this fix will be in the next full version, 3.2.
    Scott

  • Table with a composite primary key

    Intermedia Web agent/clipboard documentation has examples etc. on how to generate procedures and get/put data for tables having a single column as the primary key. Is it possible to use Web agent/clipboard to manipulate BLOB/ORDIMAGE data in a table which has 2 or more columns in Primary key. Has anyone done it? I will appreciate any code examples to do this.
    Thanks.

    It is possible, but you kind of need to come up with your own mechanism. Normally, when you try to retrieve a photo, for example, using 'id' as primary key, the URL would be something like:
    http://your_web_server/intermedia/mediaget/get_photo/23
    If you have a table with two columns, 'name' and 'id' as primary key, the URL would like something like:
    http://your_web_server/intermedia/mediaget/get_photo/james@23
    'james@23' will be passed to Web Agent as one string, but it is actually passing two values at once - 'james' for name and '23' for id. Here, '@' is used as a separater. In your get_photo procedure, you have to separate these two values by searching for '@'.
    You can use Clipboard Code Wizard for creating a basic procedure for a single column primary key. Then you would have to modify the code so that the procedure can handle multi-column primary key.
    I don't have any code examples for this. Sorry.

  • Update primary key with a tabular form based on a select list for each row

    Hello!
    I've two tables: Table1 with only one column (primary key) is a foreign key for table2.column1 (primary key). There is also a second primary key column in table2.
    Now I want to change the primary key values in table2.column1 with a tabular form (MRU) based on a select list (LOV based on table1.column1) for each row.
    The user should be able to choose for every row a new value from the select list to change the old primary key value at this position.
    How can I do this with ApEx?
    I've the tabular form and so on, but at the moment I get the following error:
    "Error in mru internal routine: ORA-20001: Fehler in MRU: row= 1, ORA-20001: ORA-20001: Die aktuelle Version der Daten in der Datenbank wurde geändert, seit der Benutzer einen Update-Prozess eingeleitet hat. ..."
    Thank you for your support!
    Kay

    Hello!
    I've two tables: Table1 with only one column (primary key) is a foreign key for table2.column1 (primary key). There is also a second primary key column in table2.
    Now I want to change the primary key values in table2.column1 with a tabular form (MRU) based on a select list (LOV based on table1.column1) for each row.
    The user should be able to choose for every row a new value from the select list to change the old primary key value at this position.
    How can I do this with ApEx?
    I've the tabular form and so on, but at the moment I get the following error:
    "Error in mru internal routine: ORA-20001: Fehler in MRU: row= 1, ORA-20001: ORA-20001: Die aktuelle Version der Daten in der Datenbank wurde geändert, seit der Benutzer einen Update-Prozess eingeleitet hat. ..."
    Thank you for your support!
    Kay

  • How do I create an Entity Bean with unknown primary keys

    Hi,
    Can a good folk help me.
    I am mapping an entity bean to an oracle table for the purpose of logging . I do not need a primary key contraint on this table. How do I specify in my entity bean file descriptor not to use any field for primary key ...
    I have done this so far...
    in my ejb.xml file - I set....
    <prim-key-class>java.lang.Object</prim-key-class>
    and deleted ....
    <primkey-field>...</primkey-field>
    My table structure is .....
    CREATE TABLE FAMS_REQUEST_LOG (
    EDITEDBY VARCHAR2(20),
    OLDTRANSDATE DATE,
    REQUESTID VARCHAR2(30) NOT NULL,
    OLDQTY NUMBER(20),
    NEWQTY NUMBER(20),
    NEWTRANSDATE DATE)
    but I still get this error message on deploying...
    [#|2006-03-01T14:30:29.250+0100|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.tools.deployment|_ThreadID=19;|Total Deployment Time: 11000 msec, Total EJB Compiler Module Time: 0 msec, Portion spent EJB Compiling: 0%|#]
    [#|2006-03-01T14:30:29.265+0100|SEVERE|sun-appserver-pe8.1_02|javax.enterprise.system.tools.deployment|_ThreadID=19;|Exception occured in J2EEC Phase
    com.sun.enterprise.deployment.backend.IASDeploymentException: Fatal Error from EJB Compiler -- JDO74046: JDOCodeGenerator: Caught a MappingConversionException loading or creating mapping model for application 'fixassetenterpriseapp' module 'FixAssetEnterpriseApp-EJBModule': JDO71030: There is no column in table FAMS_REQUEST_LOG which can be used to support the servers implementation of unknown key classes.
    at com.sun.ejb.codegen.CmpCompiler.compile(CmpCompiler.java:274)
    at com.sun.ejb.codegen.IASEJBC.doCompile(IASEJBC.java:615)
    at com.sun.ejb.codegen.IASEJBC.ejbc(IASEJBC.java:563)
    at com.sun.enterprise.deployment.backend.EJBCompiler.preDeployApp(EJBCompiler.java:340)
    at com.sun.enterprise.deployment.backend.EJBCompiler.compile(EJBCompiler.java:209)
    at com.sun.enterprise.deployment.backend.AppDeployer.runEJBC(AppDeployer.java:284)
    at com.sun.enterprise.deployment.backend.AppDeployer.deploy(AppDeployer.java:176)
    at com.sun.enterprise.deployment.backend.AppDeployer.doRequestFinish(AppDeployer.java:107)
    at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:146)
    at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:71)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:633)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:188)
    at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:520)
    at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:143)
    at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:172)
    |#]
    Dotun

    you will have to create a sequence and a trigger
    CREATE SEQUENCE <SEQUENCE NAME>
    INCREMENT BY  1
    START WITH  1
    NOCACHE
    /this sequence will guarantee that each requested number is unique
    the trigger will select from this sequence and insert the obtained value in the new record
    CREATE OR REPLACE TRIGGER <TRIGGER NAME>
    BEFORE INSERT ON <TABLE NAME>
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
        BEGIN
            select
                <SEQUENCE NAME>.nextval
            into
                :NEW.<COLUMN NAME>
            from
                dual;
        END;
    [/CODE]
    this will always take the value from the sequence, even if you already provided a value yourself
    (otherwise you will first have to test if :NEW.<column name> is null, but I wouldn't do this for a key column.
    if you need the generated key back for further processing (inserting it into a child table for example), you can use the returning clause on the insert statement
    see the oracle documentation for more information about sequences, triggers and the returning clause
    greetings
    Freek D
    I am new to Oracle and need to know how to create a table that uses an automatic incrementation on a primay key for it's default. I need the uniqueness automatically managed by the DBMS.. This activity is know as setting the Column (primary key with identity) in Ms-SQL..
    Your help would be appreciated greatly....
    Thanks....

  • How do I Create an AutoIncrement on a Primary key Default

    I am new to Oracle and need to know how to create a table that uses an automatic incrementation on a primay key for it's default. I need the uniqueness automatically managed by the DBMS.. This activity is know as setting the Column (primary key with identity) in Ms-SQL..
    Your help would be appreciated greatly....
    Thanks....

    you will have to create a sequence and a trigger
    CREATE SEQUENCE <SEQUENCE NAME>
    INCREMENT BY  1
    START WITH  1
    NOCACHE
    /this sequence will guarantee that each requested number is unique
    the trigger will select from this sequence and insert the obtained value in the new record
    CREATE OR REPLACE TRIGGER <TRIGGER NAME>
    BEFORE INSERT ON <TABLE NAME>
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
        BEGIN
            select
                <SEQUENCE NAME>.nextval
            into
                :NEW.<COLUMN NAME>
            from
                dual;
        END;
    [/CODE]
    this will always take the value from the sequence, even if you already provided a value yourself
    (otherwise you will first have to test if :NEW.<column name> is null, but I wouldn't do this for a key column.
    if you need the generated key back for further processing (inserting it into a child table for example), you can use the returning clause on the insert statement
    see the oracle documentation for more information about sequences, triggers and the returning clause
    greetings
    Freek D
    I am new to Oracle and need to know how to create a table that uses an automatic incrementation on a primay key for it's default. I need the uniqueness automatically managed by the DBMS.. This activity is know as setting the Column (primary key with identity) in Ms-SQL..
    Your help would be appreciated greatly....
    Thanks....

  • Deleting Primary Key --- High Priority -- Please help us

    There is a custom defined table which had two primary keys and then moved the same to production. Since we got some requiremnent we added two more primary keys in the table in development server. We also activated the same in Development server. Now we need to delete the recently added two primary keys. It is a most important custom table. It is not allowing us to delete.
    It gives us error message about lot of dependencies and foreign key used in other tables.
    Please help us resolve this issue. FULL POINTS WILL BE AWARDED FOR THE SOLUTION. please help us resolve the same. Bottle neck situation.
    Regards,
    Siddhartha

    Hi Siddhartha,
    http://www.ncsu.edu/it/mirror/mysql/doc/maxdb/en/3c/384c4005a99523e10000000a1550b0/content.htm
    If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key ... Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, ...
    http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm
    This links will help you to solve your  problem
    Thanks
    sunil

  • Outer join with tow columns foreign key

    If I want to select from two tables (A and B) with outer join on table "B" and I have two columns foregn key between the two tables what is the correct way:
    1)
    ...from A,B
    where A.key1 = B.key1 (+)
    and A.key2 = B.key2 (+)
    2)
    ...from A,B
    where A.key1||A.key2 = B.key1||B.key2 (+)
    thank you,
    ENdre

    #1

  • Atomic Primary Key or Composite ? Which approach is better ?

    Hi all,
    I have a table that has its composite primary key (infact foriegn keys of other tables make pk in this table).
    But due to large project complexity, i just want to have an atomic primary key, so that i could use a sequence for it, instead of using N foreign keys from other tables. And furthermore, a single column primary key can be easily accessed as foreign key as compared to N columns primary key.
    Is it a good approach in general ?
    My personal view has certain reservations regarding the atomic primary key in such case. It could lead to a weak database design.
    Any suggestion ?
    Thanx
    Zaaf.

    Most large data warehouses implement a 'synthetic' key approach for much the same reasons that you describe. You can still carry the FKs and use them to assist in joining operations, while keeping the size (and complexity) of the primary key down to a manageable size.
    There are downsides to this approach - it depends on how the data is most frequently accessed and many other factors. But in general it can work quite well.

Maybe you are looking for