Copy rows from the same table and update the ID column

前端 未结 8 446
情歌与酒
情歌与酒 2021-02-01 02:09

I have the following table

\"alt

I have inserted Product B to it and it gives me an ID of 15

8条回答
  •  失恋的感觉
    2021-02-01 03:00

    Do you use Oracle? It does not have an automatic PK_generator, nothing to work for your INSERT silently. However, it has SEQUENCEs, so let's use its NEXTVAL:

    INSERT INTO Orders_tab (Orderno, Custno)
        VALUES (Order_seq.NEXTVAL, 1032);
    

    The INSERT operation is exactly the case for them, the purpose of a SEQUENCE, you just have to use it explicitly. More described: Managing Sequences # Using Sequences

    The node for Sequences is on the level of Tables, i.e. in the SQLdeveloper. Ours are ID_GENERATOR, in every DB.

提交回复
热议问题