Last active
January 6, 2018 05:40
-
-
Save navinthenapster/bc6ade4932f4abff1a82c558bb55c6ed to your computer and use it in GitHub Desktop.
Oracle Sql . proper Create table which can take default timestamp, condition and triggers a sequences
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 SEQUENCE notify_seq | |
INCREMENT BY 1 | |
NOCACHE | |
NOCYCLE; | |
DROP SEQUENCE notify_seq | |
CREATE TABLE NOTIFICATIONS( | |
NOTIFY_ID NUMBER , | |
SENDER VARCHAR2(500), | |
RECEIVER VARCHAR2(500), | |
MESSAGE VARCHAR2(500), | |
NOTIFY_TYPE VARCHAR2(500), | |
NOTIFY_TIME timestamp default SYSTIMESTAMP , | |
READ VARCHAR2(5) DEFAULT 'false' CHECK ( READ in ('true','false')) , | |
CLEAR VARCHAR2(5) DEFAULT 'false' CHECK ( CLEAR in ('true','false')) | |
); | |
SELECT * FROM NOTIFICATIONS | |
DROP TABLE NOTIFICATIONS | |
//TRIGGER THE NOTIFY SEQUENCE | |
CREATE OR REPLACE TRIGGER notify_trigger BEFORE INSERT ON NOTIFICATIONS | |
FOR EACH ROW | |
declare foo number | |
BEGIN | |
if :NOTIFICATIONS.NOTIFY_ID is null then | |
select notify_seq.nextval into foo from dual | |
:NOTIFICATIONS.NOTIFY_ID := foo | |
end if | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment