Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Script - primary index

Status
Not open for further replies.

Generator3Punkte

Programmer
Jun 6, 2007
3
AT
Hello...

...I have a problem with inserting into more then one table.

Ive got 3 Tables:

T1:
id (primery key with autoincrease )
Data...int


T2:
id (primery key with autoincrease )
OtherData...int


T3:
id (primery key with autoincrease )
T1_id...is connceted by a key with the id of T1
T2_id...is connceted by a key with the id of T2
some other Data


Now I want to write a UpdateScript that inserts:
One Row into T1, One Row into T2 and finaly:
One Row with the new ids from T1 and T2 into T3

Thank you
 
T3 should not have its own auto_increment id
Code:
create table T3
( T1_id integer not null 
, T2_id integer not null 
, foreign key ( T1_id ) references T1 ( id )
, foreign key ( T2_id ) references T2 ( id )
, [b]primary key ( T1_id
              , T2_id )[/b]
);

r937.com | rudy.ca
 
@guelphdad:
ok i try it

@r937:
In my system every table got an own id so i can reference to it. What is wrong about?
 
the "own id" is completely unnecessary for relationship tables like T3

wasted space, wasted cycles, poor performance unless T1_id and T2_id are also indexed, and, most importantly of all, unless there is a unique constraint on (T1_id,T2_id), you run the risk of entering a duplicate relationship, which, if you are somehow preventing this through application logic, is even more unnecessary processing

r937.com | rudy.ca
 
@r937:

Ok...

...the Table T3 is just an simple Version of my tables and there is a lot of other data in it as you can see in my 1st post

T3:
id (primery key with autoincrease )
T1_id...is connceted by a key with the id of T1
T2_id...is connceted by a key with the id of T2
some other Data <==== !!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top