Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> New Id usign max(id)
I have a table defined like:
CREATE TABLE mytable
(
NUM INTEGER NOT NULL, ID INTEGER NOT NULL, TITLE VARCHAR(50) NOT NULL,
ALTER TABLE mytable
ADD CONSTRAINT XPK_IDX PRIMARY KEY(NUM, ID)
ALTER TABLE mytable
ADD CONSTRAINT XFK FOREIGN KEY (NUM) REFERENCES yourtable(NUM) ON DELETE CASCADE
So my NUM, ID relationship would look like:
NUM ID
1 1
1 2
1 3
2 1
2 2
2 3
I wanted the ID to be sequential, but can't tie a sequence to it because for each NUM I'd like the ID to be 1,2,3, etc. as defined
So, my question then is before I do the insert are there any other ways you consider better than doing a query to get the max(id).
My select would be: select max(id) from mytable where num=1
Mike Received on Thu Oct 06 2005 - 15:39:05 CDT
![]() |
![]() |