From: Richard S. <ri...@ri...> - 2003-08-20 18:47:43
|
As I looked for what is the common standard for creating auto increment=20= columns in a table I found that there isn't one. I know the built in=20 sequencing PWS has in play for auto increment has some play in this but=20= not completely sure how it works when setting up a table? What do you guys think will be the best way to create tables with an=20 AUTO INCREMENT column with PWS? I currently don't care for too much=20 support for Oracle right now as you can see with the example below. Syntax for MySQL =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D CREATE TABLE test ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ( id) ); Syntax for PostgreSQL =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D CREATE TABLE test ( id SERIAL , PRIMARY KEY (id) ); Syntax for Oracle9i =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D -- --Create sequence called demo -- CREATE SEQUENCE "DEMO"."SEQ_INSERT" INCREMENT BY 1 START WITH 1780229 MAXVALUE 1.0E28 MINVALUE 1 NOCYCLE CACHE 20 ORDER -- -- Next place a trigger for that column you want to auto increment -- -- CREATE OR REPLACE TRIGGER "DEMO"."TRG_EMP_INSERT" BEFORE INSERT ON "DEMO"."EMP" =A0 =A0 FOR EACH ROW BEGIN =A0 SELECT seq_insert .nextval =A0-- get the new seq number =A0 =A0 INTO :NEW.emp_no -- :NEW missed =A0 =A0 FROM DUAL; END; # Found source for Oracle at=20 http://www.experts-exchange.com/Databases/Q_20412293.html Best Regards, - Richard S= |