0

Imagine I have the following database structure:

enter image description here

  • product_id in Products table is Auto-Increment

How can I Insert something in the Products table and either Amazon_Books or Starbucks_Products without losing track of the product_id?

My first thought (let's say for an Amazon_book):

  • insert product information in Products table. Auto-increment is generated.
  • get the max product_id
  • insert in Amazon_Books the max(product_id) of products and then the amazon book information

But, what if two or more products are inserted almost in the same time? My max(product_id) could get incremented and the subtype insertion would go for something else.

Thanks.

Cristian
  • 1,919
  • 3
  • 21
  • 33

1 Answers1

0

Well a idon't know if it is the best solution, I add to the tables a column called iduser which stored the user id that is doing the insertion, and the query

SELECT max(product_id) From yourTable WHERE iduser='$iduser'
Emilio Gort
  • 3,382
  • 2
  • 27
  • 43