Updating a table with no Primary key

What I am trying to find out is if you can uniquely update a single record in a table that has no primary key. I see no way to reference the record I want, other than specifying all the field values in a where clause. This is a problem though, because if I have another record with the same field values, that will get updated too. (I know its a bad database design, but some people do it and I need to work around it!!!), there are some situations where you would have identical records as far as a where clause is concerned, for example, you cant use a blob in a where clause so that might be where your records differ...
In SQLServer 2000, Enterprise manager throws an error if you have a table with no primary key and duplicate records that you try to update through the GUI. EM uses stored procedures to execute updates, and it rolls back ones which result in more than one update result.
Im not too familiar with Cursors in SQL, only that they are quite slow and not implemented on all DB products. But I think that they might be able to solve the problem (but I dont logically see how).
Can anybody explain this to me?

another record with the same field valuesIf you have two records and all the field values are the same then the records are logically the same anyways, so it shouldn't matter if you update both (one would question why there are two records in the first place.) In other words there is no way, either computationally or manually to tell them apart.
I suspect that that is rather rare. Instead what is more likely is that you are only using some of the fields. So just keep adding fields until it is unique.

Similar Messages

  • Mapping tables with no primary key defined

    Hi!
    I was just wondering if it's possible to map a table with no primary key? The reason why is that I have a logging table that I want to access, which is built very simple and the only useful filtering criteria that I'll be using there is a date column.
    Regards,
    Bjorn Boe

    TopLink requires that an object have a primary key to determine identity, perform caching, and database updates and deletes. It is best to define a primary key in all your objects; a sequence number can be used if the object has no natural primary key. The primary key does not have to be defined on the database, as long as a set of fields in the table are unique you can define them to be the primary key in your TopLink descriptor.
    If your table truly has no primary key, nor unique set of fields, it is still possible to map the table with some restrictions. If you disable caching, and mark the object as read-only, and never update or delete the object, you can map it for read-only purposes.
    You will need to do the following:
    - Set any field as the primary key to avoid the validation warning.
    - Set the cache type to NoIdentityMap.
    - Set the descriptor to be read-only.

  • Insert values of form on a table with compound primary keys in APEX

    Good evening,
    I have a table with compoud primay keys. On ER model I had a many to many relation and when I coverted to relational model I've got a table with the primary keys of the two entities.
    My problem now is that I am trying to build an APEX application with a Form/Report and I want to insert a tuple both on the "entity" and on the table with two primary keys.
    I created a trigger with
    CREATE OR REPLACE TRIGGER ins_key_elem
    INSTEAD OF INSERT
    ON v_key_elem
    REFERENCING NEW AS NEW
    FOR EACH ROW
    BEGIN
    INSERT INTO elem_type (elem_key, type_key)
    VALUES (:NEW.elem_key, :NEW.type_key);
    INSERT INTO elem(elem_key, name)
    VALUES (:NEW.elem_key, :NEW.name);
    END;
    Is that ok? If it is, now how I can use that trigger to do what I need? i.e. insert the tuple on the two tables when I use the create button of the form
    Edited by: 934530 on May 15, 2012 2:36 PM

    Nevermind...figured it out. Was able to set the value on the Report Attributes page.

  • 2 tables with same primary key

    Hi,
    2 tables with same primary key is possible,but when is wise to go for such ?
    is that a bad desisn ?
    eg:
    Personal_details_employee
    Official_details_employee
    these 2 tables have same Primary key emp_id.
    plz. reply me at [email protected] also
    thanx
    vikram

    hi Vikram,
    In this case u can have then in one table itself and why do want to have two tables.
    - Suresh.A

  • 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

  • Using table with no primary key

    I habe some older table that use unique indexes (instead of primary keys). Some of these are comprised of 3 or 4 columns (see below). When I try to create an HTML DB tabular form or report is it asking for primary key. How do I get around this?
    CREATE UNIQUE INDEX COURSES ON COURSE(START_YY,SCHOOL,CLASS_CD)
    TABLESPACE starindx
    STORAGE (INITIAL 61440
    NEXT 61440
    PCTINCREASE 0);

    You will have to code your own inserts, updates, and deletes along with optimist row locking, which is painful.
    To use HTML DB's built-in/default inserts, deletes, updates, and optimistic row locking, add a number column to your table. Make that new column be the primary key on the table. In the HTML PAGE populate it from a number generator. The primary key column will in essence function like a rowid for the row. The only thing you will want to do is code a validation to check for a unique combination of START_YY,SCHOOL, and CLASS_CD in the table so the page can present a more pleasing 'duplicate key on index' message in the event that the user has matched an already existing tuple.

  • ResultSet updateRow ,insertRow ,deleteRow APIs on table with no PRIMARY KEY

    Hi,
    When I use ResultSet.insertRow , updateRow ,deleteRow API's on a table which contais no primary key column I find the following Exception ,
    java.sql.SQLException: Operation invalid. No primary key for the table
    at com.tandem.sqlmx.Messages.createSQLException(Messages.java:69)
    at com.tandem.sqlmx.SQLMXResultSet.getKeyColumns(SQLMXResultSet.java:3501)
    at com.tandem.sqlmx.SQLMXResultSet.prepareInsertStmt(SQLMXResultSet.java:3652)
    at com.tandem.sqlmx.SQLMXResultSet.insertRow(SQLMXResultSet.java:2073)
    at testdateupdate.main(testdateupdate.java:33)
    It looks like the table needs to have a primary key column to update or insert or delete rows using the ResultSret APIs.
    I use a proprietary JDBC driver. I find the Explanation for this behavior like this ,
    JDBC allows update stmts on tables w/out a primary key defined if the stmt is issued by the application. For updateable ResultSets, a primary key restriction is required to avoid updating more rows than desired.I dont understand this explanation and also I dont find this behavior is some other JDBC drivers that I tried with.
    Some one Please Clarify the same.
    Thanks in Advance.
    Thanks and Regards,
    Jay

    Hi,
    in simple words, when a table does not have primary key you can send update and delete on it only by using a Statement object. When using ResultSet.updateRow or ResultSet.deleteRow the jdbc looks for the primary key on the metadata in order to send the correct where clause to the rdbms. I think that this could maybe work with Oracle DBMS, which has a unique id (ROWID) for each record.
    Kiros

  • Tabular Form on Table with no primary key

    I have many tables defined with Unique Index (instead of Primary Keys). This allows my user to update/insert the value of the unique index. When I try to create my form in HTML DB, it makes me put in the primary key. If I choose th column that has the unique index, it will not let me update or insert that value. How can I achieve this?

    Create a surrogate PK called rec_id or something and populate that using a BEFORE INSERT row-level trigger
    create sequence pk_seq;
    create or  replace trigger trg
    before insert on t
    for each row
    begin
    select pk_seq.nextval into :new.rec_id from dual;
    end;
    /Tell the HTML DB wizard about this new PK (rec_id), should work fine
    Hope this helps.

  • Help.......... required :Database table with no primary key

    Hi All,
    I have a table sponsor_logos whose structure is as follows:
    sl__sponsorid number,
    sl__clubid number,
    sl_hallno varchar2(7) not null,
    sl_logofilename varchar2(100) not null,
    sl_date_modified date not null
    Where in the sl__sponsorid and sl__clubid are foreign keys and I do not have any primary key for the table.
    I need to insert into and also delete records from the table.
    I have gone through various topics in the java forum for EJB's to find out what design strategy should I use?
    Some say that if a table does not have primary keys, and if the table is represented by a CMP entity bean all the fields of the table are considered as a part of primary key.In that case what would my code look like and what would my deployment descriptor contain?????
    According to the specification, the CMP or a BMP represents a unique record in a database.In that case should I be using a Session bean to handle insertions and deletions for the table?
    Since this is my first project with EJB's I am really confused as to what design should I be using for this situation. Since I have a time constraint I can't take a long time to decide on what strategy I should use.
    Suggestions regarding this are welcome .

    Hi Maris,
    I have my PK class ready with all the fields in it.
    Deployment descriptor ready with <prim-key-class>package.SponsorLogoPK</prim-key-class>
    . According to descriptor specification there is no need to have an entry for
    <primkey-field>bookingSlNo</primkey-field>
    in case of custom primary key .
    So I have omitted <primkey-field>bookingSlNo</primkey-field>
    I have used the verifier tool and verified the ejb , no errors with regards to this ejb, but , getting errors while deploying:
    An error has occurred.
    Deployment Error -- Error while running ejbc -- Fatal Error from EJB Compiler -- JDO74025: JDOCodeGenerator: Caught an Exception validating CMP bean 'SponsorLogoBean' in application 'resnet_ejb' module 'E:\Sun\AppServer\domains\domain1\applications\j2ee-modules\resnet': JDO72335: If the table SPONSOR_LOGOS for the bean corresponding to the generated class com.resnet.squash.api.entity.SponsorLogoBean483209734_JDOState is mapped as the primary table, it must have a primary key. Choose a different primary table or verify that the contents of the schema file are correct.
    Now what could the problem be . Do I need to do any other setting in the descriptor. I have the cmp-mapping also intact.

  • Issues mapping table with no primary key?

    As an exercise, I'm building a small application mapping a set of mySQL tables, using JPA. I have one table that does not have a primary key. I can see a workable natural composite key that will be unique in my data. Will I have any issues if I define the composite primary key in my JPA code, even though the table doesn't have a primary key defined?

    As long as the primary key do not change after the constructor is called it should work without any problem. But your select may be show without an index.

  • Need to create form on a table with report with a table has NO primary key

    Hi, I tried to created some insert/update/delete form+report in an application, it works fine only if the table has primary key. Does anyone know how to create the same functionality with a table with no primary key? I saw an application is built on older version of htmldb that is using tables with no primary keys at all.
    Here are the specific issues that I am facing:
    - I am building some Form on a table with Report, it requires the table with primary key for form to update. Is there a workaround that I can use tables that has no primary keys at all?
    - Say if primary key is necessary in the previous report+form, but the maximum number of columns that I can use to composed a primary is only 2 for that Form-Report, I cannot find anything handling > 2 primary key. Do you know if there are some ways to composite a primary key from many columns together?
    Your help is really appreciated.
    Thanks,
    Angela

    Sorry to ask response so late. I had no time to get back to that issue before.
    Regarding the triggers, I can make it work for the update, but not the insert.
    Here is my trigger:
    create or replace trigger STATUS_T1
    instead of insert on STATUS
    begin
    insert into STATUS ("LABEL", "AREA", "OWNER", "TEST_NAME", "STATUS", "REMARKS", "BUGS", "DEV_MGR", "TEST_BY_DATE")
    values(:new.LABEL, :new.AREA, :new.OWNER, :new.TEST_NAME, :new.STATUS, :new.REMARKS, :new.BUGS, :new.DEV_MGR, :new.TEST_BY_DATE);
    end;
    by any chance, you can notify what is wrong?
    I already skip the ROWID when inserting to the view STATUS, but I cannot figure out what is wrong when inserting a new record to that view.
    It gave me the following errors:
    ORA-06550: line 1, column 38: PL/SQL: ORA-00904: "ID": invalid identifier ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored
    Error Unable to process row of table STATUS
    Then, I turned to debug mode, I am thinking that maybe because I use a HIDDEN item to hold the value of ROW_ID as I use the rowid (called ID in the view) to retrieve the record as a column link from previous page. What do you think?
    Thanks again,
    Angela

  • Problem with varchar2 primary key..

    OWM version 10.1.0.8
    When I am trying to add a column in a version enable table with varchar2 primary key, it fails.
    If primary key is numeric it works.
    See below the test case.
    -- CASE 1. When primary key is number.
    SQL> create table wmtab
    ( wmtab_id number,
    price number,
    title varchar2(80),
    AUTHOR VARCHAR2(10)
    Table created.
    SQL> ALTER TABLE wmtab add (CONSTRAINT PK_kontakt PRIMARY KEY (wmtab_id));
    Table altered.
    SQL> EXECUTE DBMS_WM.EnableVersioning('WMTAB');
    PL/SQL procedure successfully completed.
    SQL> CALL DBMS_WM.BEGINDDL('WMTAB');
    Call completed.
    SQL> ALTER TABLE wmtab_lts add ( FREIGEGEBEN varchar2(1));
    Table altered.
    SQL> CALL DBMS_WM.commitDDL('WMTAB');
    Call completed.
    -- CASE 2. When primary key is varchar2.
    SQL> create table wmtab
    (wmtab_id varchar2(10) constraint wmtab_pk primary key,
    price number,
    title varchar2(80),
    AUTHOR VARCHAR2(10)
    Table created.
    SQL> EXECUTE DBMS_WM.EnableVersioning('WMTAB');
    PL/SQL procedure successfully completed.
    SQL> CALL DBMS_WM.BEGINDDL('WMTAB');
    Call completed.
    SQL> ALTER TABLE wmtab_lts add ( FREIGEGEBEN varchar2(1));
    Table altered.
    SQL> call DBMS_WM.CommitDDL('wmtab');
    call DBMS_WM.CommitDDL('wmtab')
    ERROR at line 1:
    ORA-20199: primary key columns cannot be added/dropped/modified/reordered for
    version enabled tables
    ORA-06512: at "SYS.OWM_DDL_PKG", line 6196
    ORA-06512: at "SYS.LT", line 11930
    ORA-06512: at line 1
    Same problem is reprosucible on OWM 10.2.0.1.
    But its working fine with varchar2 primary key On OWM 10.2.0.4.2/3
    Is there any workaround or we can get patch for 10.1.x.x?

    Hi,
    I was unable to reproduce this behavior on OWM 10.1.0.8. It appears that you have a SR open for this issue, so I would suggest to continue with that process.
    Regards,
    Ben

  • FindByKey with tow primary keys

    I am using findByKey in a table with two primary keys. It works fine if I use only one key in the ViewObject, using either of the two keys, but I need to use both keys, but search on the value of only one of them.
    I read I could pass null as the value of the other key, to consider all the values on it, but it doesn't work.
    Both keys are String.�Any suggestions?
    Thank you.

    Victoria:
    Please run your test case with diagnostic turned on. It will show the SQL statement used for your findByKey() request. See if the SQL makes sense. If still doesn't work and if you cannot figure out what's going on, please post the diagnostic output.
    To turn on diagnostic, you need to specify
    -Djbo.debugoutput=console
    as one of the JVM switches.
    If you're invoking your app (middle-tier app) from command line,
    include -Djbo.debugoutput=console as in
    java.exe -Djbo.debugoutput=console ...
    If you're running your app from within JDev:
    1. Select the project.
    2. Do right mouse click and select "Project Settings..."
    3. On the Settings dialog, select Configurations/Runner.
    4. In the righthand side pane, you should see a textbox for "Java
    Options". Please add the following JVM switch:
    -Djbo.debugoutput=console
    Then, rerun. The run command should include
    -Djbo.debugoutput=console as in
    "D:\JDev9i\jdk\bin\javaw.exe" -Djbo.debugoutput=console -classpath ...
    You should now see a lot more output on the IDE's message window.
    Thanks.
    Sung

  • Getting errors when updating a column on a table having a primary key

    Hi,
    I have an application on Oracle APEX that raises the following error after an attempt (through the application) to update a column with no specific constraint on it:
    ORA-06550: line 1, column 17: PL/SQL: ORA-00936: missing expression ORA-06550: line 1, column 9: PL/SQL: SQL Statement ignoredUnable to fetch row.
    The involved table has a primary key conatraint and the corresponding column can be populated by a sequence (but there is no trigger to manipulate the sequence).
    The sequence is mentioned in the involved page definition for populating the primary key.
    If I disable the primry key and set to null the corresponding value for the primary of the record to be updated, then it is possible to update that record (thus the above column) through the application.
    Did someone encountered this situation before?
    If yes, what was then your workaround/solution?
    Kind Regards.

    Dear user8058501 ,
    Firstly) Did you check
    Auto Row Fetch (After upgrade to 4.0.1)
    Automated Row Fetch on Table with Synonym causes ORA-00936: missing expr.
    Secondly) If the problem is not resolved, Would you provide a sample on apex.oracle.com with workspace/developer account to be able to help you
    Please, if this solves your question, mark it as Correct. Otherwise as helpful.
    Best Regards
    Mahmoud

  • DBMS_CDC find only the columns that are changed along with the primary key in the table

    Hello,
    We are having a requirement to find the change data in the production environment.
    We are planning to use the DBMS_CDC utility.
    But for  example in the create change table 1 picked emp_id,ename, address, salary,dob.
    I have a sample data of
    empid
    ename
    address
    salary
    DOB
    1
    test1
    24 test street
    2000
    20-Jan-98
    2
    test2
    25 test street
    2500
    15-Aug-97
    if ename for empid 1 is changed to test1_test3 from test1.
    My CDC is capturing  the values in the old and new values in the 5 columns.
    But i need to get only the empid (primary key of the source table) and the ename column as only that's been updated not the rest of the 3 columns.
    Can i accomplish this.
    Please advice.

    Hello,
    Thanks for the information.
    but if i change the change table  then i will miss the other columns right?
    I want to get the columns( empid and ename) only if ename is changed. i.e when ever any column in emp table changes i need to get all the columns where the data is changed along with the primary key columns empid.
    Is there any way i can tweak the parameters so that i can achieve this or is there any other way using the cdc i can get this data.
    Thanks

Maybe you are looking for