Last active
March 14, 2016 09:24
-
-
Save nulpatrol/7287e0fe53f70bd527c1 to your computer and use it in GitHub Desktop.
AutoIncrement.sql
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 people ( | |
id NUMBER NOT NULL, | |
name VARCHAR(56), | |
last_name VARCHAR(56), | |
dob DATE, | |
graduation_date DATE, | |
created_at TIMESTAMP, | |
updated_at TIMESTAMP) | |
ALTER TABLE people ADD CONSTRAINT people_pk PRIMARY KEY ( id ) | |
CREATE SEQUENCE people_seq START WITH 1 INCREMENT BY 1 | |
CREATE OR REPLACE TRIGGER people_trigger | |
BEFORE INSERT ON people REFERENCING | |
NEW AS new | |
OLD AS old | |
FOR EACH ROW | |
BEGIN | |
SELECT COALESCE(:new.id, people_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