user3522444
user3522444

Reputation: 77

many to many relationship data confusion

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.

Upvotes: 0

Views: 114

Answers (1)

M. K. Hunter
M. K. Hunter

Reputation: 1828

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.

Upvotes: 1

Related Questions