Created
May 25, 2018 06:08
-
-
Save WendySanarwanto/eda047d6586328b0c048f7b28d5617c2 to your computer and use it in GitHub Desktop.
Creating a new table with autoincrement column on Oracle database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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