Entering Information Into Two Tables at Once

Question:
I have two tables:

Items_table: Item_id (primary key)       Description (foreign key)       Item_priceDescrip_table: Description (primary key)       Item_type

How do I enter information into the two Description columns simultaneously?

Answer:
An insert statement can only insert into one table. So there is no way to actually insert into two tables in one statement.

However, if you wrap the two insert statements into a transaction, then both insert statements are treated as one unit of work.

Therefore, either both are successful or none are. And no one will be able to see any of the rows being inserted till they are both committed.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: