Skip to content

Instantly share code, notes, and snippets.

@WendySanarwanto
Created May 25, 2018 06:08
Show Gist options
  • Save WendySanarwanto/eda047d6586328b0c048f7b28d5617c2 to your computer and use it in GitHub Desktop.
Save WendySanarwanto/eda047d6586328b0c048f7b28d5617c2 to your computer and use it in GitHub Desktop.
Creating a new table with autoincrement column on Oracle database
CREATE TABLE USER_ACCOUNTS (
ID NUMBER(10) NOT NULL,
EMAIL VARCHAR(30) NOT NULL,
PASSWORD VARCHAR(100) NOT NULL
);
ALTER TABLE USER_ACCOUNTS ADD (
CONSTRAINT user_acc_pk PRIMARY KEY (ID)
);
CREATE SEQUENCE user_acc_seq START WITH 1;
CREATE OR REPLACE TRIGGER user_acc_before_insert_trigger
BEFORE INSERT ON USER_ACCOUNTS
FOR EACH ROW
BEGIN
SELECT user_acc_seq.NEXTVAL
INTO :new.id
FROM dual;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment