Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: primary keys

Re: primary keys

From: Randy A. Stebbins <randys_at_triax.com>
Date: 1997/06/13
Message-ID: <01bc77af$6d1e0f80$146930cf@default>#1/1

Aldo Alejandro <aalejan_at_pacbell.net> wrote in article <01bc743a$da8362a0$cf05aace_at_aalejan.pacbell.net>...

> How would you create primary keys in personal oracle 7.3 using the create
> sequence route?
> Also I would like my pk's to be informative (e.g.) customer order id # is
> today's date + order number
>
> The second case would be creating a pk that uses the concatenation of the
> first four letters of the fname and the first 4 letters of the lname.

I don't think you want a sequence. Sequences are for using ordered lists of numbers. A primary key is not something separate from a table. It is one (or more) columns of the table itself. When you identify a primary key for a table, Oracle creates an index on the key, and prevents any duplicate entries.

I think you may want to use a "before insert" trigger. It's hard to say without knowing a bit more about your transaction. Have the trigger create the primary key from other values in the insert. Or you could use a stored procedure to "wrap" the insert into the database, creating the primary key in the code before inserting into the table. The second would be my choice, but you sound like a beginner, and that might be a steep learning curve for you. Maybe you're faster than I am, but it took me awhile to learn to write good stored procedures. Steve Feuerstein's books were an immense help. I would recommend them.

Good luck. Received on Fri Jun 13 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US