Manage Learn to apply best practices and optimize your operations.

Auto-increment and how-to book

I have created a table on an 8i database and I would like one of the attributes, which is a number (primary key), to be auto incremented. How do I define this?

Could you please also recommend a book on PL/SQL that has practical examples as seen in your answers?
Before sending in a question to this forum, you may want to see if there is information already on the site by typing a couple of key words in the "Oracle Target Search" window just above the expert's picture. Of course, part of the problem is knowing the right buzz words to search for. I tried "auto increment" and got just a couple of hits (but enough to answer your first question).

Knowing that Oracle uses sequences and triggers to do what you want, I tried "sequence trigger" and got dozens of good tips, including my own earlier column on how to create a sequence to use as a primary key, and how to write a trigger to make sure it's used in all INSERT commands.

A good teach-yourself-PL/SQL book is Oracle PL/SQL by example: Third edition by Benjamin Rosenzweig and Elena Silverstova (Prentice Hall PTR, 2003, ISBN 0-13-117261-1, list price $50 in the USA). It has good examples and exercises.

Dig Deeper on Using Oracle PL-SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.