By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,824 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,824 IT Pros & Developers. It's quick & easy.

dealing with composite primary keys

P: 52

i have two tables:

table1: mid,name [ here, mid is the primary key ]
table2: mid,did,location [ here, mid&did is the composite primary key
also, mid references mid in table1 ]

now, i need to increment [did] against a particular mid value....
how can that be done?
please help.

i have created my tables this this correct?

T1: create table t1(mid number(2) primary key, name varchar2(20));

T2: create table t2(mid number(12),did number(3),location varchar2(1000) not null, PRIMARY KEY(mid,did),
constraint me_id foreign key(mid) references t1(mid));

please help.
Mar 22 '07 #1
Share this Question
Share on Google+
1 Reply

P: 24
see if it works or not, i am not sure, if it does not, try to play with it, you will succeed, i won't test the code here...

CREATE SEQUENCE sequence_name
INCREMENT BY your_desired_value
START WITH value_you_want_to_start_with
MAXVALUE maximum_value

and then use that sequence with the help of a trigger to put into your did field-

SELECT sequence_name.nextval
INTO :T2.did
FROM dual;

Mar 25 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.