Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

oracle sql plus making an existing primary key auto_increment

  • 04-10-2007 4:04pm
    #1
    Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭


    Can I change an existing primary key in a table to auto_increment?

    The table has nothing in it.


Comments

  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    there's no such thing as an auto-increment field in oracle. you can use a sequence to simulate an auto-increment field though.

    *edit* the above information is good up to Oracle 9. After that I dont have a clue


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Beano is correct in that there is no auto_incrememnt feature directly implemented in Oracle.

    I did, however, run a quick google on "oracle auto_increment" and the second hit returned gives a decent workaround.


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    Beano wrote:
    *edit* the above information is good up to Oracle 9. After that I dont have a clue

    Yip, same in 10.

    As the chaps are saying. You need a trigger and a sequence.


  • Registered Users, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    You just need to create a sequence, then call sequencename.nextval in your field to use it. (or currval to check what it is)


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    Giblet wrote:
    You just need to create a sequence, then call sequencename.nextval in your field to use it. (or currval to check what it is)

    Then how does it auto-increment upon an update?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    tom dunne wrote:
    Then how does it auto-increment upon an update?

    Why would you want it to auto-increment on an update?


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    bonkey wrote:
    Why would you want it to auto-increment on an update?

    Doh! Insert is of course what I meant.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    I think what Giblet is describing is how to use a sequence to provide the functionality....which is fine if you have control over who can run inserts and make sure that this technique is always used.

    If you do it with a sequence inside a before-insert trigger, then it doesn't matter who runs inserts, nor how.


Advertisement