Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: primary keys
Hello everyone
Aldo Alejandro <aalejan_at_pacbell.net> napisa³(a) w artykule
<01bc743a$da8362a0$cf05aace_at_aalejan.pacbell.net>...
> Hello everyone,
>
> 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
I think you should create objects in database...
CREATE SEQUENCE seq1
INCREMENT BY 1
START WITH 1
NOCYCLE
CACHE 20
NOORDER
;
CREATE OR REPLACE TRIGGER triggername
BEFORE INSERT
ON tablename
FOR EACH ROW
DECLARE
BEGIN
:new.id:=seq1.nextval;
....
END;
> 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.
> --
> Thanks & have a nice day! ;-)
CREATE OR REPLACE TRIGGER triggername
BEFORE INSERT
ON tablename
FOR EACH ROW
DECLARE
BEGIN
:new.id:=substr(:new.fname,1,4)||substr(:new.lname,1,4);
....
END;
Pawel Plichta
pp_at_inwar.com.pl
Invar System - Sieradz POLAND
Client-Server Department of Technology
Received on Wed Jun 11 1997 - 00:00:00 CDT
![]() |
![]() |