How to Create Auto-Increment Field in Oracle

Create a sample table.

CREATE  TABLE SAMPLETABLE (
  TABLEID  number,
  TABLEDATA  varchar2(20)
);

Create a new sequence.

CREATE SEQUENCE SEQ_SAMPLETABLE_ID
START WITH 1
INCREMENT BY 1 ;

Create a new trigger.

CREATE OR REPLACE TRIGGER TRIGGER_SAMPLETABLE 
BEFORE INSERT ON SAMPLETABLE 
FOR EACH ROW
BEGIN
  SELECT SEQ_SAMPLETABLE_ID.NEXTVAL INTO :NEW.TABLEID FROM dual;
END;

Comments

Popular posts from this blog

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"

Solution for "Can not obtain Oracle client information from registry"