SQL>
SQL> CREATE TABLE myTable (
2 myTableID INT PRIMARY KEY NOT NULL,
3 Name VARCHAR(50),
4 PhoneNo VARCHAR(15) DEFAULT 'Unknown Phone');
Table created.
SQL>
SQL> CREATE SEQUENCE SEQ;
SQL>
SQL> CREATE OR REPLACE TRIGGER AUTONUMBER
2 BEFORE INSERT ON myTable
3 FOR EACH ROW
4 BEGIN
5 SELECT SEQ.NEXTVAL
6 INTO :NEW.myTableID FROM DUAL;
7 END;
8 /
Trigger created.
SQL>
SQL>
SQL> drop table myTable;
Table dropped.
|