1

Okay for various reasons I need to make sure an auto incremental ID is not in another table when it is inserted. So the ID in table1 cannot be the same as the ID in table2. The ID in both tables must be auto incremented but the numbers cannot be the same as ID from both are inserted into another table with a trigger. I cannot have the auto incremental value set higher on one table than the other as that causes other problems.

My idea is to have a WHERE clause with a sub query in the auto increment part of the schema but I am not sure if that's possible.

Any ideas?

Jacob Windsor
  • 6,750
  • 6
  • 33
  • 49

1 Answers1

0

I would recommend using a trigger to check whether the next ID exists using BEFORE INSERT.

This resource will show you how to fetch the next AUTO_INCREMENT value and this resource outlines how to create a BEFORE INSERT trigger. Hopefully these resources can get you on the right path.

Community
  • 1
  • 1
Kermit
  • 33,827
  • 13
  • 85
  • 121