I use a conjunction (or bridge) table but I'm confused what does the table do. I'm not totally don't know how it work, just that when I insert data into my PK, the FK of bridge table should be automatically inserted the same data also right? since FK is reference of PK.
Asked
Active
Viewed 112 times
1 Answers
1
If BRIDGE_TABLE is a many-to-many mapping between TABLE_A and TABLE_B, insert elements into TABLE_A and TABLE_B, then insert (many) relationship values into BRIDGE_TABLE using the primary keys of TABLE_A and TABLE_B as foreign keys in BRIDGE_TABLE. The database cannot know the needed relationships between A and B, so you must determine them and insert them yourself.
If you want to do multiple inserts "at the same time" you can put them in one transaction: SQL Server: Is it possible to insert into two tables at the same time?
However, you cannot use one statement to insert into two tables.

Community
- 1
- 1

M. K. Hunter
- 1,778
- 3
- 21
- 27
-
so it's common in query I insert twice? one into table A / B and one into the bridge table? – user3522444 Apr 24 '14 at 11:35
-
the only information you insert twice are the primary keys of the A/B tables. the rest remains in those tables. its really only a mapping of data from table a to b and vice versa – Olli Apr 24 '14 at 11:38
-
@user3522444: Yes, two inserts, as you give the database separate information: First: table A has a new entry 'X'. Second: entry 'X' in table A is related to entry '123' in table B. – Thorsten Kettner Apr 24 '14 at 11:38
-
I modified it to add a reference to another SO question. – M. K. Hunter Apr 24 '14 at 11:39