this is what i have:
CREATE TABLE EMP (
EMPNO NUMBER(4) NOT NULL,
To insert into this table, I have to put in the primary key. I can use a sequence.
Insert into emp(empno, empname)
In SQL SERver we have the @@IDENTITY key. Also, when we have a column as a primary key, we do not need to specifically insert it into the table.
Thus, if the above were in SQL Server, i would say:
Insert into EMP(empname)
How can I in oracle, setup my primary key column such that it enters a unique value by default similar to in SQL Server.
I tried this:
create table emp(
empno number(4) DEFAULT emp_seq.nextval NOT NULL,
I get an error saying something like column not allowed.
Any ideas, folks?
Create Before insert Trigger on emp to insert nextval into empno, e.g.:
create or replace trigger emp_trigger before insert on emp
for each row
I couldn't get it to work. Is there a trick to writing theinsert statement?
If you have table and trigger, then
'Insert into EMP(empname)
should do the trick.
What is the problem?
akkerend: it worked! Thank you
Hi! sorry. I forgot to create the sequence. Its working now.
Thanks a bunch.
Click Here to Expand Forum to Full Width