Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to create primary key?

chamsterchamster Member Posts: 662
When i execute the example on Suns website:
"INSERT INTO COFFEES " +
"VALUES ('Colombian', 101, 7.99, 0, 0)");
then everything is fine the first time.

What i expected it to do the next time i execute the
very same line is to UPDATE row 'Colombian' with
(the same) values provided.

To my amazment i get more and more rows with the same
name. I understand that Oracle believs i don't want to
use any primary key. Why? How to solve this?

Kind Regards
Konrad
----------------------------
(+46/0) 708-70 73 92
chamster@home.se
http://konrads.webbsida.com

Comments

  • dannyerldannyerl Member Posts: 20
    Hi. This what you've need to do:
    1) create a PK, in this way:

    ALTER TABLE
    ADD PRIMARY KEY;
    2) Do your process again.

    Maybe in the WHERE part of the UPDATE statement, add another filter
    condition.

    Bye

    : When i execute the example on Suns website:
    : "INSERT INTO COFFEES " +
    : "VALUES ('Colombian', 101, 7.99, 0, 0)");
    : then everything is fine the first time.
    :
    : What i expected it to do the next time i execute the
    : very same line is to UPDATE row 'Colombian' with
    : (the same) values provided.
    :
    : To my amazment i get more and more rows with the same
    : name. I understand that Oracle believs i don't want to
    : use any primary key. Why? How to solve this?
    :
    : Kind Regards
    : Konrad
    : ----------------------------
    : (+46/0) 708-70 73 92
    : chamster@home.se
    : http://konrads.webbsida.com
    :

  • DvaleroDvalero Member Posts: 2
    Cuando se define una tabla en Oracle, debe especificarse cual es el primary key en su definicion, de lo contrario Oracle asigna como especie de primary key a cada registro que insertes en la tabla, y esto es porque cada registro tiene un campo oculto llamado ROWNUM que es asignado por ORACLE cada vez que insertes un registro en la tabla...

    por eso es que lo puedes hacer...

    Solucion:
    Define nuevamente la tabla y especifica que tenga un primary key o cuando vayas a actualizar nuevamente un registro primero pregunta por su rownum

    Ejm:
    Select rownum, ... from table
  • Shawn CarterShawn Carter Member Posts: 0

    _________ / http://forcoder.org / free video tutorials and ebooks about ( Visual Basic, C, C#, Java, R, Python, MATLAB, Go, Ruby, Assembly, PL/SQL, Swift, Visual Basic .NET, JavaScript, PHP, C++, Objective-C, Delphi, Perl, Scratch Erlang, Scheme, Rust, Lisp, Kotlin, Crystal, Prolog, Fortran, F#, FoxPro, Hack, Scala, LabVIEW, VBScript, Ada, SAS, ML, Alice, Bash, ABAP, COBOL, Awk, Julia, Apex, Dart, Lua, Clojure, Logo, D, Transact-SQL ) ______________

Sign In or Register to comment.