Autoincrement Primary key in Oracle database
I would like to achieve an identity or auto-incrementing value in a column ala SQL Server: CREATE TABLE RollingStock ( Id NUMBER IDENTITY(1,1), Name Varchar2(80) NOT NULL ); How can this be done? Matthew Watson As Orbman says, the standard way to do it is with a sequence. What most people also do is couple this with an insert trigger. So, when a row is inserted without an ID, the trigger fires to fill out the ID for you from the sequence. CREATE SEQUENCE SEQ_ROLLINGSTOCK_ID START WITH 1 INCREMENT BY 1 NOCYCLE; CREATE OR REPLACE TRIGGER BI_ROLLINGSTOCK BEFORE INSERT ON ROLLINGSTOCK REFERENCING